diff --git a/routers/album/photo.go b/routers/album/photo.go index 75787bc..8f07a37 100644 --- a/routers/album/photo.go +++ b/routers/album/photo.go @@ -3,15 +3,11 @@ 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" ) -// GetAllAlbumPhotos - -func GetAllAlbumPhotos(c *context.Context) { - -} - -// GetPhoto - -func GetPhoto(c *context.Context) { +// GetAlbumPhotos - +func GetAlbumPhotos(c *context.Context) { data, ok := c.Get("album") album := data.(models.Album) if !ok { @@ -19,9 +15,22 @@ func GetPhoto(c *context.Context) { return } - _, err := models.GetPhoto(album.ID) + 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) { + } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index f4c2ed8..0f2806d 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -57,6 +57,6 @@ func SetDefaultRoutes(r *gin.Engine) { } 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)) } }