119 lines
3.3 KiB
Go
119 lines
3.3 KiB
Go
package productctrl
|
|
|
|
import (
|
|
"91porn-server/common"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/v/productposimod"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Get doc
|
|
// @Summary
|
|
// @Description 查询
|
|
// @Tags productposition
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /productposition/list [post]
|
|
func GetPosition(ctx *gin.Context) {
|
|
data, err := productposimod.FindAll()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, gin.H{
|
|
"list": data,
|
|
})
|
|
}
|
|
|
|
// Get doc
|
|
// @Summary
|
|
// @Description 查询位置名字列表
|
|
// @Tags productposition
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /productposition/names [post]
|
|
func GetPositionNames(ctx *gin.Context) {
|
|
data, err := productposimod.FindNames()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, gin.H{
|
|
"list": data,
|
|
})
|
|
}
|
|
|
|
// Insert doc
|
|
// @Summary 新增
|
|
// @Description 新增
|
|
// @Tags productposition
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /productposition/add [post]
|
|
func InsertPosition(ctx *gin.Context) {
|
|
v := productposimod.ProductPosition{}
|
|
if err := ctx.ShouldBind(&v); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
if err := productposimod.Insert(&v); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error())
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, nil)
|
|
}
|
|
|
|
// Update doc
|
|
// @Summary 修改
|
|
// @Description 修改
|
|
// @Tags productposition
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /productposition/edit [post]
|
|
func UpdatePosition(ctx *gin.Context) {
|
|
p := productposimod.ProductPositionSelector{}
|
|
if err := ctx.ShouldBind(&p); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
if err := productposimod.Update(&p); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbUpdateError, "")
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, nil)
|
|
}
|
|
|
|
// Delete doc
|
|
// @Summary 删除
|
|
// @Description 删除
|
|
// @Tags productposition
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param id formData int true "productposition等级""
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /productposition/del [delete]
|
|
func DeletePosition(ctx *gin.Context) {
|
|
var p struct {
|
|
ID string `json:"id" form:"id"`
|
|
}
|
|
if err := ctx.ShouldBind(&p); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
if err := productposimod.Remove(p.ID); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbDeleteError, "")
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, nil)
|
|
}
|