|
|
|
@ -122,10 +122,19 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// var input struct {
|
|
|
|
|
// Title string `json:"title"`
|
|
|
|
|
// Year int32 `json:"year"`
|
|
|
|
|
// Runtime data.Runtime `json:"runtime"`
|
|
|
|
|
// Genres []string `json:"genres"`
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Choosing to use pointers to allow us to determine if the zero value was sent
|
|
|
|
|
// by the client or if it was excluded from the client submission
|
|
|
|
|
var input struct {
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Year int32 `json:"year"`
|
|
|
|
|
Runtime data.Runtime `json:"runtime"`
|
|
|
|
|
Title *string `json:"title"`
|
|
|
|
|
Year *int32 `json:"year"`
|
|
|
|
|
Runtime *data.Runtime `json:"runtime"`
|
|
|
|
|
Genres []string `json:"genres"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -135,10 +144,19 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
movie.Title = input.Title
|
|
|
|
|
movie.Year = input.Year
|
|
|
|
|
movie.Runtime = input.Runtime
|
|
|
|
|
if input.Title != nil {
|
|
|
|
|
movie.Title = *input.Title
|
|
|
|
|
}
|
|
|
|
|
if input.Year != nil {
|
|
|
|
|
movie.Year = *input.Year
|
|
|
|
|
}
|
|
|
|
|
if input.Runtime != nil {
|
|
|
|
|
movie.Runtime = *input.Runtime
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if input.Genres != nil {
|
|
|
|
|
movie.Genres = input.Genres
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v := validator.New()
|
|
|
|
|
|
|
|
|
@ -149,7 +167,12 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
|
|
|
|
|
err = app.models.Movies.Update(r.Context(), movie)
|
|
|
|
|
if err != nil {
|
|
|
|
|
switch {
|
|
|
|
|
case errors.Is(err, data.ErrEditConflict):
|
|
|
|
|
app.editConflictResponse(w, r)
|
|
|
|
|
default:
|
|
|
|
|
app.serverErrorResponse(w, r, err)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|