Creating GetAll MovieModel method to retrieve all movies. Updating the listMovieHandler to use the new GetAll MovieModel's method.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 59s

This commit is contained in:
Maxime Delporte
2025-11-13 15:25:00 +01:00
parent 95d9de60b4
commit 1b71a1a8ad
2 changed files with 66 additions and 5 deletions

View File

@@ -236,12 +236,16 @@ func (app *application) listMoviesHandler(w http.ResponseWriter, r *http.Request
return
}
// Check the Validator instance for any errors and use the failedValidationResponse() helper to send the client a response if necessary
if !v.Valid() {
app.failedValidationResponse(w, r, v.Errors)
// Call the GetAll() method to retrieve the movies, passing in the various filter parameters.
movies, err := app.models.Movies.GetAll(input.Title, input.Genres, input.Filters)
if err != nil {
app.serverErrorResponse(w, r, err)
return
}
// Dump the contents of the input struct in a HTTP response
fmt.Fprintf(w, "%+v\n", input)
// Send a JSON response containing the movie data
err = app.writeJSON(w, http.StatusOK, envelope{"movies": movies}, nil)
if err != nil {
app.serverErrorResponse(w, r, err)
}
}