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
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 59s
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user