34 lines
893 B
Go
34 lines
893 B
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"chatapp3-golang/internal/config"
|
|
"chatapp3-golang/internal/service/luckygift"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// registerLuckyGiftRoutes 注册幸运礼物内部路由。
|
|
func registerLuckyGiftRoutes(engine *gin.Engine, cfg config.Config, luckyGiftService *luckygift.LuckyGiftService) {
|
|
if luckyGiftService == nil {
|
|
return
|
|
}
|
|
|
|
internalGroup := engine.Group("/internal/lucky-gift")
|
|
internalGroup.Use(internalSecretMiddleware(cfg.HTTP.InternalCallbackSecret))
|
|
internalGroup.POST("/draw", func(c *gin.Context) {
|
|
var req luckygift.LuckyGiftDrawRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, luckygift.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := luckyGiftService.Draw(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
}
|