mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-17 06:08:42 +00:00
31b34241e0
* change /content/ -> /homebox/ * add cache to code generators * update env variables to set data storage * update env variables * set env variables in prod container * implement attachment post route (WIP) * get attachment endpoint * attachment download * implement string utilities lib * implement generic drop zone * use explicit truncate * remove clean dir * drop strings composable for lib * update item types and add attachments * add attachment API * implement service context * consolidate API code * implement editing attachments * implement upload limit configuration * improve error handling * add docs for max upload size * fix test cases
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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) 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) Delete(ctx context.Context, groupId uuid.UUID, id uuid.UUID) error {
|
|
label, err := svc.repos.Labels.Get(ctx, 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)
|
|
|
|
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
|
|
}
|