109 lines
3.5 KiB
Go
109 lines
3.5 KiB
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"chatapp3-golang/internal/service/weekstar"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// registerWeekStarRoutes 注册指定礼物周榜路由。
|
|
func registerWeekStarRoutes(engine *gin.Engine, javaClient authGateway, weekStarService *weekstar.WeekStarService) {
|
|
if weekStarService == nil {
|
|
return
|
|
}
|
|
|
|
engine.GET("/public/h5/week-star/page", func(c *gin.Context) {
|
|
resp, err := weekStarService.GetPublicPage(c.Request.Context(), c.Query("sysOrigin"))
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
registerSpecifiedGiftWeeklyRankRoutes(engine.Group("/resident-activity/specified-gift-weekly-rank"), javaClient, weekStarService)
|
|
registerSpecifiedGiftWeeklyRankRoutes(engine.Group("/resident-activity/week-star"), javaClient, weekStarService)
|
|
}
|
|
|
|
// registerSpecifiedGiftWeeklyRankRoutes 注册周榜后台配置、快照和发奖记录路由。
|
|
func registerSpecifiedGiftWeeklyRankRoutes(group *gin.RouterGroup, javaClient authGateway, weekStarService *weekstar.WeekStarService) {
|
|
group.Use(consoleAuthMiddleware(javaClient))
|
|
|
|
group.GET("/config/page", func(c *gin.Context) {
|
|
cursor, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("cursor", "1")))
|
|
limit, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("limit", "20")))
|
|
resp, err := weekStarService.PageConfigs(c.Request.Context(), c.Query("sysOrigin"), cursor, limit)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
group.GET("/config", func(c *gin.Context) {
|
|
id, _ := strconv.ParseInt(strings.TrimSpace(c.Query("id")), 10, 64)
|
|
resp, err := weekStarService.GetConfig(c.Request.Context(), c.Query("sysOrigin"), id)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
group.POST("/config/save", func(c *gin.Context) {
|
|
var req weekstar.SaveWeekStarConfigRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, weekstar.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := weekStarService.SaveConfig(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
group.GET("/snapshot/page", func(c *gin.Context) {
|
|
cursor, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("cursor", "1")))
|
|
limit, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("limit", "20")))
|
|
configID, _ := strconv.ParseInt(strings.TrimSpace(c.Query("configId")), 10, 64)
|
|
resp, err := weekStarService.PageSnapshots(c.Request.Context(), c.Query("sysOrigin"), configID, c.Query("cycleKey"), cursor, limit)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
group.GET("/reward-record/page", func(c *gin.Context) {
|
|
cursor, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("cursor", "1")))
|
|
limit, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("limit", "20")))
|
|
configID, _ := strconv.ParseInt(strings.TrimSpace(c.Query("configId")), 10, 64)
|
|
resp, err := weekStarService.PageRewardRecords(c.Request.Context(), c.Query("sysOrigin"), configID, c.Query("cycleKey"), c.Query("status"), cursor, limit)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
group.POST("/reward-record/retry", func(c *gin.Context) {
|
|
var req weekstar.WeekStarRetryRewardRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, weekstar.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := weekStarService.RetryRewardRecord(c.Request.Context(), req.ID.Int64())
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
}
|