bindbox-game/internal/api/app/categories.go
邹方成 c8b04e2bc6 feat(活动): 新增抽奖记录等级筛选功能并优化展示信息
refactor(抽奖记录): 重构抽奖记录列表接口,支持按等级筛选
新增用户昵称、头像及奖品名称、图片等展示字段
优化分页逻辑,默认返回最新100条记录

feat(游戏): 添加扫雷游戏验证和结算接口
新增游戏票据验证和结算相关接口定义及Swagger文档

docs(API): 更新Swagger文档
更新抽奖记录和游戏相关接口的文档描述

style(路由): 添加游戏路由注释
添加扫雷游戏接口路由的占位注释
2025-12-21 23:45:01 +08:00

57 lines
1.7 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"`
}
// ListCategoriesForApp 获取分类列表
// @Summary 获取分类列表
// @Description 获取APP端商品分类列表
// @Tags APP端.基础
// @Accept json
// @Produce json
// @Success 200 {object} listAppCategoriesResponse
// @Failure 400 {object} code.Failure
// @Router /api/app/categories [get]
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)
}
}