Compare commits
No commits in common. "8186d8a46cbfeddef48bb142fcccc6292a2bbc14" and "8ac753f63293092318f4967cfef813eb9f94f93d" have entirely different histories.
8186d8a46c
...
8ac753f632
5 changed files with 9 additions and 77 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue