view models
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import type { MediaApiClient } from '../../api/media/MediaApiClient';
|
||||
import type { AvatarPresenter } from '../../presenters/AvatarPresenter';
|
||||
import type {
|
||||
RequestAvatarGenerationInputDto,
|
||||
UpdateAvatarInputDto
|
||||
} from '../../dtos';
|
||||
import type {
|
||||
import type { RequestAvatarGenerationInputDTO } from '../../types/generated';
|
||||
|
||||
// TODO: Move these types to apps/website/lib/types/generated when available
|
||||
type UpdateAvatarInputDto = { driverId: string; avatarUrl: string };
|
||||
import {
|
||||
RequestAvatarGenerationViewModel,
|
||||
AvatarViewModel,
|
||||
UpdateAvatarViewModel
|
||||
@@ -13,48 +12,35 @@ import type {
|
||||
/**
|
||||
* Avatar Service
|
||||
*
|
||||
* Orchestrates avatar operations by coordinating API calls and presentation logic.
|
||||
* Orchestrates avatar operations by coordinating API calls and view model creation.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class AvatarService {
|
||||
constructor(
|
||||
private readonly apiClient: MediaApiClient,
|
||||
private readonly presenter: AvatarPresenter
|
||||
private readonly apiClient: MediaApiClient
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Request avatar generation with presentation transformation
|
||||
* Request avatar generation with view model transformation
|
||||
*/
|
||||
async requestAvatarGeneration(input: RequestAvatarGenerationInputDto): Promise<RequestAvatarGenerationViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.requestAvatarGeneration(input);
|
||||
return this.presenter.presentRequestGeneration(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
async requestAvatarGeneration(input: RequestAvatarGenerationInputDTO): Promise<RequestAvatarGenerationViewModel> {
|
||||
const dto = await this.apiClient.requestAvatarGeneration(input);
|
||||
return new RequestAvatarGenerationViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get avatar for driver with presentation transformation
|
||||
* Get avatar for driver with view model transformation
|
||||
*/
|
||||
async getAvatar(driverId: string): Promise<AvatarViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.getAvatar(driverId);
|
||||
return this.presenter.presentAvatar(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
const dto = await this.apiClient.getAvatar(driverId);
|
||||
return new AvatarViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update avatar for driver with presentation transformation
|
||||
* Update avatar for driver with view model transformation
|
||||
*/
|
||||
async updateAvatar(input: UpdateAvatarInputDto): Promise<UpdateAvatarViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.updateAvatar(input);
|
||||
return this.presenter.presentUpdate(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
const dto = await this.apiClient.updateAvatar(input);
|
||||
return new UpdateAvatarViewModel(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user