wip
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* Defines the contract for AI-powered avatar generation.
|
||||
*/
|
||||
|
||||
import type { RacingSuitColor, AvatarStyle } from '../../domain/entities/AvatarGenerationRequest';
|
||||
import type { RacingSuitColor, AvatarStyle } from '../../domain/types/AvatarGenerationRequest';
|
||||
|
||||
export interface AvatarGenerationOptions {
|
||||
facePhotoUrl: string;
|
||||
|
||||
@@ -42,7 +42,7 @@ export class RequestAvatarGenerationUseCase
|
||||
userId: command.userId,
|
||||
facePhotoUrl: `data:image/jpeg;base64,${command.facePhotoData}`,
|
||||
suitColor: command.suitColor,
|
||||
style: command.style,
|
||||
...(command.style ? { style: command.style } : {}),
|
||||
});
|
||||
|
||||
// Mark as validating
|
||||
|
||||
@@ -53,10 +53,13 @@ export class SelectAvatarUseCase
|
||||
request.selectAvatar(command.avatarIndex);
|
||||
await this.avatarRepository.save(request);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
selectedAvatarUrl: request.selectedAvatarUrl,
|
||||
};
|
||||
const selectedAvatarUrl = request.selectedAvatarUrl;
|
||||
const result: SelectAvatarResult =
|
||||
selectedAvatarUrl !== undefined
|
||||
? { success: true, selectedAvatarUrl }
|
||||
: { success: true };
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -34,8 +34,12 @@ export class AvatarGenerationRequest implements IEntity<string> {
|
||||
this.style = props.style;
|
||||
this._status = props.status;
|
||||
this._generatedAvatarUrls = props.generatedAvatarUrls.map(url => MediaUrl.create(url));
|
||||
this._selectedAvatarIndex = props.selectedAvatarIndex;
|
||||
this._errorMessage = props.errorMessage;
|
||||
if (props.selectedAvatarIndex !== undefined) {
|
||||
this._selectedAvatarIndex = props.selectedAvatarIndex;
|
||||
}
|
||||
if (props.errorMessage !== undefined) {
|
||||
this._errorMessage = props.errorMessage;
|
||||
}
|
||||
this.createdAt = props.createdAt;
|
||||
this._updatedAt = props.updatedAt;
|
||||
}
|
||||
@@ -85,10 +89,15 @@ export class AvatarGenerationRequest implements IEntity<string> {
|
||||
}
|
||||
|
||||
get selectedAvatarUrl(): string | undefined {
|
||||
if (this._selectedAvatarIndex !== undefined && this._generatedAvatarUrls[this._selectedAvatarIndex]) {
|
||||
return this._generatedAvatarUrls[this._selectedAvatarIndex].value;
|
||||
const index = this._selectedAvatarIndex;
|
||||
if (index === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return undefined;
|
||||
const avatar = this._generatedAvatarUrls[index];
|
||||
if (!avatar) {
|
||||
return undefined;
|
||||
}
|
||||
return avatar.value;
|
||||
}
|
||||
|
||||
get errorMessage(): string | undefined {
|
||||
@@ -172,7 +181,7 @@ export class AvatarGenerationRequest implements IEntity<string> {
|
||||
}
|
||||
|
||||
toProps(): AvatarGenerationRequestProps {
|
||||
return {
|
||||
const base: AvatarGenerationRequestProps = {
|
||||
id: this.id,
|
||||
userId: this.userId,
|
||||
facePhotoUrl: this.facePhotoUrl.value,
|
||||
@@ -180,10 +189,18 @@ export class AvatarGenerationRequest implements IEntity<string> {
|
||||
style: this.style,
|
||||
status: this._status,
|
||||
generatedAvatarUrls: this._generatedAvatarUrls.map(url => url.value),
|
||||
selectedAvatarIndex: this._selectedAvatarIndex,
|
||||
errorMessage: this._errorMessage,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this._updatedAt,
|
||||
};
|
||||
|
||||
return {
|
||||
...base,
|
||||
...(this._selectedAvatarIndex !== undefined && {
|
||||
selectedAvatarIndex: this._selectedAvatarIndex,
|
||||
}),
|
||||
...(this._errorMessage !== undefined && {
|
||||
errorMessage: this._errorMessage,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* Defines the contract for avatar generation request persistence.
|
||||
*/
|
||||
|
||||
import type { AvatarGenerationRequest, AvatarGenerationRequestProps } from '../entities/AvatarGenerationRequest';
|
||||
import type { AvatarGenerationRequest } from '../entities/AvatarGenerationRequest';
|
||||
|
||||
export interface IAvatarGenerationRepository {
|
||||
/**
|
||||
|
||||
@@ -9,4 +9,5 @@ export * from './application/use-cases/SelectAvatarUseCase';
|
||||
|
||||
// Domain
|
||||
export * from './domain/entities/AvatarGenerationRequest';
|
||||
export * from './domain/repositories/IAvatarGenerationRepository';
|
||||
export * from './domain/repositories/IAvatarGenerationRepository';
|
||||
export type { AvatarGenerationRequestProps } from './domain/types/AvatarGenerationRequest';
|
||||
Reference in New Issue
Block a user