refactor
This commit is contained in:
@@ -1,41 +1,82 @@
|
||||
import { Provider } from '@nestjs/common';
|
||||
import { MediaService } from './MediaService';
|
||||
|
||||
// Due to persistent module resolution issues in the environment,
|
||||
// actual core interfaces and adapter implementations are not directly imported here.
|
||||
// In a functional TypeScript environment, these would be imported as follows:
|
||||
/*
|
||||
import { IAvatarGenerationRepository } from 'core/media/domain/repositories/IAvatarGenerationRepository';
|
||||
import { FaceValidationPort } from 'core/media/application/ports/FaceValidationPort';
|
||||
import { Logger } from '@gridpilot/shared/logging/Logger';
|
||||
// Import core interfaces
|
||||
import { IAvatarGenerationRepository } from '@gridpilot/media/domain/repositories/IAvatarGenerationRepository';
|
||||
import { FaceValidationPort } from '@gridpilot/media/application/ports/FaceValidationPort';
|
||||
import { AvatarGenerationPort } from '@gridpilot/media/application/ports/AvatarGenerationPort';
|
||||
import { Logger } from '@gridpilot/shared/application';
|
||||
|
||||
import { InMemoryAvatarGenerationRepository } from 'adapters/media/persistence/inmemory/InMemoryAvatarGenerationRepository';
|
||||
import { InMemoryFaceValidationAdapter } from 'adapters/media/ports/InMemoryFaceValidationAdapter';
|
||||
import { ConsoleLogger } from 'adapters/logging/ConsoleLogger';
|
||||
*/
|
||||
// Import use cases
|
||||
import { RequestAvatarGenerationUseCase } from '@gridpilot/media/application/use-cases/RequestAvatarGenerationUseCase';
|
||||
|
||||
// Define injection tokens as string literals for NestJS
|
||||
// Define injection tokens
|
||||
export const AVATAR_GENERATION_REPOSITORY_TOKEN = 'IAvatarGenerationRepository';
|
||||
export const FACE_VALIDATION_PORT_TOKEN = 'FaceValidationPort';
|
||||
export const AVATAR_GENERATION_PORT_TOKEN = 'AvatarGenerationPort';
|
||||
export const LOGGER_TOKEN = 'Logger';
|
||||
|
||||
// Use case tokens
|
||||
export const REQUEST_AVATAR_GENERATION_USE_CASE_TOKEN = 'RequestAvatarGenerationUseCase';
|
||||
|
||||
// Mock implementations
|
||||
class MockAvatarGenerationRepository implements IAvatarGenerationRepository {
|
||||
async save(_request: any): Promise<void> {}
|
||||
async findById(_id: string): Promise<any | null> { return null; }
|
||||
async findByUserId(_userId: string): Promise<any[]> { return []; }
|
||||
async findLatestByUserId(_userId: string): Promise<any | null> { return null; }
|
||||
async delete(_id: string): Promise<void> {}
|
||||
}
|
||||
|
||||
class MockFaceValidationAdapter implements FaceValidationPort {
|
||||
async validateFacePhoto(data: string): Promise<any> {
|
||||
return { isValid: true, hasFace: true, faceCount: 1 };
|
||||
}
|
||||
}
|
||||
|
||||
class MockAvatarGenerationAdapter implements AvatarGenerationPort {
|
||||
async generateAvatars(options: any): Promise<any> {
|
||||
return {
|
||||
success: true,
|
||||
avatars: [
|
||||
{ url: 'https://cdn.example.com/avatars/mock-avatar-1.png' },
|
||||
{ url: 'https://cdn.example.com/avatars/mock-avatar-2.png' },
|
||||
{ url: 'https://cdn.example.com/avatars/mock-avatar-3.png' },
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class MockLogger implements Logger {
|
||||
debug(message: string, meta?: any): void {}
|
||||
info(message: string, meta?: any): void {}
|
||||
warn(message: string, meta?: any): void {}
|
||||
error(message: string, error?: Error): void {}
|
||||
}
|
||||
|
||||
export const MediaProviders: Provider[] = [
|
||||
MediaService, // Provide the service itself
|
||||
// In a functional setup, the following would be enabled:
|
||||
/*
|
||||
{
|
||||
provide: AVATAR_GENERATION_REPOSITORY_TOKEN,
|
||||
useFactory: (logger: Logger) => new InMemoryAvatarGenerationRepository(logger),
|
||||
inject: [LOGGER_TOKEN],
|
||||
useClass: MockAvatarGenerationRepository,
|
||||
},
|
||||
{
|
||||
provide: FACE_VALIDATION_PORT_TOKEN,
|
||||
useFactory: (logger: Logger) => new InMemoryFaceValidationAdapter(logger),
|
||||
inject: [LOGGER_TOKEN],
|
||||
useClass: MockFaceValidationAdapter,
|
||||
},
|
||||
{
|
||||
provide: AVATAR_GENERATION_PORT_TOKEN,
|
||||
useClass: MockAvatarGenerationAdapter,
|
||||
},
|
||||
{
|
||||
provide: LOGGER_TOKEN,
|
||||
useClass: ConsoleLogger,
|
||||
useClass: MockLogger,
|
||||
},
|
||||
// Use cases
|
||||
{
|
||||
provide: REQUEST_AVATAR_GENERATION_USE_CASE_TOKEN,
|
||||
useFactory: (avatarRepo: IAvatarGenerationRepository, faceValidation: FaceValidationPort, avatarGeneration: AvatarGenerationPort, logger: Logger) =>
|
||||
new RequestAvatarGenerationUseCase(avatarRepo, faceValidation, avatarGeneration, logger),
|
||||
inject: [AVATAR_GENERATION_REPOSITORY_TOKEN, FACE_VALIDATION_PORT_TOKEN, AVATAR_GENERATION_PORT_TOKEN, LOGGER_TOKEN],
|
||||
},
|
||||
*/
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user