-
-
Save JosianChevalier/eb73a2268f43c868bab0e2d5768530c4 to your computer and use it in GitHub Desktop.
An in-memory implementation of persistence mechanism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ProductRepository { | |
save(product: Product): Promise<void>; | |
load(id: ProductId): Promise<Product | null>; | |
} | |
export default class InMemoryProductRepository implements ProductRepository { | |
private products = new Map<string, Product>(); | |
async save(product: Product) { | |
this.products.set(product.id.toString(), product); | |
} | |
async load(id: ProductId): Promise<Product | null> { | |
return this.products.get(id.toString()) || null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment