add delete album
This commit is contained in:
+36
-2
@@ -52,9 +52,9 @@ func GetAlbum(c *context.Context) {
|
||||
c.NotFound("album not found")
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(album)
|
||||
data := make(map[string]interface{})
|
||||
data["album"] = album
|
||||
data["album"] = utils.ToMap(album)
|
||||
c.Success(data)
|
||||
}
|
||||
|
||||
@@ -143,3 +143,37 @@ func UpdateAlbum(c *context.Context) {
|
||||
m["album"] = res
|
||||
c.Success(m)
|
||||
}
|
||||
|
||||
// DeleteAlbum -
|
||||
func DeleteAlbum(c *context.Context) {
|
||||
id := c.Param("id")
|
||||
if len(id) == 0 {
|
||||
c.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
token, ok := c.Get("token")
|
||||
|
||||
if !ok {
|
||||
c.CustomRes("Foridden", "user token data not found")
|
||||
return
|
||||
}
|
||||
|
||||
album, err := models.GetAlbum(id, token.(map[string]interface{})["user"].(map[string]interface{})["id"].(string))
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
return
|
||||
}
|
||||
if album == nil {
|
||||
c.NotFound("album not found")
|
||||
return
|
||||
}
|
||||
|
||||
err = album.Delete()
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
return
|
||||
}
|
||||
|
||||
c.Success(nil)
|
||||
}
|
||||
|
||||
@@ -53,5 +53,6 @@ func SetDefaultRoutes(r *gin.Engine) {
|
||||
albumAPI.POST("/", context.PatchContext(album.CreateAlbum))
|
||||
albumAPI.GET("/:id", context.PatchContext(album.GetAlbum))
|
||||
albumAPI.PUT("/:id", context.PatchContext(album.UpdateAlbum))
|
||||
albumAPI.DELETE("/:id", context.PatchContext(album.DeleteAlbum))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user