Updating createMovieHandler accepting data.Runtime for the Runtime field. Updating internal/data/runtime.go with the json.Unmarshaler interface to transform our client's runtime string field '%d mins' into a Runtime type format.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 58s
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 58s
This commit is contained in:
@@ -11,10 +11,10 @@ import (
|
||||
func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Declare an anonymous struct to hold the information that we expect to be in the HTTP request body (note that the field names and types in the struct are a subset of the Movie struct that we created earlier). This struct will be our *target decode destination*.
|
||||
var input struct {
|
||||
Title string `json:"title"`
|
||||
Year int32 `json:"year"`
|
||||
Runtime int32 `json:"runtime"`
|
||||
Genres []string `json:"genres"`
|
||||
Title string `json:"title"`
|
||||
Year int32 `json:"year"`
|
||||
Runtime data.Runtime `json:"runtime"`
|
||||
Genres []string `json:"genres"`
|
||||
}
|
||||
|
||||
// Use the new readJSON() helper to decode the request body into the input struct. If this returns an error, we send the client the error message along with a 400 Bad Request status code, just like before.
|
||||
|
||||
Reference in New Issue
Block a user