package main import ( "fmt" "greenlight.craftr.fr/internal/data" "net/http" "time" ) // "POST /v1/movies" endpoint. func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "create a new movie") } // "GET /v1/movies/:id" func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request) { id, err := app.readIDParam(r) if err != nil || id < 1 { // Use the new notFoundResponse() helper app.notFoundResponse(w, r) return } /* Create a new instance of the Movie struct containing the ID we extracted from the URL and some dummy data. Also notice that we deliberately haven't set a value for the Year field. */ movie := data.Movie{ ID: id, CreatedAt: time.Now(), Title: "Casablanca", Runtime: 102, Genres: []string{"drama", "romance", "war"}, Version: 1, } // Encode the struct to JSON and send it as the HTTP response. err = app.writeJSON(w, http.StatusOK, envelope{"movie": movie}, nil) if err != nil { // Use the new serverErrorResponse() helper app.serverErrorResponse(w, r, err) } }