labels dto + controller + service placeholders
This commit is contained in:
parent
569480ba26
commit
1991e9aec8
3 changed files with 270 additions and 0 deletions
|
|
@ -48,6 +48,14 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
|
||||||
|
|
||||||
zeroPricesGroup.DELETE("/period", h.controller.deleteZeroPricesPeriod)
|
zeroPricesGroup.DELETE("/period", h.controller.deleteZeroPricesPeriod)
|
||||||
|
|
||||||
|
labelsGroup := merchGroup.Group("/labels")
|
||||||
|
labelsGroup.POST("", h.controller.createLabel)
|
||||||
|
labelsGroup.GET("", h.controller.getLabels)
|
||||||
|
labelsGroup.PUT("/:uuid", h.controller.updateLabel)
|
||||||
|
labelsGroup.DELETE("/:uuid", h.controller.deleteLabel)
|
||||||
|
labelsGroup.POST("/attach", h.controller.attachLabel)
|
||||||
|
labelsGroup.POST("/detach", h.controller.detachLabel)
|
||||||
|
labelsGroup.GET("/:uuid", h.controller.getMerchLabels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create godoc
|
// create godoc
|
||||||
|
|
@ -436,6 +444,8 @@ func (co *controller) deleteZeroPrices(c *gin.Context) {
|
||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deleteZeroPricesPeriod godoc
|
||||||
|
//
|
||||||
// @Summary Пометить нулевые цены как удаленные за указанный период
|
// @Summary Пометить нулевые цены как удаленные за указанный период
|
||||||
// @Description Пометить нулевые цены как удаленные за указанный период
|
// @Description Пометить нулевые цены как удаленные за указанный период
|
||||||
// @Tags Merch zero prices
|
// @Tags Merch zero prices
|
||||||
|
|
@ -469,3 +479,213 @@ func (co *controller) deleteZeroPricesPeriod(c *gin.Context) {
|
||||||
}
|
}
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createLabel godoc
|
||||||
|
//
|
||||||
|
// @Summary Создать новую метку для товара
|
||||||
|
// @Description Создать новую метку для товара
|
||||||
|
// @Tags Merch labels
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept json
|
||||||
|
// @Param payload body LabelDTO true "payload"
|
||||||
|
// @Success 200
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels [post]
|
||||||
|
func (co *controller) createLabel(c *gin.Context) {
|
||||||
|
var payload LabelDTO
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := co.service.createLabel(c, getUserId(c), &payload); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getLabels godoc
|
||||||
|
//
|
||||||
|
// @Summary Получить все метки товаров
|
||||||
|
// @Description Получить все метки товаров
|
||||||
|
// @Tags Merch labels
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {array} LabelsList
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels [get]
|
||||||
|
func (co *controller) getLabels(c *gin.Context) {
|
||||||
|
response, err := co.service.getLabels(c, getUserId(c))
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateLabel godoc
|
||||||
|
//
|
||||||
|
// @Summary Изменить метку
|
||||||
|
// @Description Изменить метку
|
||||||
|
// @Tags Merch labels
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept json
|
||||||
|
// @Param uuid path string true "label uuid"
|
||||||
|
// @Param payload body LabelDTO true "payload"
|
||||||
|
// @Success 200
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels/{uuid} [put]
|
||||||
|
func (co *controller) updateLabel(c *gin.Context) {
|
||||||
|
labelUuid := c.Param("uuid")
|
||||||
|
if labelUuid == "" {
|
||||||
|
e := errors.New("LabelUuid is empty")
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: e.Error()})
|
||||||
|
logErr(controllerLogHeader, e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload LabelDTO
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := co.service.updateLabel(c, getUserId(c), labelUuid, &payload); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteLabel godoc
|
||||||
|
//
|
||||||
|
// @Summary Пометить метку как удаленную
|
||||||
|
// @Description Пометить метку как удаленную
|
||||||
|
// @Tags Merch labels
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param uuid path string true "label uuid"
|
||||||
|
// @Success 200
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels/{uuid} [delete]
|
||||||
|
func (co *controller) deleteLabel(c *gin.Context) {
|
||||||
|
labelUuid := c.Param("uuid")
|
||||||
|
if labelUuid == "" {
|
||||||
|
e := errors.New("LabelUuid is empty")
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: e.Error()})
|
||||||
|
logErr(controllerLogHeader, e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := co.service.deleteLabel(c, getUserId(c), labelUuid); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// attachLabel godoc
|
||||||
|
//
|
||||||
|
// @Summary Прикрепить метку к товару
|
||||||
|
// @Description Прикрепить метку к товару
|
||||||
|
// @Tags Merch labels
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept json
|
||||||
|
// @Param payload body LabelLink true "payload"
|
||||||
|
// @Success 200
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels/attach [post]
|
||||||
|
func (co *controller) attachLabel(c *gin.Context) {
|
||||||
|
var payload LabelLink
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := co.service.attachLabel(c, getUserId(c), &payload); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// detachLabel godoc
|
||||||
|
//
|
||||||
|
// @Summary Удалить привязку метки к товару
|
||||||
|
// @Description Удалить привязку метки к товару
|
||||||
|
// @Tags Merch labels
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Accept json
|
||||||
|
// @Param payload body LabelLink true "payload"
|
||||||
|
// @Success 200
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels/detach [post]
|
||||||
|
func (co *controller) detachLabel(c *gin.Context) {
|
||||||
|
var payload LabelLink
|
||||||
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := co.service.detachLabel(c, getUserId(c), &payload); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getMerchLabels godoc
|
||||||
|
//
|
||||||
|
// @Summary Получить метки товара по его uuid
|
||||||
|
// @Description Получить метки товара по его uuid
|
||||||
|
// @Tags Merch labels
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Produce json
|
||||||
|
// @Param uuid path string true "label uuid"
|
||||||
|
// @Success 200
|
||||||
|
// @Failure 400 {object} responses.BadRequest
|
||||||
|
// @Failure 401 {object} responses.Unauthorized
|
||||||
|
// @Failure 500 {object} responses.InternalServerError
|
||||||
|
// @Router /merch/labels/{uuid} [get]
|
||||||
|
func (co *controller) getMerchLabels(c *gin.Context) {
|
||||||
|
merchUuid := c.Param("uuid")
|
||||||
|
if merchUuid == "" {
|
||||||
|
e := errors.New("MerchUuid is empty")
|
||||||
|
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: e.Error()})
|
||||||
|
logErr(controllerLogHeader, e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := co.service.getMerchLabels(c, getUserId(c), merchUuid)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||||
|
logErr(controllerLogHeader, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,3 +75,22 @@ type DeleteZeroPrices struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
MerchUuid string `json:"merch_uuid"`
|
MerchUuid string `json:"merch_uuid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Labels
|
||||||
|
type LabelDTO struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Color string `json:"color,omitempty"`
|
||||||
|
BgColor string `json:"bg_color,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LabelsList struct {
|
||||||
|
LabelUuid string `json:"label_uuid"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Color string `json:"color,omitempty"`
|
||||||
|
BgColor string `json:"bg_color,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LabelLink struct {
|
||||||
|
MerchUuid string `json:"merch_uuid"`
|
||||||
|
LabelUuid string `json:"label_uuid"`
|
||||||
|
}
|
||||||
|
|
|
||||||
31
internal/merch/service_labels.go
Normal file
31
internal/merch/service_labels.go
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
package merch
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
func (s *service) createLabel(ctx context.Context, userId int64, label *LabelDTO) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) getLabels(ctx context.Context, userId int64) ([]LabelsList, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) updateLabel(ctx context.Context, userId int64, labelUuid string, payload *LabelDTO) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) deleteLabel(ctx context.Context, userId int64, labelUuid string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) attachLabel(ctx context.Context, userId int64, payload *LabelLink) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) detachLabel(ctx context.Context, userId int64, payload *LabelLink) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) getMerchLabels(ctx context.Context, userId int64, merchUuid string) ([]string, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue