mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
implement class
This commit is contained in:
@@ -2,22 +2,35 @@ import { ParkingGetterSetterRepository } from "./ParkingGetterSetterRepository";
|
|||||||
import { IParkingStructure } from "../entities/ParkingRepositoryEntities";
|
import { IParkingStructure } from "../entities/ParkingRepositoryEntities";
|
||||||
|
|
||||||
export class InMemoryParkingRepository implements ParkingGetterSetterRepository {
|
export class InMemoryParkingRepository implements ParkingGetterSetterRepository {
|
||||||
|
private structures: Map<string, IParkingStructure>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.structures = new Map<string, IParkingStructure>();
|
||||||
|
}
|
||||||
|
|
||||||
async addOrUpdateParkingStructure(structure: IParkingStructure): Promise<void> {
|
async addOrUpdateParkingStructure(structure: IParkingStructure): Promise<void> {
|
||||||
|
this.structures.set(structure.id, { ...structure });
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearParkingStructureData(): Promise<void> {
|
async clearParkingStructureData(): Promise<void> {
|
||||||
|
this.structures.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getParkingStructureById(id: string): Promise<IParkingStructure | null> {
|
async getParkingStructureById(id: string): Promise<IParkingStructure | null> {
|
||||||
return null;
|
const structure = this.structures.get(id);
|
||||||
|
return structure ? { ...structure } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getParkingStructures(): Promise<IParkingStructure[]> {
|
async getParkingStructures(): Promise<IParkingStructure[]> {
|
||||||
return [];
|
return Array.from(this.structures.values()).map(structure => ({ ...structure }));
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeParkingStructureIfExists(id: string): Promise<IParkingStructure | null> {
|
async removeParkingStructureIfExists(id: string): Promise<IParkingStructure | null> {
|
||||||
|
const structure = this.structures.get(id);
|
||||||
|
if (structure) {
|
||||||
|
this.structures.delete(id);
|
||||||
|
return { ...structure };
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user