add delete album

This commit is contained in:
Jay
2018-04-25 17:10:29 +08:00
parent 0da02160f0
commit 1b8416dba3
3 changed files with 47 additions and 5 deletions
+36 -2
View File
@@ -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)
}