91 lines
2.3 KiB
Go
91 lines
2.3 KiB
Go
package router
|
|
|
|
import (
|
|
"chatapp3-golang/internal/service/signinreward"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// registerSignInRewardRoutes 注册签到奖励 app 与后台配置接口。
|
|
func registerSignInRewardRoutes(
|
|
engine *gin.Engine,
|
|
javaClient authGateway,
|
|
signInRewardService *signinreward.SignInRewardService,
|
|
) {
|
|
if signInRewardService == nil {
|
|
return
|
|
}
|
|
|
|
appGroup := engine.Group("/app/sign-in-reward")
|
|
appGroup.Use(authMiddleware(javaClient))
|
|
appGroup.GET("/config", func(c *gin.Context) {
|
|
resp, err := signInRewardService.GetStatus(c.Request.Context(), mustAuthUser(c))
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
appGroup.GET("/status", func(c *gin.Context) {
|
|
resp, err := signInRewardService.GetStatus(c.Request.Context(), mustAuthUser(c))
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
appGroup.POST("/check-in", func(c *gin.Context) {
|
|
resp, err := signInRewardService.CheckIn(c.Request.Context(), mustAuthUser(c))
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
residentGroup := engine.Group("/resident-activity/sign-in-reward")
|
|
residentGroup.Use(consoleAuthMiddleware(javaClient))
|
|
residentGroup.GET("/config", func(c *gin.Context) {
|
|
resp, err := signInRewardService.GetConfig(c.Request.Context(), c.Query("sysOrigin"))
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
residentGroup.GET("/record/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 := signInRewardService.PageRecords(
|
|
c.Request.Context(),
|
|
c.Query("sysOrigin"),
|
|
c.Query("claimDate"),
|
|
c.Query("status"),
|
|
signinreward.ParseSignInRewardUserID(c.Query("userId")),
|
|
cursor,
|
|
limit,
|
|
)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
residentGroup.POST("/config/save", func(c *gin.Context) {
|
|
var req signinreward.SaveSignInRewardConfigRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, signinreward.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := signInRewardService.SaveConfig(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
}
|