package price import ( "cls-server/internal/application/price" "cls-server/internal/interfaces" "cls-server/pkg/logger" "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.POST("/create", h.create) auth.GET("/get", h.getPrice) auth.PUT("/update", h.update) //auth.GET("/page", h.getPriceList) } } func (h *PriceHandler) create(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.SetPrice(dto) if err != nil { h.log.Error(err) c.AbortWithStatus(http.StatusInternalServerError) } else { c.AbortWithStatus(http.StatusOK) } } func (h *PriceHandler) getPrice(c *gin.Context) { dto := &price.PriceDto{} err := c.ShouldBindJSON(dto) if err != nil { h.log.Error(err.Error()) c.AbortWithStatus(http.StatusInternalServerError) return } price, err := h.service.GetPrice(dto) if err != nil { h.log.Error(err) c.AbortWithStatus(http.StatusInternalServerError) return } c.JSON(http.StatusOK, price) } 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) getPriceList(c *gin.Context) { // page := &page.Page{} // err := c.ShouldBindJSON(page) // if err != nil { // h.log.Error(err.Error()) // c.AbortWithStatus(http.StatusInternalServerError) // return // } // err = h.service.GetPriceList(page, map[string]string{ // "search_eq_type": c.Query("search_eq_type"), // }) // if err != nil { // h.log.Error(err) // c.AbortWithStatus(http.StatusInternalServerError) // return // } // c.JSON(http.StatusOK, page) //}