This commit is contained in:
2025-12-11 13:50:38 +01:00
parent e4c1be628d
commit c7e5de40d6
212 changed files with 2965 additions and 763 deletions

View File

@@ -1,55 +1,26 @@
/**
* Domain Entity: AvatarGenerationRequest
*
*
* Represents a request to generate a racing avatar from a face photo.
*/
export type RacingSuitColor =
| 'red'
| 'blue'
| 'green'
| 'yellow'
| 'orange'
| 'purple'
| 'black'
| 'white'
| 'pink'
| 'cyan';
export type AvatarStyle =
| 'realistic'
| 'cartoon'
| 'pixel-art';
export type AvatarGenerationStatus =
| 'pending'
| 'validating'
| 'generating'
| 'completed'
| 'failed';
export interface AvatarGenerationRequestProps {
id: string;
userId: string;
facePhotoUrl: string;
suitColor: RacingSuitColor;
style: AvatarStyle;
status: AvatarGenerationStatus;
generatedAvatarUrls: string[];
selectedAvatarIndex?: number;
errorMessage?: string;
createdAt: Date;
updatedAt: Date;
}
export class AvatarGenerationRequest {
import type { IEntity } from '@gridpilot/shared/domain';
import type {
AvatarGenerationRequestProps,
AvatarGenerationStatus,
AvatarStyle,
RacingSuitColor,
} from '../types/AvatarGenerationRequest';
import { MediaUrl } from '../value-objects/MediaUrl';
export class AvatarGenerationRequest implements IEntity<string> {
readonly id: string;
readonly userId: string;
readonly facePhotoUrl: string;
readonly facePhotoUrl: MediaUrl;
readonly suitColor: RacingSuitColor;
readonly style: AvatarStyle;
private _status: AvatarGenerationStatus;
private _generatedAvatarUrls: string[];
private _generatedAvatarUrls: MediaUrl[];
private _selectedAvatarIndex?: number;
private _errorMessage?: string;
readonly createdAt: Date;
@@ -58,11 +29,11 @@ export class AvatarGenerationRequest {
private constructor(props: AvatarGenerationRequestProps) {
this.id = props.id;
this.userId = props.userId;
this.facePhotoUrl = props.facePhotoUrl;
this.facePhotoUrl = MediaUrl.create(props.facePhotoUrl);
this.suitColor = props.suitColor;
this.style = props.style;
this._status = props.status;
this._generatedAvatarUrls = [...props.generatedAvatarUrls];
this._generatedAvatarUrls = props.generatedAvatarUrls.map(url => MediaUrl.create(url));
this._selectedAvatarIndex = props.selectedAvatarIndex;
this._errorMessage = props.errorMessage;
this.createdAt = props.createdAt;
@@ -106,7 +77,7 @@ export class AvatarGenerationRequest {
}
get generatedAvatarUrls(): string[] {
return [...this._generatedAvatarUrls];
return this._generatedAvatarUrls.map(url => url.value);
}
get selectedAvatarIndex(): number | undefined {
@@ -115,7 +86,7 @@ export class AvatarGenerationRequest {
get selectedAvatarUrl(): string | undefined {
if (this._selectedAvatarIndex !== undefined && this._generatedAvatarUrls[this._selectedAvatarIndex]) {
return this._generatedAvatarUrls[this._selectedAvatarIndex];
return this._generatedAvatarUrls[this._selectedAvatarIndex].value;
}
return undefined;
}
@@ -149,7 +120,7 @@ export class AvatarGenerationRequest {
throw new Error('At least one avatar URL is required');
}
this._status = 'completed';
this._generatedAvatarUrls = [...avatarUrls];
this._generatedAvatarUrls = avatarUrls.map(url => MediaUrl.create(url));
this._updatedAt = new Date();
}
@@ -204,11 +175,11 @@ export class AvatarGenerationRequest {
return {
id: this.id,
userId: this.userId,
facePhotoUrl: this.facePhotoUrl,
facePhotoUrl: this.facePhotoUrl.value,
suitColor: this.suitColor,
style: this.style,
status: this._status,
generatedAvatarUrls: [...this._generatedAvatarUrls],
generatedAvatarUrls: this._generatedAvatarUrls.map(url => url.value),
selectedAvatarIndex: this._selectedAvatarIndex,
errorMessage: this._errorMessage,
createdAt: this.createdAt,