143 lines
4.3 KiB
Smarty
143 lines
4.3 KiB
Smarty
package {{PackageTableName}}ctrl
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"{{ModuleName}}/common"
|
|
"{{ModuleName}}/common/stderr"
|
|
"{{ModuleName}}/models/l/operatorlgmod"
|
|
"{{ModuleName}}/web/service/{{PackageTableName}}ser"
|
|
)
|
|
|
|
// List doc
|
|
// @Summary 获取{{TableComment}}列表
|
|
// @Description 获取{{TableComment}}列表
|
|
// @Tags 后台-{{TableComment}}
|
|
// @Accept mpfd,json
|
|
// @Produce json
|
|
// @Param q query {{PackageTableName}}ser.{{VariablePrefix}}ListReq false "请求参数"
|
|
// @Success 200 object {{PackageTableName}}ser.{{VariablePrefix}}ListRes "成功"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/admin/{{PackageTableName}}/list [get]
|
|
func List(ctx *gin.Context) {
|
|
var req = &{{PackageTableName}}ser.{{VariablePrefix}}ListReq{}
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
res, err := req.GetList()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
|
|
return
|
|
}
|
|
|
|
common.ServeJSON(ctx, stderr.Success, res)
|
|
}
|
|
|
|
// Create doc
|
|
// @Summary 新增{{TableComment}}
|
|
// @Description 新增{{TableComment}}
|
|
// @Tags 后台-{{TableComment}}
|
|
// @Accept mpfd,json
|
|
// @Produce json
|
|
// @Param q body {{PackageTableName}}ser.{{VariablePrefix}}CreateReq false "请求参数"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/admin/{{PackageTableName}}/create [post]
|
|
func Create(ctx *gin.Context) {
|
|
manager, err := common.GetAdminAct(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
|
|
p := &{{PackageTableName}}ser.{{VariablePrefix}}CreateReq{}
|
|
err = ctx.ShouldBindJSON(&p)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
// 创建
|
|
err = p.Create()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.Failure, err.Error())
|
|
return
|
|
}
|
|
|
|
log, _ := json.Marshal(p)
|
|
_ = operatorlgmod.RecordOperation(manager, "{{TableComment}}管理", "创建", string(log), ctx.Request.URL.RequestURI())
|
|
common.ServeJSON(ctx, stderr.Success, "")
|
|
}
|
|
|
|
// Update doc
|
|
// @Summary 更新{{TableComment}}
|
|
// @Description 更新{{TableComment}}
|
|
// @Tags 后台-{{TableComment}}
|
|
// @Accept mpfd,json
|
|
// @Produce json
|
|
// @Param q body {{PackageTableName}}ser.{{VariablePrefix}}UpdateReq false "请求参数"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/admin/{{PackageTableName}}/update [post]
|
|
func Update(ctx *gin.Context) {
|
|
manager, err := common.GetAdminAct(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
|
|
p := &{{PackageTableName}}ser.{{VariablePrefix}}UpdateReq{}
|
|
err = ctx.ShouldBindJSON(&p)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
// 更新
|
|
err = p.Update()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.Failure, err.Error())
|
|
return
|
|
}
|
|
|
|
log, _ := json.Marshal(p)
|
|
_ = operatorlgmod.RecordOperation(manager, "{{TableComment}}管理", "更新", string(log), ctx.Request.URL.RequestURI())
|
|
common.ServeJSON(ctx, stderr.Success, "")
|
|
}
|
|
|
|
// Delete doc
|
|
// @Summary 删除{{TableComment}}
|
|
// @Description 删除{{TableComment}}
|
|
// @Tags 后台-{{TableComment}}
|
|
// @Accept mpfd,json
|
|
// @Produce json
|
|
// @Param q body {{PackageTableName}}ser.{{VariablePrefix}}DeleteReq false "请求参数"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/admin/{{PackageTableName}}/delete [post]
|
|
func Delete(ctx *gin.Context) {
|
|
manager, err := common.GetAdminAct(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
|
|
p := &{{PackageTableName}}ser.{{VariablePrefix}}DeleteReq{}
|
|
err = ctx.ShouldBindJSON(&p)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
|
|
// 删除
|
|
err = p.Delete()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.Failure, err.Error())
|
|
return
|
|
}
|
|
|
|
log, _ := json.Marshal(p)
|
|
_ = operatorlgmod.RecordOperation(manager, "{{TableComment}}管理", "删除", string(log), ctx.Request.URL.RequestURI())
|
|
common.ServeJSON(ctx, stderr.Success, "")
|
|
}
|