ch7.3
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"gitea.local.lab/Lbenedar/greenlight/internal/data"
|
||||
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
|
||||
@@ -58,13 +58,15 @@ func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
movie := data.Movie{
|
||||
ID: id,
|
||||
CreatedAt: time.Now(),
|
||||
Title: "Casablanca",
|
||||
Runtime: 102,
|
||||
Genres: []string{"drama", "romance", "war"},
|
||||
Version: 1,
|
||||
movie, err := app.models.Movies.Get(id)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, data.ErrRecordNotFound):
|
||||
app.notFoundResponse(w, r)
|
||||
default:
|
||||
app.serverErrorResponse(w, r, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = app.writeJSON(w, http.StatusOK, envelope{"movie": movie}, nil)
|
||||
|
||||
Reference in New Issue
Block a user