58c346abec
- PUT /admin/lottery/prizes/:id、DELETE /admin/lottery/prizes/:id
- handler 从 c.Param("id") 取 id;types 用 path:"id"
- 同步 apis/admin/lottery.api 定义
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
178 lines
5.5 KiB
Go
178 lines
5.5 KiB
Go
// Package lottery contains gin handlers for the admin-side lottery endpoints.
|
|
package lottery
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
adminlottery "github.com/perfect-panel/server/internal/logic/admin/lottery"
|
|
"github.com/perfect-panel/server/internal/svc"
|
|
"github.com/perfect-panel/server/internal/types"
|
|
"github.com/perfect-panel/server/pkg/result"
|
|
)
|
|
|
|
func CreateLotteryActivityHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.CreateAdminLotteryActivityRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewCreateLotteryActivityLogic(c.Request.Context(), svcCtx)
|
|
resp, err := l.CreateLotteryActivity(&req)
|
|
result.HttpResult(c, resp, err)
|
|
}
|
|
}
|
|
|
|
func UpdateLotteryActivityHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.UpdateAdminLotteryActivityRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewUpdateLotteryActivityLogic(c.Request.Context(), svcCtx)
|
|
resp, err := l.UpdateLotteryActivity(&req)
|
|
result.HttpResult(c, resp, err)
|
|
}
|
|
}
|
|
|
|
func ListLotteryActivitiesHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.ListAdminLotteryActivitiesRequest
|
|
_ = c.ShouldBind(&req)
|
|
l := adminlottery.NewListLotteryActivitiesLogic(c.Request.Context(), svcCtx)
|
|
resp, err := l.ListLotteryActivities(&req)
|
|
result.HttpResult(c, resp, err)
|
|
}
|
|
}
|
|
|
|
func GetLotteryActivityHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.AdminActivityIdRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewGetLotteryActivityLogic(c.Request.Context(), svcCtx)
|
|
resp, err := l.GetLotteryActivity(&req)
|
|
result.HttpResult(c, resp, err)
|
|
}
|
|
}
|
|
|
|
func PublishLotteryActivityHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.AdminActivityIdRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewPublishLotteryActivityLogic(c.Request.Context(), svcCtx)
|
|
result.HttpResult(c, nil, l.PublishLotteryActivity(&req))
|
|
}
|
|
}
|
|
|
|
func PauseLotteryActivityHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.AdminActivityIdRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewPauseLotteryActivityLogic(c.Request.Context(), svcCtx)
|
|
result.HttpResult(c, nil, l.PauseLotteryActivity(&req))
|
|
}
|
|
}
|
|
|
|
func UpdateLotteryRulesHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.UpdateAdminLotteryRulesRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewUpdateLotteryRulesLogic(c.Request.Context(), svcCtx)
|
|
result.HttpResult(c, nil, l.UpdateLotteryRules(&req))
|
|
}
|
|
}
|
|
|
|
func CreateLotteryPrizeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.CreateAdminLotteryPrizeRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewCreateLotteryPrizeLogic(c.Request.Context(), svcCtx)
|
|
resp, err := l.CreateLotteryPrize(&req)
|
|
result.HttpResult(c, resp, err)
|
|
}
|
|
}
|
|
|
|
func UpdateLotteryPrizeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.UpdateAdminLotteryPrizeRequest
|
|
_ = c.ShouldBind(&req)
|
|
if id, err := strconv.ParseInt(c.Param("id"), 10, 64); err == nil {
|
|
req.Id = id
|
|
}
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewUpdateLotteryPrizeLogic(c.Request.Context(), svcCtx)
|
|
resp, err := l.UpdateLotteryPrize(&req)
|
|
result.HttpResult(c, resp, err)
|
|
}
|
|
}
|
|
|
|
func DeleteLotteryPrizeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.AdminPrizeIdRequest
|
|
_ = c.ShouldBind(&req)
|
|
if id, err := strconv.ParseInt(c.Param("id"), 10, 64); err == nil {
|
|
req.Id = id
|
|
}
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewDeleteLotteryPrizeLogic(c.Request.Context(), svcCtx)
|
|
result.HttpResult(c, nil, l.DeleteLotteryPrize(&req))
|
|
}
|
|
}
|
|
|
|
func ListLotteryPrizesHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.ListAdminLotteryPrizesRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewListLotteryPrizesLogic(c.Request.Context(), svcCtx)
|
|
resp, err := l.ListLotteryPrizes(&req)
|
|
result.HttpResult(c, resp, err)
|
|
}
|
|
}
|
|
|
|
func GrantLotteryChanceHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var req types.GrantAdminLotteryChanceRequest
|
|
_ = c.ShouldBind(&req)
|
|
if err := svcCtx.Validate(&req); err != nil {
|
|
result.ParamErrorResult(c, err)
|
|
return
|
|
}
|
|
l := adminlottery.NewGrantLotteryChanceLogic(c.Request.Context(), svcCtx)
|
|
result.HttpResult(c, nil, l.GrantLotteryChance(&req))
|
|
}
|
|
}
|