This commit is contained in:
2025-12-10 00:38:59 +01:00
parent a4a732ddc5
commit 0f7fe67d3c
25 changed files with 1914 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/**
* In-Memory Implementation: ILeagueWalletRepository
*
* Mock repository for testing and development
*/
import type { LeagueWallet } from '../../domain/entities/LeagueWallet';
import type { ILeagueWalletRepository } from '../../domain/repositories/ILeagueWalletRepository';
export class InMemoryLeagueWalletRepository implements ILeagueWalletRepository {
private wallets: Map<string, LeagueWallet> = new Map();
async findById(id: string): Promise<LeagueWallet | null> {
return this.wallets.get(id) ?? null;
}
async findByLeagueId(leagueId: string): Promise<LeagueWallet | null> {
for (const wallet of this.wallets.values()) {
if (wallet.leagueId === leagueId) {
return wallet;
}
}
return null;
}
async create(wallet: LeagueWallet): Promise<LeagueWallet> {
if (this.wallets.has(wallet.id)) {
throw new Error('LeagueWallet with this ID already exists');
}
this.wallets.set(wallet.id, wallet);
return wallet;
}
async update(wallet: LeagueWallet): Promise<LeagueWallet> {
if (!this.wallets.has(wallet.id)) {
throw new Error('LeagueWallet not found');
}
this.wallets.set(wallet.id, wallet);
return wallet;
}
async delete(id: string): Promise<void> {
this.wallets.delete(id);
}
async exists(id: string): Promise<boolean> {
return this.wallets.has(id);
}
// Test helper
clear(): void {
this.wallets.clear();
}
}

View File

@@ -0,0 +1,104 @@
/**
* In-Memory Implementation: ILiveryRepository
*
* Mock repository for testing and development
*/
import type { DriverLivery } from '../../domain/entities/DriverLivery';
import type { LiveryTemplate } from '../../domain/entities/LiveryTemplate';
import type { ILiveryRepository } from '../../domain/repositories/ILiveryRepository';
export class InMemoryLiveryRepository implements ILiveryRepository {
private driverLiveries: Map<string, DriverLivery> = new Map();
private templates: Map<string, LiveryTemplate> = new Map();
// DriverLivery operations
async findDriverLiveryById(id: string): Promise<DriverLivery | null> {
return this.driverLiveries.get(id) ?? null;
}
async findDriverLiveriesByDriverId(driverId: string): Promise<DriverLivery[]> {
return Array.from(this.driverLiveries.values()).filter(l => l.driverId === driverId);
}
async findDriverLiveryByDriverAndCar(driverId: string, carId: string): Promise<DriverLivery | null> {
for (const livery of this.driverLiveries.values()) {
if (livery.driverId === driverId && livery.carId === carId) {
return livery;
}
}
return null;
}
async createDriverLivery(livery: DriverLivery): Promise<DriverLivery> {
if (this.driverLiveries.has(livery.id)) {
throw new Error('DriverLivery with this ID already exists');
}
this.driverLiveries.set(livery.id, livery);
return livery;
}
async updateDriverLivery(livery: DriverLivery): Promise<DriverLivery> {
if (!this.driverLiveries.has(livery.id)) {
throw new Error('DriverLivery not found');
}
this.driverLiveries.set(livery.id, livery);
return livery;
}
async deleteDriverLivery(id: string): Promise<void> {
this.driverLiveries.delete(id);
}
// LiveryTemplate operations
async findTemplateById(id: string): Promise<LiveryTemplate | null> {
return this.templates.get(id) ?? null;
}
async findTemplatesBySeasonId(seasonId: string): Promise<LiveryTemplate[]> {
return Array.from(this.templates.values()).filter(t => t.seasonId === seasonId);
}
async findTemplateBySeasonAndCar(seasonId: string, carId: string): Promise<LiveryTemplate | null> {
for (const template of this.templates.values()) {
if (template.seasonId === seasonId && template.carId === carId) {
return template;
}
}
return null;
}
async createTemplate(template: LiveryTemplate): Promise<LiveryTemplate> {
if (this.templates.has(template.id)) {
throw new Error('LiveryTemplate with this ID already exists');
}
this.templates.set(template.id, template);
return template;
}
async updateTemplate(template: LiveryTemplate): Promise<LiveryTemplate> {
if (!this.templates.has(template.id)) {
throw new Error('LiveryTemplate not found');
}
this.templates.set(template.id, template);
return template;
}
async deleteTemplate(id: string): Promise<void> {
this.templates.delete(id);
}
// Test helpers
clearDriverLiveries(): void {
this.driverLiveries.clear();
}
clearTemplates(): void {
this.templates.clear();
}
clear(): void {
this.driverLiveries.clear();
this.templates.clear();
}
}

View File

@@ -0,0 +1,59 @@
/**
* In-Memory Implementation: ISeasonSponsorshipRepository
*
* Mock repository for testing and development
*/
import type { SeasonSponsorship, SponsorshipTier } from '../../domain/entities/SeasonSponsorship';
import type { ISeasonSponsorshipRepository } from '../../domain/repositories/ISeasonSponsorshipRepository';
export class InMemorySeasonSponsorshipRepository implements ISeasonSponsorshipRepository {
private sponsorships: Map<string, SeasonSponsorship> = new Map();
async findById(id: string): Promise<SeasonSponsorship | null> {
return this.sponsorships.get(id) ?? null;
}
async findBySeasonId(seasonId: string): Promise<SeasonSponsorship[]> {
return Array.from(this.sponsorships.values()).filter(s => s.seasonId === seasonId);
}
async findBySponsorId(sponsorId: string): Promise<SeasonSponsorship[]> {
return Array.from(this.sponsorships.values()).filter(s => s.sponsorId === sponsorId);
}
async findBySeasonAndTier(seasonId: string, tier: SponsorshipTier): Promise<SeasonSponsorship[]> {
return Array.from(this.sponsorships.values()).filter(
s => s.seasonId === seasonId && s.tier === tier
);
}
async create(sponsorship: SeasonSponsorship): Promise<SeasonSponsorship> {
if (this.sponsorships.has(sponsorship.id)) {
throw new Error('SeasonSponsorship with this ID already exists');
}
this.sponsorships.set(sponsorship.id, sponsorship);
return sponsorship;
}
async update(sponsorship: SeasonSponsorship): Promise<SeasonSponsorship> {
if (!this.sponsorships.has(sponsorship.id)) {
throw new Error('SeasonSponsorship not found');
}
this.sponsorships.set(sponsorship.id, sponsorship);
return sponsorship;
}
async delete(id: string): Promise<void> {
this.sponsorships.delete(id);
}
async exists(id: string): Promise<boolean> {
return this.sponsorships.has(id);
}
// Test helper
clear(): void {
this.sponsorships.clear();
}
}

View File

@@ -0,0 +1,58 @@
/**
* In-Memory Implementation: ISponsorRepository
*
* Mock repository for testing and development
*/
import type { Sponsor } from '../../domain/entities/Sponsor';
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
export class InMemorySponsorRepository implements ISponsorRepository {
private sponsors: Map<string, Sponsor> = new Map();
async findById(id: string): Promise<Sponsor | null> {
return this.sponsors.get(id) ?? null;
}
async findAll(): Promise<Sponsor[]> {
return Array.from(this.sponsors.values());
}
async findByEmail(email: string): Promise<Sponsor | null> {
for (const sponsor of this.sponsors.values()) {
if (sponsor.contactEmail === email) {
return sponsor;
}
}
return null;
}
async create(sponsor: Sponsor): Promise<Sponsor> {
if (this.sponsors.has(sponsor.id)) {
throw new Error('Sponsor with this ID already exists');
}
this.sponsors.set(sponsor.id, sponsor);
return sponsor;
}
async update(sponsor: Sponsor): Promise<Sponsor> {
if (!this.sponsors.has(sponsor.id)) {
throw new Error('Sponsor not found');
}
this.sponsors.set(sponsor.id, sponsor);
return sponsor;
}
async delete(id: string): Promise<void> {
this.sponsors.delete(id);
}
async exists(id: string): Promise<boolean> {
return this.sponsors.has(id);
}
// Test helper
clear(): void {
this.sponsors.clear();
}
}

View File

@@ -0,0 +1,53 @@
/**
* In-Memory Implementation: ITransactionRepository
*
* Mock repository for testing and development
*/
import type { Transaction, TransactionType } from '../../domain/entities/Transaction';
import type { ITransactionRepository } from '../../domain/repositories/ITransactionRepository';
export class InMemoryTransactionRepository implements ITransactionRepository {
private transactions: Map<string, Transaction> = new Map();
async findById(id: string): Promise<Transaction | null> {
return this.transactions.get(id) ?? null;
}
async findByWalletId(walletId: string): Promise<Transaction[]> {
return Array.from(this.transactions.values()).filter(t => t.walletId === walletId);
}
async findByType(type: TransactionType): Promise<Transaction[]> {
return Array.from(this.transactions.values()).filter(t => t.type === type);
}
async create(transaction: Transaction): Promise<Transaction> {
if (this.transactions.has(transaction.id)) {
throw new Error('Transaction with this ID already exists');
}
this.transactions.set(transaction.id, transaction);
return transaction;
}
async update(transaction: Transaction): Promise<Transaction> {
if (!this.transactions.has(transaction.id)) {
throw new Error('Transaction not found');
}
this.transactions.set(transaction.id, transaction);
return transaction;
}
async delete(id: string): Promise<void> {
this.transactions.delete(id);
}
async exists(id: string): Promise<boolean> {
return this.transactions.has(id);
}
// Test helper
clear(): void {
this.transactions.clear();
}
}