greenlight/cmd/api/movies.go

39 lines
824 B
Go

package main
import (
"fmt"
"net/http"
"time"
"greenlight.ergz/internal/data"
)
func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "create a new movie")
}
func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request) {
id, err := app.readIDParam(r)
if err != nil {
http.NotFound(w, r)
return
}
movie := data.Movie{
ID: id,
CreatedAt: time.Now(),
Title: "Casablanca",
Runtime: 102,
Genres: []string{"drama", "romance", "war"},
Version: 1,
}
envelopedMovie := envelope{"movie": movie}
err = app.writeJSON(w, http.StatusOK, envelopedMovie, nil)
if err != nil {
app.logger.Print(err)
http.Error(w, "the server encountered an error and could process your request", http.StatusInternalServerError)
}
}