wip
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import type {
|
||||
IAvatarGenerationRepository
|
||||
} from '@gridpilot/media';
|
||||
import {
|
||||
AvatarGenerationRequest,
|
||||
type AvatarGenerationRequestProps
|
||||
} from '@gridpilot/media';
|
||||
|
||||
/**
|
||||
* In-memory implementation of IAvatarGenerationRepository.
|
||||
*
|
||||
* For demo/development purposes. In production, this would use a database.
|
||||
*/
|
||||
export class InMemoryAvatarGenerationRepository implements IAvatarGenerationRepository {
|
||||
private readonly requests = new Map<string, AvatarGenerationRequestProps>();
|
||||
|
||||
async save(request: AvatarGenerationRequest): Promise<void> {
|
||||
this.requests.set(request.id, request.toProps());
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<AvatarGenerationRequest | null> {
|
||||
const props = this.requests.get(id);
|
||||
if (!props) {
|
||||
return null;
|
||||
}
|
||||
return AvatarGenerationRequest.reconstitute(props);
|
||||
}
|
||||
|
||||
async findByUserId(userId: string): Promise<AvatarGenerationRequest[]> {
|
||||
const results: AvatarGenerationRequest[] = [];
|
||||
for (const props of this.requests.values()) {
|
||||
if (props.userId === userId) {
|
||||
results.push(AvatarGenerationRequest.reconstitute(props));
|
||||
}
|
||||
}
|
||||
return results.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
||||
}
|
||||
|
||||
async findLatestByUserId(userId: string): Promise<AvatarGenerationRequest | null> {
|
||||
const userRequests = await this.findByUserId(userId);
|
||||
return userRequests.length > 0 ? userRequests[0] : null;
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
this.requests.delete(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user