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
|
// Call BindJSON to bind the received JSON to
|
||||||
// newAlbum.
|
// newAlbum.
|
||||||
if err := c.BindJSON(&newAlbum); err != nil {
|
if err := c.BindJSON(&newAlbum); err != nil {
|
||||||
|
c.Status(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, a := range albums {
|
||||||
|
if a == newAlbum {
|
||||||
|
c.Status(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add the new album to the slice.
|
// Add the new album to the slice.
|
||||||
albums = append(albums, newAlbum)
|
albums = append(albums, newAlbum)
|
||||||
c.IndentedJSON(http.StatusCreated, newAlbum)
|
c.JSON(http.StatusCreated, newAlbum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getAlbumByID locates the album whose ID value matches the id
|
// getAlbumByID locates the album whose ID value matches the id
|
||||||
|
Loading…
x
Reference in New Issue
Block a user