update
This commit is contained in:
parent
59df5ce6a1
commit
70d8971e64
@ -32,8 +32,8 @@ func GetPhotos(album string) (photo []Photo, err error) {
|
||||
}
|
||||
|
||||
// GetPhoto -
|
||||
func GetPhoto(id string) (photo *Photo, err error) {
|
||||
rows, err := x.Query(`select "id", "album", "name", "thumbnail", "ctime", "mtime" from "storage"."photo" where "id" = $1`, id)
|
||||
func GetPhoto(album, id string) (photo *Photo, err error) {
|
||||
rows, err := x.Query(`select "id", "album", "name", "thumbnail", "ctime", "mtime" from "storage"."photo" where "album" = $1 and "id" = $2`, album, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ func GetAlbum(c *context.Context) {
|
||||
c.NotFound("album not found")
|
||||
return
|
||||
}
|
||||
log.Println(album)
|
||||
data := make(map[string]interface{})
|
||||
data["album"] = utils.ToMap(album)
|
||||
c.Success(data)
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
// GetAlbumPhotos -
|
||||
func GetAlbumPhotos(c *context.Context) {
|
||||
data, ok := c.Get("album")
|
||||
album := data.(models.Album)
|
||||
if !ok {
|
||||
c.NotFound("album not found")
|
||||
return
|
||||
}
|
||||
album := data.(*models.Album)
|
||||
data = nil
|
||||
|
||||
photos, err := models.GetPhotos(album.ID)
|
||||
if err != nil {
|
||||
@ -32,5 +33,31 @@ func GetAlbumPhotos(c *context.Context) {
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
@ -54,9 +54,10 @@ func SetDefaultRoutes(r *gin.Engine) {
|
||||
albumAPI.GET("/:album", context.PatchContext(album.GetAlbum))
|
||||
albumAPI.PUT("/:album", context.PatchContext(album.UpdateAlbum))
|
||||
albumAPI.DELETE("/:album", context.PatchContext(album.DeleteAlbum))
|
||||
albumAPI.GET("/:album/photos", context.PatchContext(middleware.VerifyToken), context.PatchContext(middleware.GetAlbumToNext), context.PatchContext(album.GetAlbumPhotos))
|
||||
}
|
||||
photoAPI := albumAPI.Group("/:album/photo", context.PatchContext(middleware.VerifyToken), context.PatchContext(middleware.GetAlbumToNext))
|
||||
{
|
||||
photoAPI.GET("/", context.PatchContext(album.GetAlbumPhotos))
|
||||
photoAPI.GET("/:photo", context.PatchContext(album.GetPhoto))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user