71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package router
|
|
|
|
import (
|
|
"chatapp3-golang/internal/service/signinreward"
|
|
"net/http"
|
|
|
|
"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.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)
|
|
})
|
|
}
|