2026-03-13 16:02:49 +03:00
|
|
|
package merch
|
|
|
|
|
|
2026-03-13 16:51:34 +03:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"github.com/gofrs/uuid"
|
|
|
|
|
)
|
2026-03-13 16:02:49 +03:00
|
|
|
|
|
|
|
|
func (s *service) createLabel(ctx context.Context, userId int64, label *LabelDTO) error {
|
2026-03-13 16:51:34 +03:00
|
|
|
if label == nil {
|
|
|
|
|
logWarn(serviceLogHeader, "label payload is empty")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
now := s.utils.TimeNowUTC()
|
|
|
|
|
|
|
|
|
|
lUuid, err := uuid.NewV7()
|
|
|
|
|
if err != nil {
|
|
|
|
|
logErr(serviceLogHeader, err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newLabel := Label{
|
|
|
|
|
CreatedAt: now,
|
|
|
|
|
UpdatedAt: s.utils.NullTimeFromNow(now),
|
|
|
|
|
DeletedAt: s.utils.DeletedNullTime(),
|
|
|
|
|
UserId: userId,
|
|
|
|
|
Uuid: lUuid.String(),
|
|
|
|
|
Name: label.Name,
|
|
|
|
|
Color: label.Color,
|
|
|
|
|
BgColor: label.BgColor,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s.repo.createLabel(ctx, userId, &newLabel)
|
2026-03-13 16:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *service) getLabels(ctx context.Context, userId int64) ([]LabelsList, error) {
|
2026-03-13 16:51:34 +03:00
|
|
|
return s.repo.getLabels(ctx, userId)
|
2026-03-13 16:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *service) updateLabel(ctx context.Context, userId int64, labelUuid string, payload *LabelDTO) error {
|
2026-03-13 16:51:34 +03:00
|
|
|
|
|
|
|
|
l := Label{
|
|
|
|
|
UpdatedAt: s.utils.NullTimeNowUTC(),
|
|
|
|
|
Uuid: labelUuid,
|
|
|
|
|
Name: payload.Name,
|
|
|
|
|
Color: payload.Color,
|
|
|
|
|
BgColor: payload.BgColor,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s.repo.updateLabel(ctx, userId, &l)
|
2026-03-13 16:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *service) deleteLabel(ctx context.Context, userId int64, labelUuid string) error {
|
2026-03-13 16:51:34 +03:00
|
|
|
return s.repo.deleteLabel(ctx, userId, labelUuid, s.utils.NullTimeNowUTC())
|
2026-03-13 16:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *service) attachLabel(ctx context.Context, userId int64, payload *LabelLink) error {
|
2026-03-13 16:51:34 +03:00
|
|
|
return s.repo.attachLabel(ctx, userId, payload)
|
2026-03-13 16:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *service) detachLabel(ctx context.Context, userId int64, payload *LabelLink) error {
|
2026-03-13 16:51:34 +03:00
|
|
|
return s.repo.detachLabel(ctx, userId, payload)
|
2026-03-13 16:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *service) getMerchLabels(ctx context.Context, userId int64, merchUuid string) ([]string, error) {
|
2026-03-13 16:51:34 +03:00
|
|
|
return s.repo.getAttachedLabelsByUuid(ctx, userId, merchUuid)
|
2026-03-13 16:02:49 +03:00
|
|
|
}
|