homebox/backend/internal/services/service_admin.go

49 lines
1.3 KiB
Go
Raw Normal View History

2022-08-30 02:30:36 +00:00
package services
import (
"context"
"github.com/google/uuid"
2022-08-30 18:05:11 +00:00
"github.com/hay-kot/content/backend/ent"
2022-08-30 02:40:54 +00:00
"github.com/hay-kot/content/backend/internal/repo"
"github.com/hay-kot/content/backend/internal/types"
2022-08-30 02:30:36 +00:00
)
type AdminService struct {
repos *repo.AllRepos
}
2022-08-30 18:05:11 +00:00
func (svc *AdminService) Create(ctx context.Context, usr types.UserCreate) (*ent.User, error) {
2022-08-30 02:30:36 +00:00
return svc.repos.Users.Create(ctx, usr)
}
2022-08-30 18:05:11 +00:00
func (svc *AdminService) GetAll(ctx context.Context) ([]*ent.User, error) {
2022-08-30 02:30:36 +00:00
return svc.repos.Users.GetAll(ctx)
}
2022-08-30 18:05:11 +00:00
func (svc *AdminService) GetByID(ctx context.Context, id uuid.UUID) (*ent.User, error) {
2022-08-30 02:30:36 +00:00
return svc.repos.Users.GetOneId(ctx, id)
}
2022-08-30 18:05:11 +00:00
func (svc *AdminService) GetByEmail(ctx context.Context, email string) (*ent.User, error) {
2022-08-30 02:30:36 +00:00
return svc.repos.Users.GetOneEmail(ctx, email)
}
2022-08-30 18:05:11 +00:00
func (svc *AdminService) UpdateProperties(ctx context.Context, ID uuid.UUID, data types.UserUpdate) (*ent.User, error) {
2022-08-30 02:30:36 +00:00
err := svc.repos.Users.Update(ctx, ID, data)
if err != nil {
2022-08-30 18:05:11 +00:00
return &ent.User{}, err
2022-08-30 02:30:36 +00:00
}
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)
}