This commit is contained in:
2025-12-14 18:11:59 +01:00
parent acc15e8d8d
commit 217337862c
91 changed files with 5919 additions and 1999 deletions

View File

@@ -4,7 +4,7 @@
* Allows a user to select one of the generated avatars as their profile avatar.
*/
import type { AsyncUseCase } from '@gridpilot/shared/application';
import type { AsyncUseCase, ILogger } from '@gridpilot/shared/application';
import type { IAvatarGenerationRepository } from '../../domain/repositories/IAvatarGenerationRepository';
export interface SelectAvatarCommand {
@@ -23,12 +23,16 @@ export class SelectAvatarUseCase
implements AsyncUseCase<SelectAvatarCommand, SelectAvatarResult> {
constructor(
private readonly avatarRepository: IAvatarGenerationRepository,
private readonly logger: ILogger,
) {}
async execute(command: SelectAvatarCommand): Promise<SelectAvatarResult> {
this.logger.debug(`Executing SelectAvatarUseCase for userId: ${command.userId}, requestId: ${command.requestId}, avatarIndex: ${command.avatarIndex}`);
const request = await this.avatarRepository.findById(command.requestId);
if (!request) {
this.logger.info(`Avatar generation request not found for requestId: ${command.requestId}`);
return {
success: false,
errorMessage: 'Avatar generation request not found',
@@ -36,6 +40,7 @@ export class SelectAvatarUseCase
}
if (request.userId !== command.userId) {
this.logger.info(`Permission denied for userId: ${command.userId} to select avatar for requestId: ${command.requestId}`);
return {
success: false,
errorMessage: 'You do not have permission to select this avatar',
@@ -43,6 +48,7 @@ export class SelectAvatarUseCase
}
if (request.status !== 'completed') {
this.logger.info(`Avatar generation not completed for requestId: ${command.requestId}, current status: ${request.status}`);
return {
success: false,
errorMessage: 'Avatar generation is not yet complete',
@@ -59,8 +65,10 @@ export class SelectAvatarUseCase
? { success: true, selectedAvatarUrl }
: { success: true };
this.logger.info(`Avatar selected successfully for userId: ${command.userId}, requestId: ${command.requestId}, selectedAvatarUrl: ${selectedAvatarUrl}`);
return result;
} catch (error) {
this.logger.error(`Failed to select avatar for userId: ${command.userId}, requestId: ${command.requestId}: ${error instanceof Error ? error.message : 'Unknown error'}`, error);
return {
success: false,
errorMessage: error instanceof Error ? error.message : 'Failed to select avatar',