Adding a check on the X-Expected-Version header field.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 1m0s
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 1m0s
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"greenlight.craftr.fr/internal/data"
|
||||
"greenlight.craftr.fr/internal/validator"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// "POST /v1/movies" endpoint.
|
||||
@@ -108,6 +109,14 @@ func (app *application) updateMovieHandler(w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
// If the request contains a X-Expected-Version header, verify that the movie version in the database matches the expected version specified in the header.
|
||||
if r.Header.Get("X-Expected-Version") != "" {
|
||||
if strconv.Itoa(int(movie.Version)) != r.Header.Get("X-Expected-Version") {
|
||||
app.editConflictResponse(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Declare an input struct to hold the expected data from the client
|
||||
// Use pointers for the Title, Year and Runtime fields : so we can see if a client has provided a particular key/value pair in the JSON.
|
||||
var input struct {
|
||||
|
||||
Reference in New Issue
Block a user