mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Adds skeleton Users management system
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.UsersManagement;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -19,6 +20,7 @@ namespace Lumina.DataAccess.Core.UoW;
|
||||
public class LuminaDbContext : DbContext
|
||||
{
|
||||
public virtual DbSet<BookEntity> Books { get; set; } = null!;
|
||||
public virtual DbSet<UserEntity> Users { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LuminaDbContext"/> class.
|
||||
|
||||
Reference in new issue
Block a user