generated from pkg/go-template
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
|
package handler
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/error_process"
|
||
|
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/model"
|
||
|
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/service"
|
||
|
"github.com/gofiber/fiber/v2"
|
||
|
ctxLogger "github.com/luizsuper/ctxLoggers"
|
||
|
"go.uber.org/zap"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
func GetScriptsH(ctx *fiber.Ctx) error {
|
||
|
page := ctx.Query("page", "1")
|
||
|
limit := ctx.Query("size", "10")
|
||
|
iPage, _ := strconv.Atoi(page)
|
||
|
iLimit, _ := strconv.Atoi(limit)
|
||
|
s := ctx.Query("query", "")
|
||
|
query := model.GetQuery{Query: s}
|
||
|
processMap, err := query.ProcessMap()
|
||
|
if err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.GrammerError, zap.String("", fmt.Sprintf("%+v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
m, num, err := service.GetScripts(iPage, iLimit, processMap, ctx)
|
||
|
if err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.ServiceErr, zap.String("", fmt.Sprintf("%+v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
return ctx.JSON(success(&Data{
|
||
|
Elements: m,
|
||
|
Total: num,
|
||
|
}))
|
||
|
}
|
||
|
|
||
|
func UpdateScriptsH(ctx *fiber.Ctx) error {
|
||
|
m := new(model.Scripts)
|
||
|
if err := checkParam(m, ctx); err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.BodyParserErr, zap.String("", fmt.Sprintf("%v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
err := service.UpdateScripts(m, ctx)
|
||
|
if err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.ServiceErr, zap.String("", fmt.Sprintf("%+v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
return ctx.JSON(success(nil))
|
||
|
}
|
||
|
|
||
|
func CreateScriptsH(ctx *fiber.Ctx) error {
|
||
|
m := new(model.Scripts)
|
||
|
if err := createScriptParamCheck(m, ctx); err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.BodyParserErr, zap.String("", fmt.Sprintf("%v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
err := service.CreateScripts(m, ctx)
|
||
|
if err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.ServiceErr, zap.String("", fmt.Sprintf("%+v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
return ctx.JSON(success(nil))
|
||
|
}
|
||
|
|
||
|
func DeleteScriptsH(ctx *fiber.Ctx) error {
|
||
|
m := new(model.Scripts)
|
||
|
if err := checkParam(m, ctx); err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.BodyParserErr, zap.String("", fmt.Sprintf("%v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
err := service.DeleteScripts(m, ctx)
|
||
|
if err != nil {
|
||
|
ctxLogger.FError(ctx, error_process.ServiceErr, zap.String("", fmt.Sprintf("%+v", err)))
|
||
|
return ctx.JSON(fail(nil))
|
||
|
}
|
||
|
return ctx.JSON(success(nil))
|
||
|
}
|