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: 添加道具卡测试脚本
224 lines
7.0 KiB
Go
224 lines
7.0 KiB
Go
package admin
|
||
|
||
import (
|
||
"net/http"
|
||
"strconv"
|
||
|
||
"bindbox-game/internal/code"
|
||
"bindbox-game/internal/pkg/core"
|
||
"bindbox-game/internal/pkg/validation"
|
||
activitysvc "bindbox-game/internal/service/activity"
|
||
)
|
||
|
||
type listIssuesRequest struct {
|
||
Page int `form:"page"`
|
||
PageSize int `form:"page_size"`
|
||
}
|
||
|
||
type listIssuesResponse struct {
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
Total int64 `json:"total"`
|
||
List []*activitysvcIssueData `json:"list"`
|
||
}
|
||
|
||
type activitysvcIssueData struct {
|
||
ID int64 `json:"id"`
|
||
IssueNumber string `json:"issue_number"`
|
||
Status int32 `json:"status"`
|
||
Sort int32 `json:"sort"`
|
||
}
|
||
|
||
// ListActivityIssues 查看活动期数
|
||
// @Summary 查看活动期数
|
||
// @Description 获取指定活动的期数列表,支持分页
|
||
// @Tags 管理端.活动
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param activity_id path integer true "活动ID"
|
||
// @Param page query int true "页码" default(1)
|
||
// @Param page_size query int true "每页数量,最多100" default(20)
|
||
// @Success 200 {object} listIssuesResponse
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/admin/activities/{activity_id}/issues [get]
|
||
// @Security LoginVerifyToken
|
||
func (h *handler) ListActivityIssues() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(listIssuesRequest)
|
||
res := new(listIssuesResponse)
|
||
if err := ctx.ShouldBindForm(req); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
||
return
|
||
}
|
||
id, err := strconv.ParseInt(ctx.Param("activity_id"), 10, 64)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递活动ID"))
|
||
return
|
||
}
|
||
if req.Page <= 0 {
|
||
req.Page = 1
|
||
}
|
||
if req.PageSize <= 0 {
|
||
req.PageSize = 20
|
||
}
|
||
items, total, err := h.activity.ListIssues(ctx.RequestContext(), id, req.Page, req.PageSize)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListActivityIssuesError, err.Error()))
|
||
return
|
||
}
|
||
res.Page = req.Page
|
||
res.PageSize = req.PageSize
|
||
res.Total = total
|
||
res.List = make([]*activitysvcIssueData, len(items))
|
||
for i, v := range items {
|
||
res.List[i] = &activitysvcIssueData{
|
||
ID: v.ID,
|
||
IssueNumber: v.IssueNumber,
|
||
Status: v.Status,
|
||
Sort: v.Sort,
|
||
}
|
||
}
|
||
ctx.Payload(res)
|
||
}
|
||
}
|
||
|
||
type createIssueRequest struct {
|
||
IssueNumber string `json:"issue_number" binding:"required"`
|
||
Status int32 `json:"status"`
|
||
Sort int32 `json:"sort"`
|
||
}
|
||
|
||
type createIssueResp struct {
|
||
ID int64 `json:"id"`
|
||
Message string `json:"message"`
|
||
}
|
||
type simpleMessage struct {
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// CreateActivityIssue 创建活动期数
|
||
// @Summary 创建活动期数
|
||
// @Description 为指定活动创建一个新的期数
|
||
// @Tags 管理端.活动
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param activity_id path integer true "活动ID"
|
||
// @Param RequestBody body createIssueRequest true "请求参数"
|
||
// @Success 200 {object} simpleMessage
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/admin/activities/{activity_id}/issues [post]
|
||
// @Security LoginVerifyToken
|
||
func (h *handler) CreateActivityIssue() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(createIssueRequest)
|
||
res := new(createIssueResp)
|
||
if err := ctx.ShouldBindJSON(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.CreateActivityIssueError, "禁止操作"))
|
||
return
|
||
}
|
||
id, err := strconv.ParseInt(ctx.Param("activity_id"), 10, 64)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递活动ID"))
|
||
return
|
||
}
|
||
item, err := h.activity.CreateIssue(ctx.RequestContext(), id, activitysvc.CreateIssueInput{
|
||
IssueNumber: req.IssueNumber,
|
||
Status: req.Status,
|
||
Sort: req.Sort,
|
||
})
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.CreateActivityIssueError, err.Error()))
|
||
return
|
||
}
|
||
res.ID = item.ID
|
||
res.Message = "操作成功"
|
||
ctx.Payload(res)
|
||
}
|
||
}
|
||
|
||
type modifyIssueRequest struct {
|
||
IssueNumber string `json:"issue_number"`
|
||
Status int32 `json:"status"`
|
||
Sort int32 `json:"sort"`
|
||
}
|
||
|
||
// ModifyActivityIssue 修改活动期数
|
||
// @Summary 修改活动期数
|
||
// @Description 修改指定期数的信息
|
||
// @Tags 管理端.活动
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param activity_id path integer true "活动ID"
|
||
// @Param issue_id path integer true "期ID"
|
||
// @Param RequestBody body modifyIssueRequest true "请求参数"
|
||
// @Success 200 {object} simpleMessage
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/admin/activities/{activity_id}/issues/{issue_id} [put]
|
||
// @Security LoginVerifyToken
|
||
func (h *handler) ModifyActivityIssue() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(modifyIssueRequest)
|
||
res := new(simpleMessage)
|
||
if err := ctx.ShouldBindJSON(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.ModifyActivityIssueError, "禁止操作"))
|
||
return
|
||
}
|
||
issueID, err := strconv.ParseInt(ctx.Param("issue_id"), 10, 64)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递期ID"))
|
||
return
|
||
}
|
||
if err := h.activity.ModifyIssue(ctx.RequestContext(), issueID, activitysvc.ModifyIssueInput{
|
||
IssueNumber: req.IssueNumber,
|
||
Status: req.Status,
|
||
Sort: req.Sort,
|
||
}); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ModifyActivityIssueError, err.Error()))
|
||
return
|
||
}
|
||
res.Message = "操作成功"
|
||
ctx.Payload(res)
|
||
}
|
||
}
|
||
|
||
// DeleteActivityIssue 删除活动期数
|
||
// @Summary 删除活动期数
|
||
// @Description 删除指定期数
|
||
// @Tags 管理端.活动
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param activity_id path integer true "活动ID"
|
||
// @Param issue_id path integer true "期ID"
|
||
// @Success 200 {object} simpleMessage
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/admin/activities/{activity_id}/issues/{issue_id} [delete]
|
||
// @Security LoginVerifyToken
|
||
func (h *handler) DeleteActivityIssue() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
res := new(simpleMessage)
|
||
if ctx.SessionUserInfo().IsSuper != 1 {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.DeleteActivityIssueError, "禁止操作"))
|
||
return
|
||
}
|
||
issueID, err := strconv.ParseInt(ctx.Param("issue_id"), 10, 64)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递期ID"))
|
||
return
|
||
}
|
||
if err := h.activity.DeleteIssue(ctx.RequestContext(), issueID); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.DeleteActivityIssueError, err.Error()))
|
||
return
|
||
}
|
||
res.Message = "操作成功"
|
||
ctx.Payload(res)
|
||
}
|
||
}
|