initial commit

This commit is contained in:
Developer 02
2024-03-06 16:14:36 +01:00
commit 67d5385c56
474 changed files with 17468 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
using DigitalData.Core.Contracts.CleanArchitecture.Infrastructure;
namespace DigitalData.Core.Contracts.CleanArchitecture.Application
{
/// <summary>
/// Implements a simplified CRUD service interface that uses a single Data Transfer Object (DTO) type for all CRUD operations,
/// streamlining the process for entities where the same DTO can be used for creating, reading, updating, and deleting entities.
/// This interface inherits from the ICRUDService interface, applying the same DTO type for all generic type parameters,
/// thereby simplifying the usage for cases where a single DTO is sufficient for all operations on an entity.
/// </summary>
/// <typeparam name="TCRUDRepository">The repository type that provides CRUD operations for entities of type TEntity.</typeparam>
/// <typeparam name="TDto">The type of the Data Transfer Object used for all CRUD operations.</typeparam>
/// <typeparam name="TEntity">The type of the entity this service maps to.</typeparam>
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
/// <remarks>
/// This interface is useful for entities that do not require different DTOs for different operations,
/// allowing for a more concise and maintainable codebase when implementing services for such entities.
/// </remarks>
public interface IBasicCRUDService<TCRUDRepository, TDto, TEntity, TId> : ICRUDService<TCRUDRepository, TDto, TDto, TDto, TEntity, TId>
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TDto : class where TEntity : class
{
}
}

View File

@@ -0,0 +1,75 @@
using DigitalData.Core.Contracts.CleanArchitecture.Infrastructure;
namespace DigitalData.Core.Contracts.CleanArchitecture.Application
{
/// <summary>
/// Defines the contract for CRUD operations at the service level using Data Transfer Objects (DTOs) for entities of type TEntity,
/// wrapped in an IServiceResult to encapsulate the outcome of the operation, including success, data, and error messages.
/// </summary>
/// <typeparam name="TCRUDRepository">The repository type that provides CRUD operations for entities of type TEntity.</typeparam>
/// <typeparam name="TCreateDto">The type of the Data Transfer Object this service works with to create new entity.</typeparam>
/// <typeparam name="TReadDto">The type of the Data Transfer Object this service works with to read new entity.</typeparam>
/// <typeparam name="TUpdateDto">The type of the Data Transfer Object this service works with to update new entity.</typeparam>
/// <typeparam name="TEntity">The type of the entity this service maps to.</typeparam>
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
public interface ICRUDService<TCRUDRepository, TCreateDto, TReadDto, TUpdateDto, TEntity, TId>
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TCreateDto : class where TReadDto : class where TUpdateDto : class where TEntity : class
{
/// <summary>
/// Creates a new entity based on the provided DTO and returns the result wrapped in an IServiceResult,
/// including the created entity on success or an error message on failure.
/// </summary>
/// <param name="createDto">The createDto to create a new entity from.</param>
/// <returns>An IServiceResult containing the id of created entity or an error message.</returns>
Task<IServiceResult<TId>> CreateAsync(TCreateDto createDto);
/// <summary>
/// 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.
/// </summary>
/// <param name="id">The identifier of the entity to retrieve.</param>
/// <returns>An IServiceResult containing the readDTO representing the found entity or null, with an appropriate message.</returns>
Task<IServiceResult<TReadDto>> ReadByIdAsync(TId id);
/// <summary>
/// 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.
/// </summary>
/// <returns>An IServiceResult containing a collection of readDTOs representing all entities or an error message.</returns>
Task<IServiceResult<IEnumerable<TReadDto>>> ReadAllAsync();
/// <summary>
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,
/// indicating the success or failure of the operation, including the error messages on failure.
/// </summary>
/// <param name="updateDto">The updateDTO with updated values for the entity.</param>
/// <returns>An IServiceMessage indicating the outcome of the update operation, with an appropriate message.</returns>
Task<IServiceMessage> UpdateAsync(TUpdateDto updateDto);
/// <summary>
/// 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.
/// </summary>
/// <param name="id">The identifier of the entity to delete.</param>
/// <returns>An IServiceMessage indicating the outcome of the delete operation, with an appropriate message.</returns>
Task<IServiceMessage> DeleteAsyncById(TId id);
/// <summary>
/// Asynchronously checks if an entity with the specified identifier exists within the data store.
/// </summary>
/// <param name="id">The identifier of the entity to check.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists.</returns>
Task<bool> HasEntity(TId id);
/// <summary>
/// Handles exceptions that occur within service actions. This method should log the exception
/// and return an String that contains information about the error, which can then be sent to the client.
/// The implementation should determine the appropriate level of detail to include in the error message
/// based on security and usability considerations.
/// </summary>
/// <param name="ex">The exception that occurred during the controller action.</param>
/// <returns>An string instance representing the outcome of the error handling process.
/// This includes a flag indicating the operation was unsuccessful and any relevant error messages.</returns>
string HandleException(Exception ex);
}
}

View File

@@ -0,0 +1,21 @@
namespace DigitalData.Core.Contracts.CleanArchitecture.Application
{
/// <summary>
/// Defines a basic structure for service messages, including a success flag and a collection of messages.
/// This interface is intended to be a base for more specific service result types, offering a way to communicate
/// operation outcomes (success or failure) along with relevant messages.
/// </summary>
public interface IServiceMessage
{
/// <summary>
/// Gets or sets a value indicating whether the service operation was successful.
/// </summary>
bool IsSuccess { get; set; }
/// <summary>
/// Gets or sets a collection of messages associated with the service operation. These messages can be error descriptions,
/// success notifications, or other relevant information related to the operation's outcome.
/// </summary>
List<string> Messages { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
namespace DigitalData.Core.Contracts.CleanArchitecture.Application
{
public interface IServiceReplier
{
IServiceMessage CreateMessage(bool isSuccess, params string[] messages);
IServiceResult<T> CreateResult<T>(T? data, bool isSuccess = true, params string[] messages);
IServiceMessage Successful() => CreateMessage(true);
IServiceMessage Failed(params string[] messages) => CreateMessage(false, messages);
IServiceResult<T> Successful<T>(T data) => CreateResult(data);
IServiceResult<T> Failed<T>(T? data, params string[] messages) => CreateResult(data, false, messages);
IServiceResult<T> FailedResult<T>(params string[] messages) => Failed<T>(default, messages);
}
}

View File

@@ -0,0 +1,19 @@
namespace DigitalData.Core.Contracts.CleanArchitecture.Application
{
/// <summary>
/// Represents the outcome of a service operation, extending IServiceMessage with the addition of a data payload.
/// This interface is generic, allowing for the specification of the type of data returned by the service operation.
/// It is used to communicate not just the success or failure of an operation, but also to return any relevant data
/// along with the operation's outcome.
/// </summary>
/// <typeparam name="T">The type of the data associated with the service operation's outcome. This could be a model,
/// a collection of models, or any other type relevant to the operation.</typeparam>
public interface IServiceResult<T> : IServiceMessage
{
/// <summary>
/// Gets or sets the data resulting from the service operation. This property is nullable to accommodate operations
/// that might not return data upon failure.
/// </summary>
T? Data { get; set; }
}
}