module cleanup
This commit is contained in:
73
core/media/domain/entities/Avatar.ts
Normal file
73
core/media/domain/entities/Avatar.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Domain Entity: Avatar
|
||||
*
|
||||
* Represents a user's selected avatar.
|
||||
*/
|
||||
|
||||
import type { IEntity } from '@core/shared/domain';
|
||||
import { MediaUrl } from '../value-objects/MediaUrl';
|
||||
|
||||
export interface AvatarProps {
|
||||
id: string;
|
||||
driverId: string;
|
||||
mediaUrl: string;
|
||||
selectedAt: Date;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
export class Avatar implements IEntity<string> {
|
||||
readonly id: string;
|
||||
readonly driverId: string;
|
||||
readonly mediaUrl: MediaUrl;
|
||||
readonly selectedAt: Date;
|
||||
private _isActive: boolean;
|
||||
|
||||
private constructor(props: AvatarProps) {
|
||||
this.id = props.id;
|
||||
this.driverId = props.driverId;
|
||||
this.mediaUrl = MediaUrl.create(props.mediaUrl);
|
||||
this.selectedAt = props.selectedAt;
|
||||
this._isActive = props.isActive;
|
||||
}
|
||||
|
||||
static create(props: {
|
||||
id: string;
|
||||
driverId: string;
|
||||
mediaUrl: string;
|
||||
}): Avatar {
|
||||
if (!props.driverId) {
|
||||
throw new Error('Driver ID is required');
|
||||
}
|
||||
if (!props.mediaUrl) {
|
||||
throw new Error('Media URL is required');
|
||||
}
|
||||
|
||||
return new Avatar({
|
||||
...props,
|
||||
selectedAt: new Date(),
|
||||
isActive: true,
|
||||
});
|
||||
}
|
||||
|
||||
static reconstitute(props: AvatarProps): Avatar {
|
||||
return new Avatar(props);
|
||||
}
|
||||
|
||||
get isActive(): boolean {
|
||||
return this._isActive;
|
||||
}
|
||||
|
||||
deactivate(): void {
|
||||
this._isActive = false;
|
||||
}
|
||||
|
||||
toProps(): AvatarProps {
|
||||
return {
|
||||
id: this.id,
|
||||
driverId: this.driverId,
|
||||
mediaUrl: this.mediaUrl.value,
|
||||
selectedAt: this.selectedAt,
|
||||
isActive: this._isActive,
|
||||
};
|
||||
}
|
||||
}
|
||||
95
core/media/domain/entities/Media.ts
Normal file
95
core/media/domain/entities/Media.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Domain Entity: Media
|
||||
*
|
||||
* Represents a media file (image, video, etc.) stored in the system.
|
||||
*/
|
||||
|
||||
import type { IEntity } from '@core/shared/domain';
|
||||
import { MediaUrl } from '../value-objects/MediaUrl';
|
||||
|
||||
export type MediaType = 'image' | 'video' | 'document';
|
||||
|
||||
export interface MediaProps {
|
||||
id: string;
|
||||
filename: string;
|
||||
originalName: string;
|
||||
mimeType: string;
|
||||
size: number;
|
||||
url: string;
|
||||
type: MediaType;
|
||||
uploadedBy: string;
|
||||
uploadedAt: Date;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
export class Media implements IEntity<string> {
|
||||
readonly id: string;
|
||||
readonly filename: string;
|
||||
readonly originalName: string;
|
||||
readonly mimeType: string;
|
||||
readonly size: number;
|
||||
readonly url: MediaUrl;
|
||||
readonly type: MediaType;
|
||||
readonly uploadedBy: string;
|
||||
readonly uploadedAt: Date;
|
||||
readonly metadata?: Record<string, any>;
|
||||
|
||||
private constructor(props: MediaProps) {
|
||||
this.id = props.id;
|
||||
this.filename = props.filename;
|
||||
this.originalName = props.originalName;
|
||||
this.mimeType = props.mimeType;
|
||||
this.size = props.size;
|
||||
this.url = MediaUrl.create(props.url);
|
||||
this.type = props.type;
|
||||
this.uploadedBy = props.uploadedBy;
|
||||
this.uploadedAt = props.uploadedAt;
|
||||
this.metadata = props.metadata;
|
||||
}
|
||||
|
||||
static create(props: {
|
||||
id: string;
|
||||
filename: string;
|
||||
originalName: string;
|
||||
mimeType: string;
|
||||
size: number;
|
||||
url: string;
|
||||
type: MediaType;
|
||||
uploadedBy: string;
|
||||
metadata?: Record<string, any>;
|
||||
}): Media {
|
||||
if (!props.filename) {
|
||||
throw new Error('Filename is required');
|
||||
}
|
||||
if (!props.url) {
|
||||
throw new Error('URL is required');
|
||||
}
|
||||
if (!props.uploadedBy) {
|
||||
throw new Error('Uploaded by is required');
|
||||
}
|
||||
|
||||
return new Media({
|
||||
...props,
|
||||
uploadedAt: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
static reconstitute(props: MediaProps): Media {
|
||||
return new Media(props);
|
||||
}
|
||||
|
||||
toProps(): MediaProps {
|
||||
return {
|
||||
id: this.id,
|
||||
filename: this.filename,
|
||||
originalName: this.originalName,
|
||||
mimeType: this.mimeType,
|
||||
size: this.size,
|
||||
url: this.url.value,
|
||||
type: this.type,
|
||||
uploadedBy: this.uploadedBy,
|
||||
uploadedAt: this.uploadedAt,
|
||||
metadata: this.metadata,
|
||||
};
|
||||
}
|
||||
}
|
||||
34
core/media/domain/repositories/IAvatarRepository.ts
Normal file
34
core/media/domain/repositories/IAvatarRepository.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Repository Interface: IAvatarRepository
|
||||
*
|
||||
* Defines the contract for avatar persistence.
|
||||
*/
|
||||
|
||||
import type { Avatar } from '../entities/Avatar';
|
||||
|
||||
export interface IAvatarRepository {
|
||||
/**
|
||||
* Save an avatar
|
||||
*/
|
||||
save(avatar: Avatar): Promise<void>;
|
||||
|
||||
/**
|
||||
* Find avatar by ID
|
||||
*/
|
||||
findById(id: string): Promise<Avatar | null>;
|
||||
|
||||
/**
|
||||
* Find active avatar for a driver
|
||||
*/
|
||||
findActiveByDriverId(driverId: string): Promise<Avatar | null>;
|
||||
|
||||
/**
|
||||
* Find all avatars for a driver
|
||||
*/
|
||||
findByDriverId(driverId: string): Promise<Avatar[]>;
|
||||
|
||||
/**
|
||||
* Delete an avatar
|
||||
*/
|
||||
delete(id: string): Promise<void>;
|
||||
}
|
||||
29
core/media/domain/repositories/IMediaRepository.ts
Normal file
29
core/media/domain/repositories/IMediaRepository.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Repository Interface: IMediaRepository
|
||||
*
|
||||
* Defines the contract for media file persistence.
|
||||
*/
|
||||
|
||||
import type { Media } from '../entities/Media';
|
||||
|
||||
export interface IMediaRepository {
|
||||
/**
|
||||
* Save a media file
|
||||
*/
|
||||
save(media: Media): Promise<void>;
|
||||
|
||||
/**
|
||||
* Find a media file by ID
|
||||
*/
|
||||
findById(id: string): Promise<Media | null>;
|
||||
|
||||
/**
|
||||
* Find media files by uploader
|
||||
*/
|
||||
findByUploadedBy(uploadedBy: string): Promise<Media[]>;
|
||||
|
||||
/**
|
||||
* Delete a media file
|
||||
*/
|
||||
delete(id: string): Promise<void>;
|
||||
}
|
||||
Reference in New Issue
Block a user