module cleanup
This commit is contained in:
77
core/media/application/use-cases/GetAvatarUseCase.ts
Normal file
77
core/media/application/use-cases/GetAvatarUseCase.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Use Case: GetAvatarUseCase
|
||||
*
|
||||
* Handles the business logic for retrieving a driver's avatar.
|
||||
*/
|
||||
|
||||
import type { IAvatarRepository } from '../../domain/repositories/IAvatarRepository';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type { IGetAvatarPresenter } from '../presenters/IGetAvatarPresenter';
|
||||
|
||||
export interface GetAvatarInput {
|
||||
driverId: string;
|
||||
}
|
||||
|
||||
export interface GetAvatarResult {
|
||||
success: boolean;
|
||||
avatar?: {
|
||||
id: string;
|
||||
driverId: string;
|
||||
mediaUrl: string;
|
||||
selectedAt: Date;
|
||||
};
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
export interface IGetAvatarPresenter {
|
||||
present(result: GetAvatarResult): void;
|
||||
}
|
||||
|
||||
export class GetAvatarUseCase {
|
||||
constructor(
|
||||
private readonly avatarRepo: IAvatarRepository,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
input: GetAvatarInput,
|
||||
presenter: IGetAvatarPresenter,
|
||||
): Promise<void> {
|
||||
try {
|
||||
this.logger.info('[GetAvatarUseCase] Getting avatar', {
|
||||
driverId: input.driverId,
|
||||
});
|
||||
|
||||
const avatar = await this.avatarRepo.findActiveByDriverId(input.driverId);
|
||||
|
||||
if (!avatar) {
|
||||
presenter.present({
|
||||
success: false,
|
||||
errorMessage: 'Avatar not found',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
presenter.present({
|
||||
success: true,
|
||||
avatar: {
|
||||
id: avatar.id,
|
||||
driverId: avatar.driverId,
|
||||
mediaUrl: avatar.mediaUrl.value,
|
||||
selectedAt: avatar.selectedAt,
|
||||
},
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
this.logger.error('[GetAvatarUseCase] Error getting avatar', {
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
driverId: input.driverId,
|
||||
});
|
||||
|
||||
presenter.present({
|
||||
success: false,
|
||||
errorMessage: 'Internal error occurred while retrieving avatar',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user