51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package scenebannerctrl
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"91porn-server/common"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/v/scenebannermod"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type listResp struct {
|
|
List []bannerItem `json:"list"`
|
|
}
|
|
|
|
type bannerItem struct {
|
|
ID string `json:"id"`
|
|
ImageURL string `json:"imageUrl"`
|
|
MediaType string `json:"mediaType"`
|
|
LinkType string `json:"linkType"`
|
|
LinkValue string `json:"linkValue"`
|
|
Sort int `json:"sort"`
|
|
}
|
|
|
|
func List(ctx *gin.Context) {
|
|
scene := strings.ToUpper(strings.TrimSpace(ctx.Query("scene")))
|
|
if !scenebannermod.ValidScene(scene) {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, "invalid scene")
|
|
return
|
|
}
|
|
list, err := scenebannermod.FindActive(scene, time.Now())
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, nil)
|
|
return
|
|
}
|
|
items := make([]bannerItem, 0, len(list))
|
|
for _, banner := range list {
|
|
items = append(items, bannerItem{
|
|
ID: banner.ID.Hex(),
|
|
ImageURL: banner.ImageURL,
|
|
MediaType: banner.MediaType,
|
|
LinkType: banner.LinkType,
|
|
LinkValue: banner.LinkValue,
|
|
Sort: banner.Sort,
|
|
})
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, listResp{List: items})
|
|
}
|