labels service impl

This commit is contained in:
nquidox 2026-03-13 16:51:34 +03:00
parent 229e438367
commit c1e8922968

View file

@ -1,31 +1,67 @@
package merch package merch
import "context" import (
"context"
"github.com/gofrs/uuid"
)
func (s *service) createLabel(ctx context.Context, userId int64, label *LabelDTO) error { func (s *service) createLabel(ctx context.Context, userId int64, label *LabelDTO) error {
if label == nil {
logWarn(serviceLogHeader, "label payload is empty")
return nil 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)
} }
func (s *service) getLabels(ctx context.Context, userId int64) ([]LabelsList, error) { func (s *service) getLabels(ctx context.Context, userId int64) ([]LabelsList, error) {
return nil, nil return s.repo.getLabels(ctx, userId)
} }
func (s *service) updateLabel(ctx context.Context, userId int64, labelUuid string, payload *LabelDTO) error { func (s *service) updateLabel(ctx context.Context, userId int64, labelUuid string, payload *LabelDTO) error {
return nil
l := Label{
UpdatedAt: s.utils.NullTimeNowUTC(),
Uuid: labelUuid,
Name: payload.Name,
Color: payload.Color,
BgColor: payload.BgColor,
}
return s.repo.updateLabel(ctx, userId, &l)
} }
func (s *service) deleteLabel(ctx context.Context, userId int64, labelUuid string) error { func (s *service) deleteLabel(ctx context.Context, userId int64, labelUuid string) error {
return nil return s.repo.deleteLabel(ctx, userId, labelUuid, s.utils.NullTimeNowUTC())
} }
func (s *service) attachLabel(ctx context.Context, userId int64, payload *LabelLink) error { func (s *service) attachLabel(ctx context.Context, userId int64, payload *LabelLink) error {
return nil return s.repo.attachLabel(ctx, userId, payload)
} }
func (s *service) detachLabel(ctx context.Context, userId int64, payload *LabelLink) error { func (s *service) detachLabel(ctx context.Context, userId int64, payload *LabelLink) error {
return nil return s.repo.detachLabel(ctx, userId, payload)
} }
func (s *service) getMerchLabels(ctx context.Context, userId int64, merchUuid string) ([]string, error) { func (s *service) getMerchLabels(ctx context.Context, userId int64, merchUuid string) ([]string, error) {
return nil, nil return s.repo.getAttachedLabelsByUuid(ctx, userId, merchUuid)
} }