From 4694f0aa2f2ddb57fa030c1520117d11ff7d2f45 Mon Sep 17 00:00:00 2001 From: lbenedar Date: Tue, 17 Mar 2026 12:06:27 +0300 Subject: [PATCH] ch4.2 --- cmd/api/movies.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/api/movies.go b/cmd/api/movies.go index bdf11be..a826b0d 100644 --- a/cmd/api/movies.go +++ b/cmd/api/movies.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "net/http" "time" @@ -9,7 +10,19 @@ import ( ) func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "create a new movie") + var input struct { + Title string `json:"title"` + Year int32 `json:"year"` + Runtime int32 `json:"runtime"` + Genres []string `json:"genres"` + } + + err := json.NewDecoder(r.Body).Decode(&input) + if err != nil { + app.errorResponse(w, r, http.StatusBadRequest, err.Error()) + return + } + fmt.Fprintf(w, "%+v\n", input) } func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request) {