Replaces MVC with FastEndpoints in Lumina.Presentation.Api

This commit is contained in:
BinaryAlley committed 2024-10-23 21:34:10 +03:00
1 parent b1a20716df
commit c7b8bc2f1c
519 files changed
+15329 -8539

No files matched your search

@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Entities.Common;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Collections.Generic;
@@ -9,15 +9,15 @@ using System.Collections.Generic;
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="BookModel"/> entity.
/// Configures the entity mapping for the <see cref="BookEntity"/> entity.
/// </summary>
public class BookConfiguration : IEntityTypeConfiguration<BookModel>
public class BookConfiguration : IEntityTypeConfiguration<BookEntity>
{
/// <summary>
/// Configures the <see cref="BookModel"/> entity.
/// Configures the <see cref="BookEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<BookModel> builder)
public void Configure(EntityTypeBuilder<BookEntity> builder)
{
builder.ToTable("Books");
builder.HasKey(book => book.Id);
@@ -46,8 +46,8 @@ public class BookConfiguration : IEntityTypeConfiguration<BookModel>
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"BookTags",
j => j.HasOne<TagModel>().WithMany().HasForeignKey("TagId"),
j => j.HasOne<BookModel>().WithMany().HasForeignKey("BookId"),
j => j.HasOne<TagEntity>().WithMany().HasForeignKey("TagId"),
j => j.HasOne<BookEntity>().WithMany().HasForeignKey("BookId"),
j =>
{
j.HasKey("BookId", "TagId");
@@ -58,8 +58,8 @@ public class BookConfiguration : IEntityTypeConfiguration<BookModel>
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"BookGenres",
j => j.HasOne<GenreModel>().WithMany().HasForeignKey("GenreId"),
j => j.HasOne<BookModel>().WithMany().HasForeignKey("BookId"),
j => j.HasOne<GenreEntity>().WithMany().HasForeignKey("GenreId"),
j => j.HasOne<BookEntity>().WithMany().HasForeignKey("BookId"),
j =>
{
j.HasKey("BookId", "GenreId");
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Entities.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
@@ -7,15 +7,15 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="GenreModel"/> entity.
/// Configures the entity mapping for the <see cref="GenreEntity"/> entity.
/// </summary>
public class GenreConfiguration : IEntityTypeConfiguration<GenreModel>
public class GenreConfiguration : IEntityTypeConfiguration<GenreEntity>
{
/// <summary>
/// Configures the <see cref="GenreModel"/> entity.
/// Configures the <see cref="GenreEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<GenreModel> builder)
public void Configure(EntityTypeBuilder<GenreEntity> builder)
{
builder.ToTable("Genres");
builder.HasKey(genre => genre.Name);
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Entities.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
@@ -7,15 +7,15 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="TagModel"/> entity.
/// Configures the entity mapping for the <see cref="TagEntity"/> entity.
/// </summary>
public class TagConfiguration : IEntityTypeConfiguration<TagModel>
public class TagConfiguration : IEntityTypeConfiguration<TagEntity>
{
/// <summary>
/// Configures the <see cref="TagModel"/> entity.
/// Configures the <see cref="TagEntity"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<TagModel> builder)
public void Configure(EntityTypeBuilder<TagEntity> builder)
{
builder.ToTable("Tags");
builder.HasKey(tag => tag.Name);
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Entities.Common;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Errors;
using Microsoft.EntityFrameworkCore;
@@ -36,24 +36,24 @@ internal sealed class BookRepository : IBookRepository
/// <param name="book">The book 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(BookModel book, CancellationToken cancellationToken)
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)
return Errors.WrittenContent.BookAlreadyExists;
// fetch existing tags and genres
List<TagModel> existingTags = await _luminaDbContext.Set<TagModel>()
List<TagEntity> existingTags = await _luminaDbContext.Set<TagEntity>()
.Where(t => book.Tags.Select(bt => bt.Name).Contains(t.Name))
.ToListAsync(cancellationToken).ConfigureAwait(false);
List<GenreModel> existingGenres = await _luminaDbContext.Set<GenreModel>()
List<GenreEntity> existingGenres = await _luminaDbContext.Set<GenreEntity>()
.Where(g => book.Genres.Select(bg => bg.Name).Contains(g.Name))
.ToListAsync(cancellationToken).ConfigureAwait(false);
// replace tags and genres in the book with existing ones
book.Tags = new HashSet<TagModel>(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag));
book.Genres = new HashSet<GenreModel>(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre));
book.Tags = new HashSet<TagEntity>(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag));
book.Genres = new HashSet<GenreEntity>(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre));
_luminaDbContext.Books.Add(book);
return Result.Created;
@@ -63,8 +63,8 @@ internal sealed class BookRepository : IBookRepository
/// Gets all books.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookModel"/>, or an error.</returns>
public async Task<ErrorOr<IEnumerable<BookModel>>> GetAllAsync(CancellationToken cancellationToken)
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookEntity"/>, or an error.</returns>
public async Task<ErrorOr<IEnumerable<BookEntity>>> GetAllAsync(CancellationToken cancellationToken)
{
return await _luminaDbContext.Books
.Include(book => book.Tags)
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Entities.Common;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Events;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
@@ -18,7 +18,7 @@ namespace Lumina.DataAccess.Core.UoW;
/// <remarks>To update the database: update-database -p Lumina.DataAccess -s Lumina.Presentation.Api</remarks>
public class LuminaDbContext : DbContext
{
public virtual DbSet<BookModel> Books { get; set; } = null!;
public virtual DbSet<BookEntity> Books { get; set; } = null!;
/// <summary>
/// Initializes a new instance of the <see cref="LuminaDbContext"/> class.
@@ -17,15 +17,14 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
<PackageReference Include="EntityFrameworkCore.Testing.NSubstitute" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>