Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 25s
feat(admin): 新增工会管理功能 feat(activity): 添加活动管理相关服务 feat(user): 实现用户道具卡和积分管理 feat(guild): 新增工会成员管理功能 fix: 修复数据库连接配置 fix: 修正jwtoken导入路径 fix: 解决端口冲突问题 style: 统一代码格式和注释风格 style: 更新项目常量命名 docs: 添加项目框架和开发规范文档 docs: 更新接口文档注释 chore: 移除无用代码和文件 chore: 更新Makefile和配置文件 chore: 清理日志文件 test: 添加道具卡测试脚本
74 lines
2.3 KiB
Go
74 lines
2.3 KiB
Go
package admin
|
||
|
||
import (
|
||
"net/http"
|
||
"strconv"
|
||
|
||
"bindbox-game/internal/code"
|
||
"bindbox-game/internal/pkg/core"
|
||
"bindbox-game/internal/pkg/validation"
|
||
)
|
||
|
||
type listGuildMembersRequest struct {
|
||
Page int `form:"page"`
|
||
PageSize int `form:"page_size"`
|
||
}
|
||
type memberItem struct {
|
||
ID int64 `json:"id"`
|
||
UserID int64 `json:"user_id"`
|
||
Role string `json:"role"`
|
||
StartTime string `json:"start_time"`
|
||
}
|
||
type listGuildMembersResponse struct {
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
Total int64 `json:"total"`
|
||
List []memberItem `json:"list"`
|
||
}
|
||
|
||
// ListGuildMembers 查看工会成员
|
||
// @Summary 查看工会成员
|
||
// @Description 查看指定工会的成员列表
|
||
// @Tags 管理端.工会
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param guild_id path integer true "工会ID"
|
||
// @Param page query int true "页码" default(1)
|
||
// @Param page_size query int true "每页数量,最多100" default(20)
|
||
// @Success 200 {object} listGuildMembersResponse
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/admin/guilds/{guild_id}/members [get]
|
||
// @Security LoginVerifyToken
|
||
func (h *handler) ListGuildMembers() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(listGuildMembersRequest)
|
||
res := new(listGuildMembersResponse)
|
||
if err := ctx.ShouldBindForm(req); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
||
return
|
||
}
|
||
if ctx.SessionUserInfo().IsSuper != 1 {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListGuildMembersError, "禁止操作"))
|
||
return
|
||
}
|
||
id, err := strconv.ParseInt(ctx.Param("guild_id"), 10, 64)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递工会ID"))
|
||
return
|
||
}
|
||
items, total, err := h.guild.ListMembers(ctx.RequestContext(), id, req.Page, req.PageSize)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListGuildMembersError, err.Error()))
|
||
return
|
||
}
|
||
res.Page = req.Page
|
||
res.PageSize = req.PageSize
|
||
res.Total = total
|
||
res.List = make([]memberItem, len(items))
|
||
for i, v := range items {
|
||
res.List[i] = memberItem{ID: v.ID, UserID: v.UserID, Role: v.Role, StartTime: v.StartTime.Format("2006-01-02 15:04:05")}
|
||
}
|
||
ctx.Payload(res)
|
||
}
|
||
}
|