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.
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package price
|
|
|
|
import (
|
|
"cls/internal/application/price"
|
|
"cls/internal/interfaces"
|
|
"cls/pkg/logger"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
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("/article/:id", h.getArticlePrice)
|
|
auth.GET("/column/:id", h.getColumnPrice)
|
|
}
|
|
}
|
|
|
|
func (h *PriceHandler) getArticlePrice(c *gin.Context) {
|
|
targetId, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
priceDto := &price.PriceDto{TargetID: uint64(targetId)}
|
|
price, err := h.service.GetArticlePrice(priceDto)
|
|
if err != nil {
|
|
h.log.Error(err)
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, price)
|
|
}
|
|
|
|
func (h *PriceHandler) getColumnPrice(c *gin.Context) {
|
|
targetId, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
h.log.Error(err.Error())
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
priceDto := &price.PriceDto{TargetID: uint64(targetId)}
|
|
price, err := h.service.GetColumnPrice(priceDto)
|
|
if err != nil {
|
|
h.log.Error(err)
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, price)
|
|
}
|