|
|
|
@ -167,7 +167,20 @@ func (app *application) deleteMovieHandler(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maybe should be passing a timeout context
|
|
|
|
|
_, err = app.models.Movies.Get(r.Context(), id)
|
|
|
|
|
// WE DON"T NEED THIS BECAUSE EXEC RETURNS A RESULT OBJECT WITH THE NUMBER
|
|
|
|
|
// OF ROWS AFFECTED. IF THE RESULT IS 0 THEN WE 404
|
|
|
|
|
// _, 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 {
|
|
|
|
|
switch {
|
|
|
|
|
case errors.Is(err, data.ErrRecordNotFound):
|
|
|
|
@ -178,13 +191,15 @@ func (app *application) deleteMovieHandler(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = app.models.Movies.Delete(r.Context(), id)
|
|
|
|
|
// I personally think this should be a 202 or a 204 but Alex thinks otherwise.
|
|
|
|
|
// his rule of thumb is if the clients are humans send human readable messages. If they
|
|
|
|
|
// are machines then status code is alright.
|
|
|
|
|
//w.WriteHeader(http.StatusAccepted)
|
|
|
|
|
|
|
|
|
|
err = app.writeJSON(w, http.StatusOK, envelope{"message": "movie successfully deleted"}, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
app.serverErrorResponse(w, r, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusAccepted)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|