mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 04:11:10 +00:00
Refactors the get books and get books lite slices across the stack
This commit is contained in:
1 parent
001146eefc
commit
1d35cd01db
44 files changed
+1681
-418
No files matched your search
-42
@@ -256,46 +256,4 @@ public static class BookEntityMapping
|
||||
NumberOfPages = repositoryEntities.NumberOfPages
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookLiteResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static BookLiteResponse ToLiteResponse(this BookEntity repositoryEntity)
|
||||
{
|
||||
return new BookLiteResponse(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.ReReleaseYear ?? repositoryEntity.OriginalReleaseYear,
|
||||
repositoryEntity.BookArtwork.FirstOrDefault(artwork => artwork.ArtworkType == ArtworkType.Cover)?.FileName
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="BookLiteResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>The converted reponses.</returns>
|
||||
public static IReadOnlyList<BookLiteResponse> ToLiteResponses(this IEnumerable<BookEntity> repositoryEntities)
|
||||
{
|
||||
return [.. repositoryEntities.Select(repositoryEntity => repositoryEntity.ToLiteResponse())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a paginated collection of <see cref="BookLiteResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The paginated repository entities to be converted.</param>
|
||||
/// <returns>The converted paginated responses.</returns>
|
||||
public static PaginatedResponse<BookLiteResponse> ToLiteResponses(this PaginatedResultDto<BookEntity> repositoryEntities)
|
||||
{
|
||||
return new PaginatedResponse<BookLiteResponse>
|
||||
{
|
||||
Data = repositoryEntities.Data.ToLiteResponses(),
|
||||
CurrentPage = repositoryEntities.CurrentPage,
|
||||
PerPage = repositoryEntities.PerPage,
|
||||
Count = repositoryEntities.Count,
|
||||
NumberOfPages = repositoryEntities.NumberOfPages
|
||||
};
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="BookLiteRow"/>.
|
||||
/// </summary>
|
||||
public static class BookLiteRowMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="readModel"/> to <see cref="BookLiteResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="readModel">The read model to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static BookLiteResponse ToResponse(this BookLiteRow readModel)
|
||||
{
|
||||
return new BookLiteResponse(
|
||||
readModel.Id,
|
||||
readModel.Title,
|
||||
readModel.ReleaseYear,
|
||||
readModel.CoverPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="readModels"/> to a collection of <see cref="BookLiteResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="readModels">The read models to be converted.</param>
|
||||
/// <returns>The converted responses.</returns>
|
||||
public static IReadOnlyList<BookLiteResponse> ToResponses(this IEnumerable<BookLiteRow> readModels)
|
||||
{
|
||||
return [.. readModels.Select(readModel => readModel.ToResponse())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="readModels"/> to a paginated collection of <see cref="BookLiteResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="readModels">The paginated read models to be converted.</param>
|
||||
/// <returns>The converted paginated responses.</returns>
|
||||
public static PaginatedResponse<BookLiteResponse> ToResponses(this PaginatedResultDto<BookLiteRow> readModels)
|
||||
{
|
||||
return new PaginatedResponse<BookLiteResponse>
|
||||
{
|
||||
Data = readModels.Data.ToResponses(),
|
||||
CurrentPage = readModels.CurrentPage,
|
||||
PerPage = readModels.PerPage,
|
||||
Count = readModels.Count,
|
||||
NumberOfPages = readModels.NumberOfPages
|
||||
};
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -16,26 +16,26 @@ public static class GetBooksLiteRequestMapping
|
||||
/// Converts <paramref name="request"/> to <see cref="GetBooksLiteQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library whose books are retrieved, taken from the route.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetBooksLiteQuery ToQuery(this GetBooksLiteRequest request)
|
||||
public static GetBooksLiteQuery ToQuery(this GetBooksLiteRequest request, string? libraryId)
|
||||
{
|
||||
PaginationDataDto? paginationData = null;
|
||||
if (request.CurrentPage is not null || request.PerPage is not null)
|
||||
{
|
||||
paginationData = new PaginationDataDto
|
||||
{
|
||||
CurrentPage = request.CurrentPage ?? 1,
|
||||
PerPage = request.PerPage ?? 200
|
||||
};
|
||||
}
|
||||
LibraryFilterDto libraryFilter = new()
|
||||
{
|
||||
LibraryId = request.LibraryId,
|
||||
SearchTerm = request.SearchTerm,
|
||||
FilterAlphaKey = request.FilterAlphaKey,
|
||||
ShouldIgnoreThePrefixForAlphaPicker = request.ShouldIgnoreThePrefixForAlphaPicker
|
||||
};
|
||||
|
||||
return new GetBooksLiteQuery(paginationData, libraryFilter, request.SortBy, request.SortOrder);
|
||||
return new GetBooksLiteQuery(
|
||||
libraryId,
|
||||
paginationData,
|
||||
request.SearchTerm,
|
||||
request.FilterAlphaKey,
|
||||
request.ShouldIgnoreThePrefixForAlphaPicker,
|
||||
request.SortBy,
|
||||
request.SortOrder
|
||||
);
|
||||
}
|
||||
}
|
||||
+3
-9
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
@@ -16,8 +15,9 @@ public static class GetBooksRequestMapping
|
||||
/// Converts <paramref name="request"/> to <see cref="GetBooksQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library whose books are retrieved, taken from the route.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetBooksQuery ToQuery(this GetBooksRequest request)
|
||||
public static GetBooksQuery ToQuery(this GetBooksRequest request, string? libraryId)
|
||||
{
|
||||
PaginationDataDto? paginationData = null;
|
||||
if (request.CurrentPage is not null || request.PerPage is not null)
|
||||
@@ -27,12 +27,6 @@ public static class GetBooksRequestMapping
|
||||
PerPage = request.PerPage ?? 200
|
||||
};
|
||||
|
||||
LibraryFilterDto libraryFilter = new()
|
||||
{
|
||||
LibraryId = request.LibraryId,
|
||||
SearchTerm = request.SearchTerm
|
||||
};
|
||||
|
||||
return new GetBooksQuery(paginationData, libraryFilter, request.SortBy, request.SortOrder);
|
||||
return new GetBooksQuery(libraryId, paginationData, request.SearchTerm, request.SortBy, request.SortOrder);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user