diff --git a/internal/api/merch/controller.go b/internal/api/merch/controller.go index 41a6983..7f0ae7a 100644 --- a/internal/api/merch/controller.go +++ b/internal/api/merch/controller.go @@ -43,14 +43,13 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup, authMW gin.HandlerFunc, ref imagesGroup.GET("/:uuid", h.controller.getMerchImage) imagesGroup.DELETE("/:uuid", h.controller.deleteMerchImage) - labelsGroup := merchGroup.Group("/labels", authMW) + 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) } // @Summary Добавить новый мерч @@ -631,38 +630,3 @@ func (co *controller) detachLabel(c *gin.Context) { } c.Status(http.StatusOK) } - -// @Summary Получить метки товара по его uuid -// @Description Получить метки товара по его uuid -// @Tags Merch labels -// @Security BearerAuth -// @Param uuid path string true "label uuid" -// @Success 200 -// @Failure 400 {object} responses.ErrorResponse400 -// @Failure 500 {object} responses.ErrorResponse500 -// @Router /merch/labels/{uuid} [get] -func (co *controller) getMerchLabels(c *gin.Context) { - const logMsg = "Merch | Get merch labels" - - userUuid, err := co.utils.GetUserUuidFromContext(c) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - - merchUuid := c.Param("uuid") - if merchUuid == "" { - c.JSON(http.StatusBadRequest, responses.ErrorResponse400{Error: "label uuid is empty"}) - log.WithError(err).Error(logMsg) - return - } - - response, err := co.service.getMerchLabels(userUuid, merchUuid) - if err != nil { - c.JSON(http.StatusInternalServerError, responses.ErrorResponse500{Error: err.Error()}) - log.WithError(err).Error(logMsg) - return - } - c.JSON(http.StatusOK, response) -} diff --git a/internal/api/merch/dto.go b/internal/api/merch/dto.go index 2f267b1..ad63c26 100644 --- a/internal/api/merch/dto.go +++ b/internal/api/merch/dto.go @@ -10,7 +10,6 @@ type MerchDTO struct { Name string `json:"name"` OriginSurugaya SurugayaDTO `json:"origin_surugaya"` OriginMandarake MandarakeDTO `json:"origin_mandarake"` - Labels []string `json:"labels,omitempty" gorm:"-"` } type SurugayaDTO struct { diff --git a/internal/api/merch/repository.go b/internal/api/merch/repository.go index b5ecf39..d1567de 100644 --- a/internal/api/merch/repository.go +++ b/internal/api/merch/repository.go @@ -48,7 +48,6 @@ type labels interface { attachLabel(label CardLabel) error detachLabel(label CardLabel) error getAttachedLabelsByList(list []string) ([]CardLabel, error) - getAttachedLabelsByUuid(userUuid, merchUuid string) ([]CardLabel, error) } func (r *Repo) addMerch(bundle merchBundle) error { @@ -301,13 +300,3 @@ func (r *Repo) getAttachedLabelsByList(list []string) ([]CardLabel, error) { return labelsList, nil } - -func (r *Repo) getAttachedLabelsByUuid(userUuid, merchUuid string) ([]CardLabel, error) { - var labelsList []CardLabel - - if err := r.db.Model(&CardLabel{}).Where("user_uuid = ? AND merch_uuid = ?", userUuid, merchUuid).Find(&labelsList).Error; err != nil { - return nil, err - } - - return labelsList, nil -} diff --git a/internal/api/merch/service.go b/internal/api/merch/service.go index 4689453..1632329 100644 --- a/internal/api/merch/service.go +++ b/internal/api/merch/service.go @@ -411,14 +411,13 @@ func (s *service) deleteMerchImage(ctx context.Context, userUuid, merchUuid stri return fmt.Errorf("no merch found for user %s with uuid %s", userUuid, merchUuid) } - //uncomment for MinIO - //if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/thumbnail.jpg", userUuid, merchUuid)); err != nil { - // return err - //} - // - //if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/full.jpg", userUuid, merchUuid)); err != nil { - // return err - //} + if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/thumbnail.jpg", userUuid, merchUuid)); err != nil { + return err + } + + if err = s.media.Delete(ctx, s.bucketName, fmt.Sprintf("%s/merch/%s/full.jpg", userUuid, merchUuid)); err != nil { + return err + } return nil } @@ -562,7 +561,7 @@ func (s *service) updateLabel(userUuid, labelUuid string, label LabelDTO) error } if label.BgColor != "" { - updateMap["bg_color"] = label.BgColor + updateMap["bgcolor"] = label.BgColor } return s.repo.updateLabel(userUuid, labelUuid, updateMap) @@ -598,17 +597,3 @@ func (s *service) detachLabel(userUuid string, label LabelLink) error { } return s.repo.detachLabel(detach) } - -func (s *service) getMerchLabels(userUuid, merchUuid string) ([]string, error) { - getLabels, err := s.repo.getAttachedLabelsByUuid(userUuid, merchUuid) - if err != nil { - return nil, err - } - - response := make([]string, 0, len(getLabels)) - for _, label := range getLabels { - response = append(response, label.LabelUuid) - } - - return response, nil -} diff --git a/migrations.sql b/migrations.sql index 1ffe7e5..b5fd81c 100644 --- a/migrations.sql +++ b/migrations.sql @@ -70,12 +70,7 @@ CREATE TABLE labels( ); CREATE TABLE card_labels ( - id BIGSERIAL PRIMARY KEY, user_uuid VARCHAR(36) NOT NULL, label_uuid VARCHAR(36) NOT NULL, merch_uuid VARCHAR(36) NOT NULL ); - -ALTER TABLE card_labels - ADD CONSTRAINT card_labels_unique_user_label_merch - UNIQUE (user_uuid, label_uuid, merch_uuid); \ No newline at end of file