services refactor
This commit is contained in:
@@ -1,5 +1,60 @@
|
||||
import { api as api } from '../../api';
|
||||
import type { MediaApiClient } from '../../api/media/MediaApiClient';
|
||||
import type { AvatarPresenter } from '../../presenters/AvatarPresenter';
|
||||
import type {
|
||||
RequestAvatarGenerationInputDto,
|
||||
UpdateAvatarInputDto
|
||||
} from '../../dtos';
|
||||
import type {
|
||||
RequestAvatarGenerationViewModel,
|
||||
AvatarViewModel,
|
||||
UpdateAvatarViewModel
|
||||
} from '../../view-models';
|
||||
|
||||
export async function requestAvatarGeneration(input: any): Promise<any> {
|
||||
return await api.media.requestAvatarGeneration(input);
|
||||
/**
|
||||
* Avatar Service
|
||||
*
|
||||
* Orchestrates avatar operations by coordinating API calls and presentation logic.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class AvatarService {
|
||||
constructor(
|
||||
private readonly apiClient: MediaApiClient,
|
||||
private readonly presenter: AvatarPresenter
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Request avatar generation with presentation transformation
|
||||
*/
|
||||
async requestAvatarGeneration(input: RequestAvatarGenerationInputDto): Promise<RequestAvatarGenerationViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.requestAvatarGeneration(input);
|
||||
return this.presenter.presentRequestGeneration(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get avatar for driver with presentation transformation
|
||||
*/
|
||||
async getAvatar(driverId: string): Promise<AvatarViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.getAvatar(driverId);
|
||||
return this.presenter.presentAvatar(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update avatar for driver with presentation transformation
|
||||
*/
|
||||
async updateAvatar(input: UpdateAvatarInputDto): Promise<UpdateAvatarViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.updateAvatar(input);
|
||||
return this.presenter.presentUpdate(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user