This commit is contained in:
Jay 2018-05-08 16:35:09 +08:00
parent fe884e6931
commit 59df5ce6a1
2 changed files with 18 additions and 9 deletions

View File

@ -3,15 +3,11 @@ package album
import ( import (
"git.trj.tw/golang/go-gallery/models" "git.trj.tw/golang/go-gallery/models"
"git.trj.tw/golang/go-gallery/modules/context" "git.trj.tw/golang/go-gallery/modules/context"
"git.trj.tw/golang/go-gallery/modules/utils"
) )
// GetAllAlbumPhotos - // GetAlbumPhotos -
func GetAllAlbumPhotos(c *context.Context) { func GetAlbumPhotos(c *context.Context) {
}
// GetPhoto -
func GetPhoto(c *context.Context) {
data, ok := c.Get("album") data, ok := c.Get("album")
album := data.(models.Album) album := data.(models.Album)
if !ok { if !ok {
@ -19,9 +15,22 @@ func GetPhoto(c *context.Context) {
return return
} }
_, err := models.GetPhoto(album.ID) photos, err := models.GetPhotos(album.ID)
if err != nil { if err != nil {
c.ServerError(nil) c.ServerError(nil)
return 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) {
} }

View File

@ -57,6 +57,6 @@ func SetDefaultRoutes(r *gin.Engine) {
} }
photoAPI := albumAPI.Group("/:album/photo", context.PatchContext(middleware.VerifyToken), context.PatchContext(middleware.GetAlbumToNext)) photoAPI := albumAPI.Group("/:album/photo", context.PatchContext(middleware.VerifyToken), context.PatchContext(middleware.GetAlbumToNext))
{ {
photoAPI.GET("/", context.PatchContext(album.GetPhoto)) photoAPI.GET("/", context.PatchContext(album.GetAlbumPhotos))
} }
} }