mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Implements Data Access Layer
This commit is contained in:
1 parent
b69e59a3d8
commit
8b729cc16c
24 files changed
+1721
-9
No files matched your search
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the repository for books.
|
||||
/// </summary>
|
||||
public interface IBookRepository : IRepository<BookDto>,
|
||||
IInsertRepositoryAction<BookDto>,
|
||||
IGetAllRepositoryAction<BookDto>
|
||||
{
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "delete all" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
public interface IDeleteAllRepositoryAction
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Deletes all entities from the storage medium.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Deleted>> DeleteAllAsync();
|
||||
#endregion
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "delete by id" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TId">The type used for the identifier of the respository. It should not be <see langword="null"/>.</typeparam>
|
||||
public interface IDeleteByIdRepositoryAction<TId> where TId : notnull
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Deletes an element identified by <paramref name="id"/> from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the element to be deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Deleted>> DeleteByIdAsync(TId id, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "get all" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used as a result for the "get all" action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IGetAllRepositoryAction<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets all data of type <typeparamref name="TModel"/> from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> containing either a collection of <typeparamref name="TModel"/>, or an error.</returns>
|
||||
Task<ErrorOr<IEnumerable<TModel>>> GetAllAsync(CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "get by id" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used as a result for the "get by id" action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
/// <typeparam name="TId">The type used for the identifier of the respository. It should not be <see langword="null"/>.</typeparam>
|
||||
public interface IGetByIdRepositoryAction<TModel, TId> where TModel : IStorageEntity
|
||||
where TId : notnull
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets an element of type <typeparamref name="TModel"/> identified by <paramref name="id"/> from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the element to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> containing either a <typeparamref name="TModel"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
Task<ErrorOr<TModel?>> GetByIdAsync(TId id, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "insert" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used for the insert action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IInsertRepositoryAction<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Saves an element of type <typeparamref name="TModel"/> in the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="data">The element to be saved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Created>> InsertAsync(TModel data, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "update" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used for the update action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IUpdateRepositoryAction<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Updates <paramref name="data"/> in the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="data">The element that will be updated.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Updated>> UpdateAsync(TModel data, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for interaction with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used for the repository. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IRepository<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Lumina.Application.Common.DataAccess.UoW;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction boundary with the Data Access Layer.
|
||||
/// </summary>
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Exposes a repository of type <typeparamref name="TRepository"/> to the Business Layer.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRepository">The type of the exposed repository.</typeparam>
|
||||
/// <returns>A repository of type <typeparamref name="TRepository"/>.</returns>
|
||||
TRepository GetRepository<TRepository>();
|
||||
|
||||
/// <summary>
|
||||
/// Saves all changes made to the database.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
Task SaveChangesAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Opens a transaction.
|
||||
/// </summary>
|
||||
void OpenTransaction();
|
||||
|
||||
/// <summary>
|
||||
/// Commits a transaction.
|
||||
/// </summary>
|
||||
void CommitTransaction();
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user