prevent overposting
This commit is contained in:
parent
1517fdaa09
commit
c61affb36e
10
main.go
10
main.go
@ -49,12 +49,20 @@ func postAlbums(c *gin.Context) {
|
||||
// Call BindJSON to bind the received JSON to
|
||||
// newAlbum.
|
||||
if err := c.BindJSON(&newAlbum); err != nil {
|
||||
c.Status(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
for _, a := range albums {
|
||||
if a == newAlbum {
|
||||
c.Status(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Add the new album to the slice.
|
||||
albums = append(albums, newAlbum)
|
||||
c.IndentedJSON(http.StatusCreated, newAlbum)
|
||||
c.JSON(http.StatusCreated, newAlbum)
|
||||
}
|
||||
|
||||
// getAlbumByID locates the album whose ID value matches the id
|
||||
|
Loading…
Reference in New Issue
Block a user