website refactor
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { injectable, unmanaged } from 'inversify';
|
||||
import { AuthApiClient } from '@/lib/api/auth/AuthApiClient';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
@@ -18,10 +19,11 @@ import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
* Orchestrates authentication operations.
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
*/
|
||||
@injectable()
|
||||
export class AuthService implements Service {
|
||||
private apiClient: AuthApiClient;
|
||||
|
||||
constructor(apiClient?: AuthApiClient) {
|
||||
constructor(@unmanaged() apiClient?: AuthApiClient) {
|
||||
if (apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
} else {
|
||||
@@ -36,30 +38,30 @@ export class AuthService implements Service {
|
||||
}
|
||||
}
|
||||
|
||||
async login(params: LoginParamsDTO): Promise<any> {
|
||||
async login(params: LoginParamsDTO): Promise<Result<SessionViewModel, DomainError>> {
|
||||
try {
|
||||
const dto = await this.apiClient.login(params);
|
||||
return new SessionViewModel(dto.user);
|
||||
return Result.ok(new SessionViewModel(dto.user));
|
||||
} catch (error: unknown) {
|
||||
throw error;
|
||||
return Result.err({ type: 'unauthorized', message: (error as Error).message || 'Login failed' });
|
||||
}
|
||||
}
|
||||
|
||||
async signup(params: SignupParamsDTO): Promise<any> {
|
||||
async signup(params: SignupParamsDTO): Promise<Result<SessionViewModel, DomainError>> {
|
||||
try {
|
||||
const dto = await this.apiClient.signup(params);
|
||||
return new SessionViewModel(dto.user);
|
||||
return Result.ok(new SessionViewModel(dto.user));
|
||||
} catch (error: unknown) {
|
||||
throw error;
|
||||
return Result.err({ type: 'validation', message: (error as Error).message || 'Signup failed' });
|
||||
}
|
||||
}
|
||||
|
||||
async logout(): Promise<any> {
|
||||
async logout(): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.apiClient.logout();
|
||||
return Result.ok(undefined);
|
||||
} catch (error: unknown) {
|
||||
throw error;
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Logout failed' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,12 +83,12 @@ export class AuthService implements Service {
|
||||
}
|
||||
}
|
||||
|
||||
async getSession(): Promise<any> {
|
||||
async getSession(): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const dto = await this.apiClient.getSession();
|
||||
return dto;
|
||||
return Result.ok(dto);
|
||||
} catch (error: unknown) {
|
||||
throw error;
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get session' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user