64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package album
|
|
|
|
import (
|
|
"git.trj.tw/golang/go-gallery/models"
|
|
"git.trj.tw/golang/go-gallery/modules/context"
|
|
"git.trj.tw/golang/go-gallery/modules/utils"
|
|
)
|
|
|
|
// GetAlbumPhotos -
|
|
func GetAlbumPhotos(c *context.Context) {
|
|
data, ok := c.Get("album")
|
|
if !ok {
|
|
c.NotFound("album not found")
|
|
return
|
|
}
|
|
album := data.(*models.Album)
|
|
data = nil
|
|
|
|
photos, err := models.GetPhotos(album.ID)
|
|
if err != nil {
|
|
c.ServerError(nil)
|
|
return
|
|
}
|
|
|
|
res := make(map[string]interface{})
|
|
res["photos"] = make([]map[string]interface{}, 0)
|
|
for _, v := range photos {
|
|
res["photos"] = append(res["photos"].([]map[string]interface{}), utils.ToMap(v))
|
|
}
|
|
|
|
c.Success(res)
|
|
}
|
|
|
|
// GetPhoto -
|
|
func GetPhoto(c *context.Context) {
|
|
data, ok := c.Get("album")
|
|
if !ok {
|
|
c.NotFound("album not found")
|
|
return
|
|
}
|
|
album := data.(*models.Album)
|
|
data = nil
|
|
var photoId string
|
|
photoId = c.Param("photo")
|
|
if len(photoId) == 0 {
|
|
c.DataFormat("photo id not found")
|
|
return
|
|
}
|
|
photo, err := models.GetPhoto(album.ID, photoId)
|
|
if err != nil {
|
|
c.ServerError(nil)
|
|
return
|
|
}
|
|
if photo == nil {
|
|
c.NotFound("photo not found")
|
|
return
|
|
}
|
|
|
|
res := make(map[string]interface{})
|
|
res["photo"] = utils.ToMap(photo)
|
|
|
|
c.Success(res)
|
|
}
|