Adds skeleton Users management system

This commit is contained in:
BinaryAlley committed 2024-11-03 15:26:38 +02:00
1 parent faa9ce7729
commit 3dd6a0a6ca
15 files changed
+804 -40

No files matched your search

@@ -38,8 +38,8 @@ internal sealed class BookRepository : IBookRepository
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public async Task<ErrorOr<Created>> InsertAsync(BookEntity book, CancellationToken cancellationToken)
{
bool jobExists = await _luminaDbContext.Books.AnyAsync(repositoryBook => repositoryBook.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
if (jobExists)
bool bookExists = await _luminaDbContext.Books.AnyAsync(repositoryBook => repositoryBook.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
if (bookExists)
return Errors.WrittenContent.BookAlreadyExists;
// fetch existing tags and genres
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Contracts.Entities.UsersManagement;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Errors;
using Microsoft.EntityFrameworkCore;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Users;
/// <summary>
/// Repository for users.
/// </summary>
internal sealed class UserRepository : IUserRepository
{
private readonly LuminaDbContext _luminaDbContext;
/// <summary>
/// Initializes a new instance of the <see cref="UserRepository"/> class.
/// </summary>
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
public UserRepository(LuminaDbContext luminaDbContext)
{
_luminaDbContext = luminaDbContext;
}
/// <summary>
/// Adds a new user.
/// </summary>
/// <param name="user">The user to add.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public async Task<ErrorOr<Created>> InsertAsync(UserEntity user, CancellationToken cancellationToken)
{
bool userExists = await _luminaDbContext.Users.AnyAsync(repositoryUser => repositoryUser.Id == user.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
if (userExists)
return Errors.Users.UserAlreadyExists;
_luminaDbContext.Users.Add(user);
return Result.Created;
}
}