46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"chatapp3-golang/internal/service/propsstore"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// registerPropsStoreRoutes registers admin props store routes.
|
|
func registerPropsStoreRoutes(engine *gin.Engine, javaClient authGateway, service *propsstore.Service) {
|
|
if service == nil {
|
|
return
|
|
}
|
|
|
|
adminGroup := engine.Group("/props/store")
|
|
adminGroup.Use(consoleAuthMiddleware(javaClient))
|
|
adminGroup.POST("/source-map", func(c *gin.Context) {
|
|
var req propsstore.MapBySourceIDsRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, propsstore.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := service.MapBySourceIDs(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
adminGroup.POST("/add-or-update", func(c *gin.Context) {
|
|
var req propsstore.SaveCommodityRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, propsstore.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := service.SaveCommodity(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
}
|