38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lincodex/backend/internal/adapter/primary/http/api"
|
|
"lincodex/backend/internal/domain"
|
|
)
|
|
|
|
func (handler *Handler) GetCurrentAccount(ctx context.Context) (api.GetCurrentAccountRes, error) {
|
|
if handler.identity == nil || handler.identity.sessions == nil {
|
|
return handler.UnimplementedHandler.GetCurrentAccount(ctx)
|
|
}
|
|
return handler.identity.GetCurrentAccount(ctx)
|
|
}
|
|
|
|
func (handler *IdentityHandler) GetCurrentAccount(ctx context.Context) (api.GetCurrentAccountRes, error) {
|
|
session, ok := sessionFromContext(ctx)
|
|
if !ok || !session.EmailVerified {
|
|
return unauthenticatedProblemResponse(ctx), nil
|
|
}
|
|
return &api.AccountHeaders{
|
|
CacheControl: api.CacheControlNoStoreNoStore,
|
|
Response: accountFromUser(session.User),
|
|
}, nil
|
|
}
|
|
|
|
func accountFromUser(user domain.User) api.Account {
|
|
return api.Account{
|
|
ID: user.ID,
|
|
Email: api.EmailAddress(user.Email.Address()),
|
|
EmailVerified: user.EmailVerified(),
|
|
Scenario: api.AccountScenario(user.Scenario),
|
|
OnboardingStep: api.OnboardingStep(user.OnboardingStep),
|
|
CreatedAt: api.Timestamp(user.CreatedAt),
|
|
}
|
|
}
|