38 lines
696 B
Go
38 lines
696 B
Go
package middleware
|
|
|
|
import (
|
|
"git.trj.tw/golang/go-gallery/models"
|
|
"git.trj.tw/golang/go-gallery/modules/context"
|
|
"git.trj.tw/golang/go-gallery/modules/utils"
|
|
)
|
|
|
|
// GetAlbumToNext -
|
|
func GetAlbumToNext(c *context.Context) {
|
|
id := c.Param("album")
|
|
if len(id) == 0 {
|
|
c.DataFormat("no album id")
|
|
return
|
|
}
|
|
|
|
token, ok := c.Get("token")
|
|
if !ok {
|
|
c.CustomRes("Foridden", nil)
|
|
return
|
|
}
|
|
|
|
album, err := models.GetAlbum(id, token.(map[string]interface{})["user"].(map[string]interface{})["id"].(string))
|
|
if err != nil {
|
|
c.ServerError(nil)
|
|
return
|
|
}
|
|
if album == nil {
|
|
c.NotFound("album not found")
|
|
return
|
|
}
|
|
|
|
albumMap := utils.ToMap(album)
|
|
c.Set("album", albumMap)
|
|
|
|
c.Next()
|
|
}
|