2022-09-02 01:52:40 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2022-09-24 19:33:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/repo"
|
2022-09-02 01:52:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type LabelService struct {
|
|
|
|
repos *repo.AllRepos
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
func (svc *LabelService) Create(ctx context.Context, groupId uuid.UUID, data repo.LabelCreate) (repo.LabelOut, error) {
|
|
|
|
return svc.repos.Labels.Create(ctx, groupId, data)
|
2022-09-02 01:52:40 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
func (svc *LabelService) Update(ctx context.Context, groupId uuid.UUID, data repo.LabelUpdate) (repo.LabelOut, error) {
|
|
|
|
return svc.repos.Labels.Update(ctx, data)
|
2022-09-02 01:52:40 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
func (svc *LabelService) Delete(ctx context.Context, gid uuid.UUID, id uuid.UUID) error {
|
|
|
|
_, err := svc.repos.Labels.GetOneByGroup(ctx, gid, id)
|
2022-09-02 01:52:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return svc.repos.Labels.Delete(ctx, id)
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
func (svc *LabelService) Get(ctx context.Context, gid uuid.UUID, id uuid.UUID) (repo.LabelOut, error) {
|
|
|
|
return svc.repos.Labels.GetOneByGroup(ctx, gid, id)
|
2022-09-02 01:52:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-27 23:52:13 +00:00
|
|
|
func (svc *LabelService) GetAll(ctx context.Context, groupId uuid.UUID) ([]repo.LabelSummary, error) {
|
|
|
|
return svc.repos.Labels.GetAll(ctx, groupId)
|
2022-09-02 01:52:40 +00:00
|
|
|
}
|