@@ -0,0 +1,95 @@
|
||||
package scenebannerctrl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/l/operatorlgmod"
|
||||
"91porn-server/models/v/scenebannermod"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type listResp struct {
|
||||
Total int `json:"total"`
|
||||
List []scenebannermod.SceneBanner `json:"list"`
|
||||
}
|
||||
|
||||
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.List(scene)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, nil)
|
||||
return
|
||||
}
|
||||
if list == nil {
|
||||
list = []scenebannermod.SceneBanner{}
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, listResp{Total: len(list), List: list})
|
||||
}
|
||||
|
||||
func Add(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
banner := scenebannermod.SceneBanner{}
|
||||
if err = ctx.ShouldBindJSON(&banner); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if err = scenebannermod.Insert(&banner); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error())
|
||||
return
|
||||
}
|
||||
body, _ := json.Marshal(banner)
|
||||
_ = operatorlgmod.RecordOperation(manager, "评论区Banner配置", "创建", string(body), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, banner.ID)
|
||||
}
|
||||
|
||||
func Edit(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
banner := scenebannermod.SceneBanner{}
|
||||
if err = ctx.ShouldBindJSON(&banner); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if err = scenebannermod.Update(&banner); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error())
|
||||
return
|
||||
}
|
||||
body, _ := json.Marshal(banner)
|
||||
_ = operatorlgmod.RecordOperation(manager, "评论区Banner配置", "修改", string(body), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
|
||||
func Delete(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := primitive.ObjectIDFromHex(ctx.Query("id"))
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "invalid id")
|
||||
return
|
||||
}
|
||||
if err = scenebannermod.Delete(id); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error())
|
||||
return
|
||||
}
|
||||
_ = operatorlgmod.RecordOperation(manager, "评论区Banner配置", "删除", id.Hex(), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
Reference in New Issue
Block a user