diff --git a/main.go b/main.go index 56fd3af..cc260a8 100644 --- a/main.go +++ b/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