From 2c739fbf024a06f10f46fdd6bff868e9df80868d Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 13 Sep 2024 16:48:37 +0200 Subject: [PATCH] refactor: ICRUDService von IReadService erweitern und Methoden aktualisieren MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ICRUDService angepasst, um von IReadService zu erben, um die Wiederverwendbarkeit von Lesevorgängen zu fördern - ICRUDService um `CreateAsync`- und `UpdateAsync`-Methoden mit geeigneten Rückgabetypen ergänzt - Konsistenz gewährleistet durch Durchsetzung von IUnique-Einschränkungen für DTOs und Entitäten --- .../Application/ICRUDService.cs | 38 ++++--------------- .../Application/IReadService.cs | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 DigitalData.Core.Abstractions/Application/IReadService.cs diff --git a/DigitalData.Core.Abstractions/Application/ICRUDService.cs b/DigitalData.Core.Abstractions/Application/ICRUDService.cs index 0b07300..bffd0b2 100644 --- a/DigitalData.Core.Abstractions/Application/ICRUDService.cs +++ b/DigitalData.Core.Abstractions/Application/ICRUDService.cs @@ -1,27 +1,18 @@ -using DigitalData.Core.Abstractions.Infrastructure; -using DigitalData.Core.DTO; +using DigitalData.Core.DTO; namespace DigitalData.Core.Abstractions.Application { - public interface ICRUDService + public interface ICRUDService : IReadService where TCreateDto : class where TReadDto : class where TUpdateDto : IUnique where TEntity : class, IUnique { - Task> CreateAsync(TCreateDto createDto); - /// - /// Retrieves an entity by its identifier and returns its readDTO representation wrapped in an IServiceResult, - /// including the readDTO on success or null and an error message on failure. + /// Asynchronously creates a new entity based on the provided and returns the identifier of the created entity wrapped in a . + /// The contains the identifier of the newly created entity on success or an error message on failure. /// - /// The identifier of the entity to retrieve. - /// An DataResult containing the readDTO representing the found entity or null, with an appropriate message. - Task> ReadByIdAsync(TId id); + /// The data transfer object containing the information for the new entity. + /// A task representing the asynchronous operation, with a containing the identifier of the created entity or an error message. + Task> CreateAsync(TCreateDto createDto); - /// - /// Retrieves all entities and returns their readDTO representations wrapped in an IServiceResult, - /// including a collection of readDTOs on success or an error message on failure. - /// - /// An DataResult containing a collection of readDTOs representing all entities or an error message. - Task>> ReadAllAsync(); /// /// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage, @@ -30,20 +21,5 @@ namespace DigitalData.Core.Abstractions.Application /// The updateDTO with updated values for the entity. /// An Result indicating the outcome of the update operation, with an appropriate message. Task UpdateAsync(TUpdateDto updateDto); - - /// - /// Deletes an entity by its identifier and returns the result wrapped in an IServiceMessage, - /// indicating the success or failure of the operation, including the error messages on failure. - /// - /// The identifier of the entity to delete. - /// An Result indicating the outcome of the delete operation, with an appropriate message. - Task DeleteAsyncById(TId id); - - /// - /// Asynchronously checks if an entity with the specified identifier exists within the data store. - /// - /// The identifier of the entity to check. - /// A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists. - Task HasEntity(TId id); } } \ No newline at end of file diff --git a/DigitalData.Core.Abstractions/Application/IReadService.cs b/DigitalData.Core.Abstractions/Application/IReadService.cs new file mode 100644 index 0000000..a5dc409 --- /dev/null +++ b/DigitalData.Core.Abstractions/Application/IReadService.cs @@ -0,0 +1,38 @@ +using DigitalData.Core.DTO; + +namespace DigitalData.Core.Abstractions.Application +{ + public interface IReadService + where TReadDto : class where TEntity : class, IUnique + { + /// + /// Retrieves an entity by its identifier and returns its readDTO representation wrapped in an IServiceResult, + /// including the readDTO on success or null and an error message on failure. + /// + /// The identifier of the entity to retrieve. + /// An DataResult containing the readDTO representing the found entity or null, with an appropriate message. + Task> ReadByIdAsync(TId id); + + /// + /// Retrieves all entities and returns their readDTO representations wrapped in an IServiceResult, + /// including a collection of readDTOs on success or an error message on failure. + /// + /// An DataResult containing a collection of readDTOs representing all entities or an error message. + Task>> ReadAllAsync(); + + /// + /// Deletes an entity by its identifier and returns the result wrapped in an IServiceMessage, + /// indicating the success or failure of the operation, including the error messages on failure. + /// + /// The identifier of the entity to delete. + /// An Result indicating the outcome of the delete operation, with an appropriate message. + Task DeleteAsyncById(TId id); + + /// + /// Asynchronously checks if an entity with the specified identifier exists within the data store. + /// + /// The identifier of the entity to check. + /// A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists. + Task HasEntity(TId id); + } +} \ No newline at end of file