|
|
@ -159,6 +159,34 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) deleteMovieHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
id, err := app.readIDParam(r)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.notFoundResponse(w, r)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Maybe should be passing a timeout context
|
|
|
|
|
|
|
|
_, err = app.models.Movies.Get(r.Context(), id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
switch {
|
|
|
|
|
|
|
|
case errors.Is(err, data.ErrRecordNotFound):
|
|
|
|
|
|
|
|
app.notFoundResponse(w, r)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
app.serverErrorResponse(w, r, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = app.models.Movies.Delete(r.Context(), id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.serverErrorResponse(w, r, err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusAccepted)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (app *application) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// JSON has to be double quoted. FYI you would never really do this
|
|
|
|
// JSON has to be double quoted. FYI you would never really do this
|
|
|
|
// js := `{"status": "available", "environment": %q, "version": %q}`
|
|
|
|
// js := `{"status": "available", "environment": %q, "version": %q}`
|
|
|
|