forked from mirrors/homebox
cleanup user implementation
This commit is contained in:
parent
9501eb398a
commit
a9f53a4671
6 changed files with 39 additions and 35 deletions
|
@ -23,6 +23,20 @@ type UserService struct {
|
|||
repos *repo.AllRepos
|
||||
}
|
||||
|
||||
func (UserService) toOutUser(user *ent.User, err error) (types.UserOut, error) {
|
||||
if err != nil {
|
||||
return types.UserOut{}, err
|
||||
}
|
||||
return types.UserOut{
|
||||
ID: user.ID,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
IsSuperuser: user.IsSuperuser,
|
||||
GroupName: user.Edges.Group.Name,
|
||||
GroupID: user.Edges.Group.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (svc *UserService) RegisterUser(ctx context.Context, data types.UserRegistration) (*ent.User, error) {
|
||||
group, err := svc.repos.Groups.Create(ctx, data.GroupName)
|
||||
if err != nil {
|
||||
|
@ -48,9 +62,9 @@ func (svc *UserService) RegisterUser(ctx context.Context, data types.UserRegistr
|
|||
}
|
||||
|
||||
// GetSelf returns the user that is currently logged in based of the token provided within
|
||||
func (svc *UserService) GetSelf(ctx context.Context, requestToken string) (*ent.User, error) {
|
||||
func (svc *UserService) GetSelf(ctx context.Context, requestToken string) (types.UserOut, error) {
|
||||
hash := hasher.HashToken(requestToken)
|
||||
return svc.repos.AuthTokens.GetUserFromToken(ctx, hash)
|
||||
return svc.toOutUser(svc.repos.AuthTokens.GetUserFromToken(ctx, hash))
|
||||
}
|
||||
|
||||
func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data types.UserUpdate) (*ent.User, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue