refactor(utils): 修复密码哈希比较逻辑错误 feat(user): 新增按状态筛选优惠券接口 docs: 添加虚拟发货与任务中心相关文档 fix(wechat): 修正Code2Session上下文传递问题 test: 补充订单折扣与积分转换测试用例 build: 更新配置文件与构建脚本 style: 清理多余的空行与注释
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/validation"
|
|
"bindbox-game/internal/pkg/logger"
|
|
"bindbox-game/internal/repository/mysql"
|
|
"bindbox-game/internal/repository/mysql/dao"
|
|
)
|
|
|
|
type categoryHandler struct {
|
|
logger logger.CustomLogger
|
|
readDB *dao.Query
|
|
}
|
|
|
|
func NewCategory(logger logger.CustomLogger, db mysql.Repo) *categoryHandler {
|
|
return &categoryHandler{logger: logger, readDB: dao.Use(db.GetDbR())}
|
|
}
|
|
|
|
type appCategoryItem struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type listAppCategoriesResponse struct {
|
|
List []appCategoryItem `json:"list"`
|
|
}
|
|
|
|
func (h *categoryHandler) ListCategoriesForApp() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
q := h.readDB.ProductCategories.WithContext(ctx.RequestContext())
|
|
items, err := q.Where(h.readDB.ProductCategories.Status.Eq(1)).Order(h.readDB.ProductCategories.ID.Asc()).Find()
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ServerError, validation.Error(err)))
|
|
return
|
|
}
|
|
res := &listAppCategoriesResponse{List: make([]appCategoryItem, len(items))}
|
|
for i, it := range items {
|
|
res.List[i] = appCategoryItem{ID: it.ID, Name: it.Name}
|
|
}
|
|
ctx.Payload(res)
|
|
}
|
|
}
|
|
|