Zeus/handler/category.go

61 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-12-13 21:39:15 +08:00
package handler
import (
2021-12-14 14:31:18 +08:00
"bgm/consts"
bgm "bgm/helper"
2021-12-13 21:39:15 +08:00
"bgm/model"
"bgm/service"
2021-12-14 19:45:25 +08:00
"fmt"
2021-12-13 21:39:15 +08:00
"github.com/gofiber/fiber/v2"
"github.com/rs/xid"
)
2021-12-14 14:31:18 +08:00
func CreateCategoryH(ctx *fiber.Ctx, mysqlMap bgm.MysqlMap) error {
2021-12-14 19:45:25 +08:00
2021-12-13 21:39:15 +08:00
category := &model.Category{
Key: 1,
Value: "默认",
Gid: xid.New().String(),
}
2021-12-14 19:45:25 +08:00
return service.CreatCategory(category, mysqlMap[consts.TestDB])
}
2021-12-14 14:31:18 +08:00
2021-12-14 19:45:25 +08:00
func GetCategoryH(ctx *fiber.Ctx, mysqlMap bgm.MysqlMap) error {
fmt.Println(string(ctx.Request().URI().QueryString()))
page, _ := ctx.ParamsInt("page", 1)
limit, _ := ctx.ParamsInt("size", 10)
s := ctx.Query("query", "")
queryMap := bgm.GetQueryMap(s)
dto, err := service.GetCategoryDto(page, limit, queryMap, mysqlMap[consts.TestDB])
if err != nil {
return ctx.JSON(model.Response{
Message: consts.ResponseFail,
Data: nil,
})
} else {
return ctx.JSON(model.Response{
Message: consts.ResponseSuccess,
Data: dto,
})
}
2021-12-13 21:39:15 +08:00
}
2021-12-14 19:45:25 +08:00
//func GetScriptH(ctx*fiber.Ctx, mysqlMap bgm.MysqlMap) error {
// page, _ := ctx.ParamsInt("page", 1)
// limit, _ := ctx.ParamsInt("size", 10)
// queryParam := ctx.Params("query","")
//
// dto, err := service.GetCategoryDto(page, limit, mysqlMap[consts.TestDB])
// if err != nil {
// return ctx.JSON(model.Response{
// Message: consts.ResponseFail,
// Data: nil,
// })
// }else {
// return ctx.JSON(model.Response{
// Message: consts.ResponseSuccess,
// Data: dto,
// })
// }
//}