ch8.1
This commit is contained in:
@@ -94,10 +94,10 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
var input struct {
|
||||
Title string `json:"title"`
|
||||
Year int32 `json:"year"`
|
||||
Runtime data.Runtime `json:"runtime"`
|
||||
Genres []string `json:"genres"`
|
||||
Title *string `json:"title"`
|
||||
Year *int32 `json:"year"`
|
||||
Runtime *data.Runtime `json:"runtime"`
|
||||
Genres []string `json:"genres"`
|
||||
}
|
||||
|
||||
err = app.readJSON(w, r, &input)
|
||||
@@ -106,10 +106,18 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
movie.Title = input.Title
|
||||
movie.Year = input.Year
|
||||
movie.Runtime = input.Runtime
|
||||
movie.Genres = input.Genres
|
||||
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()
|
||||
if data.ValidateMovie(v, movie); !v.Valid() {
|
||||
|
||||
Reference in New Issue
Block a user