From 3556f1ef3ae052d5debac39354f23217f83a6e56 Mon Sep 17 00:00:00 2001 From: Michael Krog Date: Tue, 27 Aug 2024 14:41:49 +0200 Subject: [PATCH] Adds interface method for deleting all entities. --- src/repository/crud-repository.ts | 76 +++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/src/repository/crud-repository.ts b/src/repository/crud-repository.ts index 4423865..3190b95 100644 --- a/src/repository/crud-repository.ts +++ b/src/repository/crud-repository.ts @@ -2,15 +2,85 @@ import { Page } from "../domain/page"; import { PageRequest } from "../domain/page-request"; /** - * Interface for generic CRUD operations on a repository for a specific type. + * Interface for generic CRUD (Create, Read, Update, Delete) operations on a repository + * for a specific entity type. This interface provides a blueprint for repositories to + * handle entities of any type, identified by an ID of a specific type. + * + * @template TYPE - The type of the entity the repository manages. + * @template IDTYPE - The type of the unique identifier for the entity. */ export interface CrudRepository { - findAll(pageable?: PageRequest): Promise>; + + /** + * Retrieves all entities from the repository + * + * @param {PageRequest} [pageable] - Optional pagination information (page number, page size). + * @returns {Promise>} - A promise that resolves to a page of entities. + */ + findAll(pageable?: PageRequest): Promise>; + + /** + * Retrieves an entity by its unique identifier. + * + * @param {IDTYPE} id - The unique identifier of the entity. + * @returns {Promise} - A promise that resolves to the entity, or rejects if not found. + */ findById(id: IDTYPE): Promise; + + /** + * Saves a given entity in the repository, creating a new entity if it doesn't exist, + * or updating the existing one if it does. + * + * @param {TYPE} entity - The entity to save. + * @returns {Promise} - A promise that resolves to the saved entity. + */ save(entity: TYPE): Promise; + + /** + * Saves multiple entities in the repository, creating new entities if they don't exist, + * or updating the existing ones if they do. + * + * @param {TYPE[]} entities - The entities to save. + * @returns {Promise - A promise that resolves to the saved entities. + */ saveAll(entities: TYPE[]): Promise; + + /** + * Deletes an entity by its unique identifier from the repository. + * + * @param {IDTYPE} id - The unique identifier of the entity to delete. + * @returns {Promise} - A promise that resolves when the entity is deleted. + */ deleteById(id: IDTYPE): Promise; + + /** + * Deletes multiple entities identified by their unique identifiers from the repository. + * + * @param {IDTYPE[]} ids - The unique identifiers of the entities to delete. + * @returns {Promise} - A promise that resolves when the entities are deleted. + */ deleteAllById(ids: IDTYPE[]): Promise; + + /** + * Deletes a given entity from the repository. + * + * @param {TYPE} entity - The entity to delete. + * @returns {Promise} - A promise that resolves when the entity is deleted. + */ delete(entity: TYPE): Promise; + + /** + * Deletes multiple entities from the repository. + * + * @param {TYPE[]} entities - The entities to delete. + * @returns {Promise} - A promise that resolves when the entities are deleted. + */ deleteAll(entities: TYPE[]): Promise; -} \ No newline at end of file + + /** + * Deletes all entities from the repository. + * + * @returns {Promise} - A promise that resolves when the entities are deleted. + */ + deleteAll(): Promise; +}