package production import ( "context" "errors" "gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/internal/model/dto" "gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/internal/service" "gitea.privcloud.tech/vlad_marlo/mtusi2026lab3/internal/store" ) // UsersCreate validates registration and atomically reserves the unique username. func (s *Service) UsersCreate(ctx context.Context, request dto.UsersCreateRequestDTO) (dto.UserDTO, error) { user, err := PrepareUser(request) if err != nil { return dto.UserDTO{}, err } created, err := s.repo.CreateUser(ctx, user) return created, normalizeStoreError(err) } // UsersGetMe loads the current user's profile; malformed and missing identities are unauthorized. func (s *Service) UsersGetMe(ctx context.Context, rawID string) (dto.UserDTO, error) { id, err := parseIdentity(rawID) if err != nil { return dto.UserDTO{}, err } if s.cache != nil { if cached, ok := s.cache.GetProfile(ctx, id); ok { return cached, nil } } user, err := s.repo.User(ctx, id) if errors.Is(err, store.ErrNotFound) { return dto.UserDTO{}, service.ErrUnauthorized } if err == nil && s.cache != nil { s.cache.PutProfile(ctx, user) } return user, normalizeStoreError(err) } // UsersCheckIdentity validates the current identity without loading its profile. func (s *Service) UsersCheckIdentity(ctx context.Context, rawID string) error { _, err := s.requireUserID(ctx, rawID) return err }