refactor
This commit is contained in:
@@ -2,6 +2,12 @@ import { Injectable, Inject } from '@nestjs/common';
|
||||
import type { RequestAvatarGenerationInputDTO } from './dtos/RequestAvatarGenerationInputDTO';
|
||||
import type { UploadMediaInputDTO } from './dtos/UploadMediaInputDTO';
|
||||
import type { UpdateAvatarInputDTO } from './dtos/UpdateAvatarInputDTO';
|
||||
import type { RequestAvatarGenerationOutputDTO } from './dtos/RequestAvatarGenerationOutputDTO';
|
||||
import type { UploadMediaOutputDTO } from './dtos/UploadMediaOutputDTO';
|
||||
import type { GetMediaOutputDTO } from './dtos/GetMediaOutputDTO';
|
||||
import type { DeleteMediaOutputDTO } from './dtos/DeleteMediaOutputDTO';
|
||||
import type { GetAvatarOutputDTO } from './dtos/GetAvatarOutputDTO';
|
||||
import type { UpdateAvatarOutputDTO } from './dtos/UpdateAvatarOutputDTO';
|
||||
import type { RacingSuitColor } from '@core/media/domain/types/AvatarGenerationRequest';
|
||||
|
||||
type RequestAvatarGenerationInput = RequestAvatarGenerationInputDTO;
|
||||
@@ -32,89 +38,116 @@ import {
|
||||
DELETE_MEDIA_USE_CASE_TOKEN,
|
||||
GET_AVATAR_USE_CASE_TOKEN,
|
||||
UPDATE_AVATAR_USE_CASE_TOKEN,
|
||||
LOGGER_TOKEN
|
||||
LOGGER_TOKEN,
|
||||
} from './MediaProviders';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
@Injectable()
|
||||
export class MediaService {
|
||||
constructor(
|
||||
@Inject(REQUEST_AVATAR_GENERATION_USE_CASE_TOKEN) private readonly requestAvatarGenerationUseCase: RequestAvatarGenerationUseCase,
|
||||
@Inject(UPLOAD_MEDIA_USE_CASE_TOKEN) private readonly uploadMediaUseCase: UploadMediaUseCase,
|
||||
@Inject(GET_MEDIA_USE_CASE_TOKEN) private readonly getMediaUseCase: GetMediaUseCase,
|
||||
@Inject(DELETE_MEDIA_USE_CASE_TOKEN) private readonly deleteMediaUseCase: DeleteMediaUseCase,
|
||||
@Inject(GET_AVATAR_USE_CASE_TOKEN) private readonly getAvatarUseCase: GetAvatarUseCase,
|
||||
@Inject(UPDATE_AVATAR_USE_CASE_TOKEN) private readonly updateAvatarUseCase: UpdateAvatarUseCase,
|
||||
@Inject(LOGGER_TOKEN) private readonly logger: Logger,
|
||||
@Inject(REQUEST_AVATAR_GENERATION_USE_CASE_TOKEN)
|
||||
private readonly requestAvatarGenerationUseCase: RequestAvatarGenerationUseCase,
|
||||
@Inject(UPLOAD_MEDIA_USE_CASE_TOKEN)
|
||||
private readonly uploadMediaUseCase: UploadMediaUseCase,
|
||||
@Inject(GET_MEDIA_USE_CASE_TOKEN)
|
||||
private readonly getMediaUseCase: GetMediaUseCase,
|
||||
@Inject(DELETE_MEDIA_USE_CASE_TOKEN)
|
||||
private readonly deleteMediaUseCase: DeleteMediaUseCase,
|
||||
@Inject(GET_AVATAR_USE_CASE_TOKEN)
|
||||
private readonly getAvatarUseCase: GetAvatarUseCase,
|
||||
@Inject(UPDATE_AVATAR_USE_CASE_TOKEN)
|
||||
private readonly updateAvatarUseCase: UpdateAvatarUseCase,
|
||||
@Inject(LOGGER_TOKEN)
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async requestAvatarGeneration(input: RequestAvatarGenerationInput): Promise<RequestAvatarGenerationPresenter> {
|
||||
async requestAvatarGeneration(
|
||||
input: RequestAvatarGenerationInput,
|
||||
): Promise<RequestAvatarGenerationOutputDTO> {
|
||||
this.logger.debug('[MediaService] Requesting avatar generation.');
|
||||
|
||||
const presenter = new RequestAvatarGenerationPresenter();
|
||||
await this.requestAvatarGenerationUseCase.execute({
|
||||
presenter.reset();
|
||||
|
||||
const result = await this.requestAvatarGenerationUseCase.execute({
|
||||
userId: input.userId,
|
||||
facePhotoData: input.facePhotoData,
|
||||
suitColor: input.suitColor as RacingSuitColor,
|
||||
}, presenter);
|
||||
});
|
||||
|
||||
return presenter;
|
||||
presenter.present(result);
|
||||
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async uploadMedia(input: UploadMediaInput & { file: Express.Multer.File }): Promise<UploadMediaPresenter> {
|
||||
async uploadMedia(
|
||||
input: UploadMediaInput & { file: Express.Multer.File } & { userId?: string; metadata?: Record<string, any> },
|
||||
): Promise<UploadMediaOutputDTO> {
|
||||
this.logger.debug('[MediaService] Uploading media.');
|
||||
|
||||
const presenter = new UploadMediaPresenter();
|
||||
presenter.reset();
|
||||
|
||||
await this.uploadMediaUseCase.execute({
|
||||
const result = await this.uploadMediaUseCase.execute({
|
||||
file: input.file,
|
||||
uploadedBy: input.userId, // Assuming userId is the uploader
|
||||
uploadedBy: input.userId ?? '',
|
||||
metadata: input.metadata,
|
||||
}, presenter);
|
||||
});
|
||||
|
||||
return presenter;
|
||||
presenter.present(result);
|
||||
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async getMedia(mediaId: string): Promise<GetMediaPresenter> {
|
||||
async getMedia(mediaId: string): Promise<GetMediaOutputDTO | null> {
|
||||
this.logger.debug(`[MediaService] Getting media: ${mediaId}`);
|
||||
|
||||
const presenter = new GetMediaPresenter();
|
||||
presenter.reset();
|
||||
|
||||
await this.getMediaUseCase.execute({ mediaId }, presenter);
|
||||
const result = await this.getMediaUseCase.execute({ mediaId });
|
||||
presenter.present(result);
|
||||
|
||||
return presenter;
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async deleteMedia(mediaId: string): Promise<DeleteMediaPresenter> {
|
||||
async deleteMedia(mediaId: string): Promise<DeleteMediaOutputDTO> {
|
||||
this.logger.debug(`[MediaService] Deleting media: ${mediaId}`);
|
||||
|
||||
const presenter = new DeleteMediaPresenter();
|
||||
presenter.reset();
|
||||
|
||||
await this.deleteMediaUseCase.execute({ mediaId }, presenter);
|
||||
const result = await this.deleteMediaUseCase.execute({ mediaId });
|
||||
presenter.present(result);
|
||||
|
||||
return presenter;
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async getAvatar(driverId: string): Promise<GetAvatarPresenter> {
|
||||
async getAvatar(driverId: string): Promise<GetAvatarOutputDTO | null> {
|
||||
this.logger.debug(`[MediaService] Getting avatar for driver: ${driverId}`);
|
||||
|
||||
const presenter = new GetAvatarPresenter();
|
||||
presenter.reset();
|
||||
|
||||
await this.getAvatarUseCase.execute({ driverId }, presenter);
|
||||
const result = await this.getAvatarUseCase.execute({ driverId });
|
||||
presenter.present(result);
|
||||
|
||||
return presenter;
|
||||
return presenter.responseModel;
|
||||
}
|
||||
|
||||
async updateAvatar(driverId: string, input: UpdateAvatarInput): Promise<UpdateAvatarPresenter> {
|
||||
async updateAvatar(driverId: string, input: UpdateAvatarInput): Promise<UpdateAvatarOutputDTO> {
|
||||
this.logger.debug(`[MediaService] Updating avatar for driver: ${driverId}`);
|
||||
|
||||
|
||||
const presenter = new UpdateAvatarPresenter();
|
||||
|
||||
await this.updateAvatarUseCase.execute({
|
||||
presenter.reset();
|
||||
|
||||
const result = await this.updateAvatarUseCase.execute({
|
||||
driverId,
|
||||
mediaUrl: input.mediaUrl,
|
||||
}, presenter);
|
||||
|
||||
return presenter;
|
||||
});
|
||||
|
||||
presenter.present(result);
|
||||
|
||||
return presenter.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user