You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.6 KiB
Go
114 lines
2.6 KiB
Go
package price
|
|
|
|
import (
|
|
"cls-server/internal/application/price"
|
|
"cls-server/internal/interfaces"
|
|
"cls-server/pkg/logger"
|
|
"cls-server/pkg/util/page"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
type PriceHandler struct {
|
|
service *price.PriceService
|
|
log logger.Logger
|
|
}
|
|
|
|
var _ interfaces.Handler = (*PriceHandler)(nil)
|
|
|
|
func NewPriceHandler(service *price.PriceService, log logger.New) *PriceHandler {
|
|
return &PriceHandler{service, log("cls:interfaces:price")}
|
|
}
|
|
|
|
func (h *PriceHandler) RegisterRouters(app gin.IRouter) {
|
|
auth := app.Group("/price")
|
|
{
|
|
auth.GET("/page-article", h.getPriceArticle)
|
|
auth.GET("/page-column", h.getPriceColumn)
|
|
auth.GET("/get-default", h.getPriceDefault)
|
|
auth.POST("/update-default", h.updatePriceDefault)
|
|
auth.POST("/update", h.update)
|
|
}
|
|
}
|
|
|
|
func (h *PriceHandler) update(c *gin.Context) {
|
|
dto := &price.PriceDto{}
|
|
err := c.ShouldBindJSON(dto)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
err = h.service.UpdatePrice(dto)
|
|
if err != nil {
|
|
h.log.Error(err)
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
} else {
|
|
c.AbortWithStatus(http.StatusOK)
|
|
}
|
|
}
|
|
|
|
func (h *PriceHandler) getPriceDefault(c *gin.Context) {
|
|
fmt.Println("进来了getPriceDefault………………")
|
|
|
|
p, err := h.service.GetPriceDefault()
|
|
if err != nil {
|
|
h.log.Error(err)
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, p)
|
|
}
|
|
|
|
func (h *PriceHandler) updatePriceDefault(c *gin.Context) {
|
|
dto := &price.PriceDefaultDto{}
|
|
err := c.ShouldBindJSON(dto)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
err = h.service.UpdatePriceDefault(dto)
|
|
if err != nil {
|
|
h.log.Error(err)
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
} else {
|
|
c.AbortWithStatus(http.StatusOK)
|
|
}
|
|
}
|
|
|
|
func (h *PriceHandler) getPriceArticle(c *gin.Context) {
|
|
p := &page.Page{}
|
|
err := c.ShouldBindQuery(p)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
err = h.service.GetArticlePricePage(p)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
} else {
|
|
c.JSON(http.StatusOK, p)
|
|
}
|
|
}
|
|
|
|
func (h *PriceHandler) getPriceColumn(c *gin.Context) {
|
|
p := &page.Page{}
|
|
err := c.ShouldBindQuery(p)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
err = h.service.GetColumnPricePage(p)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
} else {
|
|
c.JSON(http.StatusOK, p)
|
|
}
|
|
}
|