mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-21 14:26:31 +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
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/hay-kot/homebox/backend/ent"
|
|
"github.com/hay-kot/homebox/backend/internal/repo"
|
|
"github.com/hay-kot/homebox/backend/internal/types"
|
|
)
|
|
|
|
type AdminService struct {
|
|
repos *repo.AllRepos
|
|
}
|
|
|
|
func (svc *AdminService) Create(ctx context.Context, usr types.UserCreate) (*ent.User, error) {
|
|
return svc.repos.Users.Create(ctx, usr)
|
|
}
|
|
|
|
func (svc *AdminService) GetAll(ctx context.Context) ([]*ent.User, error) {
|
|
return svc.repos.Users.GetAll(ctx)
|
|
}
|
|
|
|
func (svc *AdminService) GetByID(ctx context.Context, id uuid.UUID) (*ent.User, error) {
|
|
return svc.repos.Users.GetOneId(ctx, id)
|
|
}
|
|
|
|
func (svc *AdminService) GetByEmail(ctx context.Context, email string) (*ent.User, error) {
|
|
return svc.repos.Users.GetOneEmail(ctx, email)
|
|
}
|
|
|
|
func (svc *AdminService) UpdateProperties(ctx context.Context, ID uuid.UUID, data types.UserUpdate) (*ent.User, error) {
|
|
err := svc.repos.Users.Update(ctx, ID, data)
|
|
|
|
if err != nil {
|
|
return &ent.User{}, err
|
|
}
|
|
|
|
return svc.repos.Users.GetOneId(ctx, ID)
|
|
}
|
|
|
|
func (svc *AdminService) Delete(ctx context.Context, id uuid.UUID) error {
|
|
return svc.repos.Users.Delete(ctx, id)
|
|
}
|
|
|
|
func (svc *AdminService) DeleteAll(ctx context.Context) error {
|
|
return svc.repos.Users.DeleteAll(ctx)
|
|
}
|