60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"chatapp3-golang/internal/service/rechargeagency"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// registerRechargeAgencyRoutes 注册充值代理 H5 币商名单路由。
|
|
func registerRechargeAgencyRoutes(engine *gin.Engine, javaClient authGateway, service *rechargeagency.Service) {
|
|
if service == nil {
|
|
return
|
|
}
|
|
|
|
handler := func(c *gin.Context) {
|
|
cursor, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("cursor", "1")))
|
|
limit, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("limit", "20")))
|
|
|
|
resp, err := service.PageSellers(c.Request.Context(), mustAuthUser(c), cursor, limit)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
}
|
|
|
|
listGroup := engine.Group("/app/h5/recharge-agency-list")
|
|
listGroup.Use(authMiddleware(javaClient))
|
|
listGroup.GET("/sellers", handler)
|
|
|
|
agencyGroup := engine.Group("/app/h5/recharge-agency")
|
|
agencyGroup.Use(authMiddleware(javaClient))
|
|
agencyGroup.GET("/sellers", handler)
|
|
agencyGroup.GET("/profile", func(c *gin.Context) {
|
|
resp, err := service.GetProfile(c.Request.Context(), mustAuthUser(c))
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
agencyGroup.POST("/profile/whatsapp", func(c *gin.Context) {
|
|
var req rechargeagency.UpdateWhatsappRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, rechargeagency.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := service.UpdateWhatsapp(c.Request.Context(), mustAuthUser(c), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
}
|