forked from mirrors/homebox
refactor: repositories (#28)
* cleanup unnecessary mocks * refactor document storage location * remove unused function * move ownership to document types to repo package * move types and mappers to repo package * refactor sets to own package
This commit is contained in:
parent
2e82398e5c
commit
343290a55a
79 changed files with 3169 additions and 3160 deletions
|
@ -5,59 +5,33 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/repo"
|
||||
"github.com/hay-kot/homebox/backend/internal/services/mappers"
|
||||
"github.com/hay-kot/homebox/backend/internal/types"
|
||||
)
|
||||
|
||||
type LabelService struct {
|
||||
repos *repo.AllRepos
|
||||
}
|
||||
|
||||
func (svc *LabelService) Create(ctx context.Context, groupId uuid.UUID, data types.LabelCreate) (*types.LabelSummary, error) {
|
||||
label, err := svc.repos.Labels.Create(ctx, groupId, data)
|
||||
return mappers.ToLabelSummaryErr(label, err)
|
||||
func (svc *LabelService) Create(ctx context.Context, groupId uuid.UUID, data repo.LabelCreate) (repo.LabelOut, error) {
|
||||
return svc.repos.Labels.Create(ctx, groupId, data)
|
||||
}
|
||||
|
||||
func (svc *LabelService) Update(ctx context.Context, groupId uuid.UUID, data types.LabelUpdate) (*types.LabelSummary, error) {
|
||||
label, err := svc.repos.Labels.Update(ctx, data)
|
||||
return mappers.ToLabelSummaryErr(label, err)
|
||||
func (svc *LabelService) Update(ctx context.Context, groupId uuid.UUID, data repo.LabelUpdate) (repo.LabelOut, error) {
|
||||
return svc.repos.Labels.Update(ctx, data)
|
||||
}
|
||||
|
||||
func (svc *LabelService) Delete(ctx context.Context, groupId uuid.UUID, id uuid.UUID) error {
|
||||
label, err := svc.repos.Labels.Get(ctx, id)
|
||||
func (svc *LabelService) Delete(ctx context.Context, gid uuid.UUID, id uuid.UUID) error {
|
||||
_, err := svc.repos.Labels.GetOneByGroup(ctx, gid, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if label.Edges.Group.ID != groupId {
|
||||
return ErrNotOwner
|
||||
}
|
||||
return svc.repos.Labels.Delete(ctx, id)
|
||||
}
|
||||
|
||||
func (svc *LabelService) Get(ctx context.Context, groupId uuid.UUID, id uuid.UUID) (*types.LabelOut, error) {
|
||||
label, err := svc.repos.Labels.Get(ctx, id)
|
||||
func (svc *LabelService) Get(ctx context.Context, gid uuid.UUID, id uuid.UUID) (repo.LabelOut, error) {
|
||||
return svc.repos.Labels.GetOneByGroup(ctx, gid, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if label.Edges.Group.ID != groupId {
|
||||
return nil, ErrNotOwner
|
||||
}
|
||||
|
||||
return mappers.ToLabelOut(label), nil
|
||||
}
|
||||
|
||||
func (svc *LabelService) GetAll(ctx context.Context, groupId uuid.UUID) ([]*types.LabelSummary, error) {
|
||||
labels, err := svc.repos.Labels.GetAll(ctx, groupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
labelsOut := make([]*types.LabelSummary, len(labels))
|
||||
for i, label := range labels {
|
||||
labelsOut[i] = mappers.ToLabelSummary(label)
|
||||
}
|
||||
|
||||
return labelsOut, nil
|
||||
func (svc *LabelService) GetAll(ctx context.Context, groupId uuid.UUID) ([]repo.LabelSummary, error) {
|
||||
return svc.repos.Labels.GetAll(ctx, groupId)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue