ch4.5
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.local.lab/Lbenedar/greenlight/internal/data"
|
||||
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
|
||||
)
|
||||
|
||||
func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -21,6 +22,20 @@ func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Reques
|
||||
app.badRequestResponse(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
movie := &data.Movie{
|
||||
Title: input.Title,
|
||||
Year: input.Year,
|
||||
Runtime: input.Runtime,
|
||||
Genres: input.Genres,
|
||||
}
|
||||
|
||||
v := validator.New()
|
||||
if data.ValidateMovie(v, movie); !v.Valid() {
|
||||
app.failedValidationResponse(w, r, v.Errors)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%+v\n", input)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user