@@ -0,0 +1,165 @@
|
||||
package fictionctrl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/constant"
|
||||
"91porn-server/common/constant/redisconst"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/l/operatorlgmod"
|
||||
"91porn-server/models/v/fictionmod"
|
||||
"91porn-server/web/webg"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// Get doc
|
||||
// @Summary
|
||||
// @Description 查询电子书
|
||||
// @Tags fiction
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /fiction/list [post]
|
||||
func List(ctx *gin.Context) {
|
||||
var p struct {
|
||||
fictionmod.QuerySelector
|
||||
commod.Page
|
||||
}
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
data, total, err := fictionmod.StdFind(p.QuerySelector, p.Page)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
||||
return
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, gin.H{
|
||||
"list": data,
|
||||
"total": total,
|
||||
})
|
||||
}
|
||||
|
||||
// Insert doc
|
||||
// @Summary 新增
|
||||
// @Description 新增
|
||||
// @Tags fiction
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /fiction/add [post]
|
||||
func Insert(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
v := fictionmod.Fiction{}
|
||||
if err = ctx.ShouldBind(&v); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if err = fictionmod.InsertFiction(&v); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error())
|
||||
return
|
||||
}
|
||||
log, _ := json.Marshal(v)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.Fiction, constant.Add, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
|
||||
// Update doc
|
||||
// @Summary 修改
|
||||
// @Description 修改
|
||||
// @Tags fiction
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /fiction/edit [post]
|
||||
func Update(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
p := fictionmod.EditSelector{}
|
||||
if err = ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if err = fictionmod.UpdateFiction(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbUpdateError, "")
|
||||
return
|
||||
}
|
||||
redisKey := redisconst.DataCachKey(fictionmod.RedisSetKey, "FindfictionByType")
|
||||
_, _ = webg.Redis.Del(redisKey)
|
||||
log, _ := json.Marshal(p)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.Fiction, constant.Modify, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
|
||||
// Delete doc
|
||||
// @Summary 删除
|
||||
// @Description 删除
|
||||
// @Tags fiction
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param id formData int true "fiction等级""
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /fiction/del [delete]
|
||||
func Delete(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
ID string `json:"id" form:"id"`
|
||||
}
|
||||
if err = ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "")
|
||||
return
|
||||
}
|
||||
if err = fictionmod.RemoveFiction(p.ID); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbDeleteError, "")
|
||||
return
|
||||
}
|
||||
redisKey := redisconst.DataCachKey(fictionmod.RedisSetKey, "FindfictionByType")
|
||||
_, _ = webg.Redis.Del(redisKey)
|
||||
log, _ := json.Marshal(p)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.Fiction, constant.Delete, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
|
||||
// Get doc
|
||||
// @Summary
|
||||
// @Description 查询电子书
|
||||
// @Tags fiction
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /fiction/list [post]
|
||||
func Get(ctx *gin.Context) {
|
||||
var p struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
}
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
data, err := fictionmod.GetByID(p.ID)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
||||
return
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, data)
|
||||
}
|
||||
Reference in New Issue
Block a user