53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package album
|
|
|
|
import (
|
|
"log"
|
|
|
|
"git.trj.tw/golang/go-gallery/modules/context"
|
|
"git.trj.tw/golang/go-gallery/modules/utils"
|
|
|
|
"git.trj.tw/golang/go-gallery/models"
|
|
)
|
|
|
|
// GetAllAlbums -
|
|
func GetAllAlbums(c *context.Context) {
|
|
val, ok := c.Get("token")
|
|
|
|
if !ok {
|
|
c.CustomRes("Foridden", "User token data not found")
|
|
}
|
|
|
|
albums, err := models.GetUserAlbums(val.(map[string]interface{})["user"].(map[string]interface{})["id"].(string))
|
|
if err != nil {
|
|
c.ServerError(nil)
|
|
return
|
|
}
|
|
|
|
data := make(map[string]interface{})
|
|
data["albums"] = make([]map[string]interface{}, 0)
|
|
for _, v := range albums {
|
|
log.Println(v)
|
|
data["albums"] = append(data["albums"].([]map[string]interface{}), utils.ToMap(v))
|
|
}
|
|
c.Success(data)
|
|
}
|
|
|
|
// GetAlbum -
|
|
func GetAlbum(c *context.Context) {
|
|
id := c.Param("id")
|
|
|
|
album, err := models.GetAlbum(id)
|
|
if err != nil {
|
|
c.ServerError(nil)
|
|
return
|
|
}
|
|
if album == nil {
|
|
c.NotFound("album not found")
|
|
return
|
|
}
|
|
|
|
data := make(map[string]interface{})
|
|
data["album"] = album
|
|
c.Success(data)
|
|
}
|