mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 10:01:10 +00:00
Implements first stage library management system
This commit is contained in:
1 parent
5e0f94cd82
commit
36352ea9e8
291 files changed
+3733
-1384
No files matched your search
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="AddBookRequest"/>.
|
||||
/// </summary>
|
||||
public static class AddBookRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="AddBookCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddBookCommand ToCommand(this AddBookRequest request)
|
||||
{
|
||||
return new AddBookCommand(
|
||||
request.Metadata,
|
||||
request.Format,
|
||||
request.Edition,
|
||||
request.VolumeNumber,
|
||||
request.Series,
|
||||
request.ASIN,
|
||||
request.GoodreadsId,
|
||||
request.LCCN,
|
||||
request.OCLCNumber,
|
||||
request.OpenLibraryId,
|
||||
request.LibraryThingId,
|
||||
request.GoogleBooksId,
|
||||
request.BarnesAndNobleId,
|
||||
request.AppleBooksId,
|
||||
request.ISBNs,
|
||||
request.Contributors,
|
||||
request.Ratings
|
||||
);
|
||||
}
|
||||
}
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="BookEntity"/>.
|
||||
/// </summary>
|
||||
public static class BookEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="Book"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Book"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Book> ToDomainEntity(this BookEntity repositoryEntity)
|
||||
{
|
||||
IEnumerable<ErrorOr<Tag>> tagsResult = repositoryEntity.Tags.ToDomainEntities();
|
||||
foreach (ErrorOr<Tag> tagResult in tagsResult)
|
||||
if (tagResult.IsError)
|
||||
return tagResult.Errors;
|
||||
|
||||
IEnumerable<ErrorOr<Genre>> genresResult = repositoryEntity.Genres.ToDomainEntities();
|
||||
foreach (ErrorOr<Genre> genreResult in genresResult)
|
||||
if (genreResult.IsError)
|
||||
return genreResult.Errors;
|
||||
|
||||
IEnumerable<ErrorOr<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainEntities();
|
||||
foreach (ErrorOr<Isbn> isbnResult in isbnsResult)
|
||||
if (isbnResult.IsError)
|
||||
return isbnResult.Errors;
|
||||
|
||||
IEnumerable<ErrorOr<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainEntities();
|
||||
foreach (ErrorOr<BookRating> bookRatingResult in bookRatingsResult)
|
||||
if (bookRatingResult.IsError)
|
||||
return bookRatingResult.Errors;
|
||||
|
||||
ErrorOr<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(repositoryEntity.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.ReReleaseDate),
|
||||
Optional<int>.FromNullable(repositoryEntity.ReReleaseYear),
|
||||
Optional<string>.FromNullable(repositoryEntity.ReleaseCountry),
|
||||
Optional<string>.FromNullable(repositoryEntity.ReleaseVersion)
|
||||
);
|
||||
if (releaseInfoResult.IsError)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
Optional<LanguageInfo> languageInfo = Optional<LanguageInfo>.None();
|
||||
if (repositoryEntity.LanguageCode is not null)
|
||||
{
|
||||
ErrorOr<LanguageInfo> languageInfoResult = LanguageInfo.Create(
|
||||
repositoryEntity.LanguageCode,
|
||||
repositoryEntity.LanguageName,
|
||||
Optional<string>.FromNullable(repositoryEntity.LanguageNativeName)
|
||||
);
|
||||
if (languageInfoResult.IsError)
|
||||
return languageInfoResult.Errors;
|
||||
languageInfo = languageInfoResult.Value;
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> originalLanguageCode = Optional<LanguageInfo>.None();
|
||||
if (repositoryEntity.OriginalLanguageCode is not null)
|
||||
{
|
||||
ErrorOr<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(
|
||||
repositoryEntity.OriginalLanguageCode,
|
||||
repositoryEntity.OriginalLanguageName!,
|
||||
Optional<string>.FromNullable(repositoryEntity.OriginalLanguageNativeName)
|
||||
);
|
||||
if (originalLanguageInfoResult.IsError)
|
||||
return originalLanguageInfoResult.Errors;
|
||||
originalLanguageCode = originalLanguageInfoResult.Value;
|
||||
}
|
||||
|
||||
ErrorOr<WrittenContentMetadata> writtenContentMetadataResult = WrittenContentMetadata.Create(
|
||||
repositoryEntity.Title,
|
||||
Optional<string>.FromNullable(repositoryEntity.OriginalTitle),
|
||||
Optional<string>.FromNullable(repositoryEntity.Description),
|
||||
releaseInfoResult.Value,
|
||||
genresResult.Select(genre => genre.Value).ToList(),
|
||||
tagsResult.Select(tag => tag.Value).ToList(),
|
||||
languageInfo,
|
||||
originalLanguageCode,
|
||||
Optional<string>.FromNullable(repositoryEntity.Publisher),
|
||||
Optional<int>.FromNullable(repositoryEntity.PageCount)
|
||||
);
|
||||
if (writtenContentMetadataResult.IsError)
|
||||
return writtenContentMetadataResult.Errors;
|
||||
|
||||
Optional<BookFormat> bookFormat = Optional<BookFormat>.FromNullable(repositoryEntity.Format);
|
||||
|
||||
return Book.Create(
|
||||
BookId.Create(repositoryEntity.Id),
|
||||
writtenContentMetadataResult.Value,
|
||||
bookFormat,
|
||||
Optional<string>.FromNullable(repositoryEntity.Edition),
|
||||
Optional<int>.FromNullable(repositoryEntity.VolumeNumber),
|
||||
Optional<BookSeries>.None(),
|
||||
Optional<string>.FromNullable(repositoryEntity.ASIN),
|
||||
Optional<string>.FromNullable(repositoryEntity.GoodreadsId),
|
||||
Optional<string>.FromNullable(repositoryEntity.LCCN),
|
||||
Optional<string>.FromNullable(repositoryEntity.OCLCNumber),
|
||||
Optional<string>.FromNullable(repositoryEntity.OpenLibraryId),
|
||||
Optional<string>.FromNullable(repositoryEntity.LibraryThingId),
|
||||
Optional<string>.FromNullable(repositoryEntity.GoogleBooksId),
|
||||
Optional<string>.FromNullable(repositoryEntity.BarnesAndNobleId),
|
||||
Optional<string>.FromNullable(repositoryEntity.AppleBooksId),
|
||||
repositoryEntity.Created,
|
||||
Optional<DateTime>.FromNullable(repositoryEntity.Updated),
|
||||
isbnsResult.Select(isbn => isbn.Value).ToList(),
|
||||
[],
|
||||
bookRatingsResult.Select(bookRating => bookRating.Value).ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Book"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>The converted domain entities.</returns>
|
||||
/// <returns>
|
||||
/// An colection of <see cref="ErrorOr{TValue}"/> containing either successfully converted <see cref="Book"/>, or error messages.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Book>> ToDomainEntities(this IEnumerable<BookEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static BookResponse ToResponse(this BookEntity repositoryEntity)
|
||||
{
|
||||
ReleaseInfoEntity releaseInfoEntity = new(
|
||||
repositoryEntity.OriginalReleaseDate,
|
||||
repositoryEntity.OriginalReleaseYear,
|
||||
repositoryEntity.ReReleaseDate,
|
||||
repositoryEntity.ReReleaseYear,
|
||||
repositoryEntity.ReleaseCountry,
|
||||
repositoryEntity.ReleaseVersion
|
||||
);
|
||||
// language and original language make sense only if their subproperties have values
|
||||
LanguageInfoEntity? languageInfoEntity = !string.IsNullOrWhiteSpace(repositoryEntity.LanguageCode) ||
|
||||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageName) ||
|
||||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageNativeName)
|
||||
? new LanguageInfoEntity(
|
||||
repositoryEntity.LanguageCode,
|
||||
repositoryEntity.LanguageName,
|
||||
repositoryEntity.LanguageNativeName
|
||||
) : null;
|
||||
LanguageInfoEntity? originalLanguageInfoEntity = !string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageCode) ||
|
||||
!string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageName) ||
|
||||
!string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageNativeName)
|
||||
? new LanguageInfoEntity(
|
||||
repositoryEntity.OriginalLanguageCode,
|
||||
repositoryEntity.OriginalLanguageName,
|
||||
repositoryEntity.OriginalLanguageNativeName
|
||||
) : null;
|
||||
WrittenContentMetadataEntity metadata = new(
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.OriginalTitle,
|
||||
repositoryEntity.Description,
|
||||
releaseInfoEntity,
|
||||
[.. repositoryEntity.Genres],
|
||||
[.. repositoryEntity.Tags],
|
||||
languageInfoEntity,
|
||||
originalLanguageInfoEntity,
|
||||
repositoryEntity.Publisher,
|
||||
repositoryEntity.PageCount
|
||||
);
|
||||
return new BookResponse(
|
||||
repositoryEntity.Id,
|
||||
metadata,
|
||||
repositoryEntity.Format,
|
||||
repositoryEntity.Edition,
|
||||
repositoryEntity.VolumeNumber,
|
||||
null,
|
||||
repositoryEntity.ASIN,
|
||||
repositoryEntity.GoodreadsId,
|
||||
repositoryEntity.LCCN,
|
||||
repositoryEntity.OCLCNumber,
|
||||
repositoryEntity.OpenLibraryId,
|
||||
repositoryEntity.LibraryThingId,
|
||||
repositoryEntity.GoogleBooksId,
|
||||
repositoryEntity.BarnesAndNobleId,
|
||||
repositoryEntity.AppleBooksId,
|
||||
repositoryEntity.ISBNs,
|
||||
null,
|
||||
repositoryEntity.Ratings,
|
||||
repositoryEntity.Created,
|
||||
repositoryEntity.Updated
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Book"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>The converted reponses.</returns>
|
||||
public static IEnumerable<BookResponse> ToResponses(this IEnumerable<BookEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToResponse());
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="Book"/>.
|
||||
/// </summary>
|
||||
public static class BookMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="BookEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static BookEntity ToRepositoryEntity(this Book domainEntity)
|
||||
{
|
||||
return new BookEntity
|
||||
{
|
||||
Id = domainEntity.Id.Value,
|
||||
Title = domainEntity.Metadata.Title,
|
||||
OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null,
|
||||
Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null,
|
||||
OriginalReleaseDate = domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null,
|
||||
OriginalReleaseYear = domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null,
|
||||
ReReleaseDate = domainEntity.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseDate.Value : null,
|
||||
ReReleaseYear = domainEntity.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseYear.Value : null,
|
||||
ReleaseCountry = domainEntity.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? domainEntity.Metadata.ReleaseInfo.ReleaseCountry.Value : null,
|
||||
ReleaseVersion = domainEntity.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? domainEntity.Metadata.ReleaseInfo.ReleaseVersion.Value : null,
|
||||
LanguageCode = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.LanguageCode : null,
|
||||
LanguageName = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.LanguageName : null,
|
||||
LanguageNativeName = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.NativeName.Value : null,
|
||||
OriginalLanguageCode = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageCode : null,
|
||||
OriginalLanguageName = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageName : null,
|
||||
OriginalLanguageNativeName = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.NativeName.Value : null,
|
||||
Tags = domainEntity.Metadata.Tags.ToRepositoryEntities().ToHashSet(),
|
||||
Genres = domainEntity.Metadata.Genres.ToRepositoryEntities().ToHashSet(),
|
||||
Publisher = domainEntity.Metadata.Publisher.HasValue ? domainEntity.Metadata.Publisher.Value : null,
|
||||
PageCount = domainEntity.Metadata.PageCount.HasValue ? domainEntity.Metadata.PageCount.Value : null,
|
||||
Format = domainEntity.Format.HasValue ? domainEntity.Format.Value : null,
|
||||
Edition = domainEntity.Edition.HasValue ? domainEntity.Edition.Value : null,
|
||||
VolumeNumber = domainEntity.VolumeNumber.HasValue ? domainEntity.VolumeNumber.Value : null,
|
||||
ASIN = domainEntity.ASIN.HasValue ? domainEntity.ASIN.Value : null,
|
||||
GoodreadsId = domainEntity.GoodreadsId.HasValue ? domainEntity.GoodreadsId.Value : null,
|
||||
LCCN = domainEntity.LCCN.HasValue ? domainEntity.LCCN.Value : null,
|
||||
OCLCNumber = domainEntity.OCLCNumber.HasValue ? domainEntity.OCLCNumber.Value : null,
|
||||
OpenLibraryId = domainEntity.OpenLibraryId.HasValue ? domainEntity.OpenLibraryId.Value : null,
|
||||
LibraryThingId = domainEntity.LibraryThingId.HasValue ? domainEntity.LibraryThingId.Value : null,
|
||||
GoogleBooksId = domainEntity.GoogleBooksId.HasValue ? domainEntity.GoogleBooksId.Value : null,
|
||||
BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null,
|
||||
AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null,
|
||||
ISBNs = domainEntity.ISBNs.ToRepositoryEntities().ToList(),
|
||||
Ratings = domainEntity.Ratings.ToRepositoryEntities().ToList(),
|
||||
Created = domainEntity.Created,
|
||||
Updated = domainEntity.Updated.HasValue ? domainEntity.Updated : null
|
||||
};
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="BookRatingEntity"/>.
|
||||
/// </summary>
|
||||
public static class BookRatingEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookRating"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted domain entity.</returns>
|
||||
public static ErrorOr<BookRating> ToDomainEntity(this BookRatingEntity repositoryEntity)
|
||||
{
|
||||
return BookRating.Create(
|
||||
repositoryEntity.Value ?? default,
|
||||
repositoryEntity.MaxValue ?? default,
|
||||
Optional<BookRatingSource>.FromNullable(repositoryEntity.Source),
|
||||
Optional<int>.FromNullable(repositoryEntity.VoteCount)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="BookRating"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>The converted domain entities.</returns>
|
||||
public static IEnumerable<ErrorOr<BookRating>> ToDomainEntities(this IEnumerable<BookRatingEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="BookRating"/>.
|
||||
/// </summary>
|
||||
public static class BookRatingMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="BookRatingEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static BookRatingEntity ToRepositoryEntity(this BookRating domainEntity)
|
||||
{
|
||||
return new BookRatingEntity(
|
||||
domainEntity.Value,
|
||||
domainEntity.MaxValue,
|
||||
domainEntity.Source.HasValue ? domainEntity.Source.Value : null,
|
||||
domainEntity.VoteCount.HasValue ? domainEntity.VoteCount.Value : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="BookRatingEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntities">The domain entities to be converted.</param>
|
||||
/// <returns>The converted repository entities.</returns>
|
||||
public static IEnumerable<BookRatingEntity> ToRepositoryEntities(this IEnumerable<BookRating> domainEntities)
|
||||
{
|
||||
return domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity());
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="IsbnEntity"/>.
|
||||
/// </summary>
|
||||
public static class IsbnEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="Isbn"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
|
||||
{
|
||||
return Isbn.Create(
|
||||
repositoryEntity.Value,
|
||||
repositoryEntity.Format ?? IsbnFormat.Isbn13
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Isbn"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>The converted domain entities.</returns>
|
||||
public static IEnumerable<ErrorOr<Isbn>> ToDomainEntities(this IEnumerable<IsbnEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="Isbn"/>.
|
||||
/// </summary>
|
||||
public static class IsbnMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="IsbnEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static IsbnEntity ToRepositoryEntity(this Isbn domainEntity)
|
||||
{
|
||||
return new IsbnEntity(
|
||||
domainEntity.Value,
|
||||
domainEntity.Format
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="IsbnEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntities">The domain entities to be converted.</param>
|
||||
/// <returns>The converted repository entities.</returns>
|
||||
public static IEnumerable<IsbnEntity> ToRepositoryEntities(this IEnumerable<Isbn> domainEntities)
|
||||
{
|
||||
return domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user