mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 18:11:10 +00:00
Adds the music library application mappings and renames the value object conversion methods
This commit is contained in:
1 parent
a939d8fd5f
commit
4f0526faa4
98 files changed
+2869
-610
No files matched your search
@@ -20,7 +20,7 @@ public static class GenreDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Genre> ToDomainEntity(this GenreDto dto)
|
||||
public static Result<Genre> ToDomainValueObject(this GenreDto dto)
|
||||
{
|
||||
return Genre.Create(
|
||||
dto.Name!
|
||||
@@ -34,8 +34,8 @@ public static class GenreDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Genre>> ToDomainEntities(this IEnumerable<GenreDto> dtos)
|
||||
public static IEnumerable<Result<Genre>> ToDomainValueObjects(this IEnumerable<GenreDto> dtos)
|
||||
{
|
||||
return dtos.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return dtos.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public static class GenreEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Genre> ToDomainEntity(this GenreEntity repositoryEntity)
|
||||
public static Result<Genre> ToDomainValueObject(this GenreEntity repositoryEntity)
|
||||
{
|
||||
return Genre.Create(
|
||||
repositoryEntity.Name!
|
||||
@@ -57,8 +57,8 @@ public static class GenreEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Genre>> ToDomainEntities(this IEnumerable<GenreEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Genre>> ToDomainValueObjects(this IEnumerable<GenreEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public static class LanguageInfoDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="LanguageInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<LanguageInfo> ToDomainEntity(this LanguageInfoDto dto)
|
||||
public static Result<LanguageInfo> ToDomainValueObject(this LanguageInfoDto dto)
|
||||
{
|
||||
return LanguageInfo.Create(
|
||||
dto.LanguageCode!,
|
||||
|
||||
@@ -20,7 +20,7 @@ public static class ReleaseInfoDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="ReleaseInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<ReleaseInfo> ToDomainEntity(this ReleaseInfoDto dto)
|
||||
public static Result<ReleaseInfo> ToDomainValueObject(this ReleaseInfoDto dto)
|
||||
{
|
||||
return ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(dto.OriginalReleaseDate),
|
||||
|
||||
@@ -20,7 +20,7 @@ public static class TagDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Tag> ToDomainEntity(this TagDto dto)
|
||||
public static Result<Tag> ToDomainValueObject(this TagDto dto)
|
||||
{
|
||||
return Tag.Create(
|
||||
dto.Name!
|
||||
@@ -34,8 +34,8 @@ public static class TagDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Tag>> ToDomainEntities(this IEnumerable<TagDto> dtos)
|
||||
public static IEnumerable<Result<Tag>> ToDomainValueObjects(this IEnumerable<TagDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public static class TagEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Tag> ToDomainEntity(this TagEntity repositoryEntity)
|
||||
public static Result<Tag> ToDomainValueObject(this TagEntity repositoryEntity)
|
||||
{
|
||||
return Tag.Create(
|
||||
repositoryEntity.Name!
|
||||
@@ -57,8 +57,8 @@ public static class TagEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Tag>> ToDomainEntities(this IEnumerable<TagEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Tag>> ToDomainValueObjects(this IEnumerable<TagEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+17
-6
@@ -3,7 +3,7 @@ using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.AddAlbum;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
@@ -30,16 +30,17 @@ public static class AddAlbumCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Album> ToDomainEntity(this AddAlbumCommand command)
|
||||
{
|
||||
Result<AlbumMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicAlbumMetadataDto metadata = command.Metadata!;
|
||||
Result<AlbumMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -78,9 +79,14 @@ public static class AddAlbumCommandMapping
|
||||
return Album.Create(
|
||||
AlbumId.Create(command.AlbumId.Value),
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(command.Packaging),
|
||||
Optional<string>.FromNullable(metadata.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(command.CatalogNumber),
|
||||
command.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(command.Label),
|
||||
Optional<string>.FromNullable(command.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
@@ -92,9 +98,14 @@ public static class AddAlbumCommandMapping
|
||||
|
||||
return Album.Create(
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(command.Packaging),
|
||||
Optional<string>.FromNullable(metadata.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(command.CatalogNumber),
|
||||
command.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(command.Label),
|
||||
Optional<string>.FromNullable(command.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
|
||||
+4
-1
@@ -27,8 +27,11 @@ public static class AddAlbumRequestMapping
|
||||
artistId,
|
||||
request.Metadata,
|
||||
request.MediaFormat,
|
||||
request.Packaging,
|
||||
request.Barcode,
|
||||
request.CatalogNumber,
|
||||
request.CatalogNumbers,
|
||||
request.Label,
|
||||
request.ASIN,
|
||||
request.MusicBrainzReleaseId,
|
||||
request.MusicBrainzReleaseGroupId,
|
||||
request.MusicBrainzReleaseArtistId,
|
||||
|
||||
+23
-13
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
@@ -16,10 +18,6 @@ using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
@@ -49,7 +47,7 @@ public static class AlbumEntityMapping
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainEntities())
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainValueObjects())
|
||||
{
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
@@ -57,7 +55,7 @@ public static class AlbumEntityMapping
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainEntities())
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainValueObjects())
|
||||
{
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
@@ -75,13 +73,14 @@ public static class AlbumEntityMapping
|
||||
Result<AlbumMetadata> metadataResult = AlbumMetadata.Create(
|
||||
repositoryEntity.Title,
|
||||
Optional<string>.FromNullable(repositoryEntity.OriginalTitle),
|
||||
Optional<string>.FromNullable(repositoryEntity.ReleaseTitle),
|
||||
Optional<string>.FromNullable(repositoryEntity.Description),
|
||||
releaseInfoResult.Value,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<MusicReleaseType>.FromNullable(repositoryEntity.ReleaseType),
|
||||
[.. repositoryEntity.ReleaseTypes.Select(releaseType => releaseType.ReleaseType)],
|
||||
Optional<MusicReleaseStatus>.FromNullable(repositoryEntity.ReleaseStatus),
|
||||
Optional<int>.FromNullable(repositoryEntity.TotalDiscs),
|
||||
repositoryEntity.TotalTracks);
|
||||
@@ -108,7 +107,7 @@ public static class AlbumEntityMapping
|
||||
musicBrainzReleaseArtistId = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseArtistId.Value);
|
||||
|
||||
List<AudioRating> domainRatings = [];
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainEntities())
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainValueObjects())
|
||||
{
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
@@ -136,9 +135,14 @@ public static class AlbumEntityMapping
|
||||
return Album.Create(
|
||||
AlbumId.Create(repositoryEntity.Id),
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(repositoryEntity.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(repositoryEntity.Packaging),
|
||||
Optional<string>.FromNullable(repositoryEntity.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(repositoryEntity.CatalogNumber),
|
||||
[.. repositoryEntity.CatalogNumbers.Select(catalogNumber => catalogNumber.CatalogNumber)],
|
||||
Optional<string>.FromNullable(repositoryEntity.Label),
|
||||
Optional<string>.FromNullable(repositoryEntity.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
@@ -181,19 +185,22 @@ public static class AlbumEntityMapping
|
||||
repositoryEntity.OriginalLanguageName,
|
||||
repositoryEntity.OriginalLanguageNativeName
|
||||
) : null;
|
||||
AlbumMetadataDto metadata = new(
|
||||
MusicAlbumMetadataDto metadata = new(
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.OriginalTitle,
|
||||
repositoryEntity.Description,
|
||||
repositoryEntity.Disambiguation,
|
||||
releaseInfo,
|
||||
languageInfo,
|
||||
originalLanguageInfo,
|
||||
[.. repositoryEntity.Tags.ToResponses()],
|
||||
[.. repositoryEntity.Genres.ToResponses()],
|
||||
repositoryEntity.ReleaseType,
|
||||
repositoryEntity.Script,
|
||||
[.. repositoryEntity.ReleaseTypes.Select(releaseType => releaseType.ReleaseType)],
|
||||
repositoryEntity.ReleaseStatus,
|
||||
repositoryEntity.TotalDiscs,
|
||||
repositoryEntity.TotalTracks
|
||||
repositoryEntity.TotalTracks,
|
||||
repositoryEntity.ReleaseTitle
|
||||
);
|
||||
return new AlbumResponse(
|
||||
repositoryEntity.Id,
|
||||
@@ -201,8 +208,11 @@ public static class AlbumEntityMapping
|
||||
repositoryEntity.LibraryId,
|
||||
metadata,
|
||||
repositoryEntity.MediaFormat,
|
||||
repositoryEntity.Packaging,
|
||||
repositoryEntity.Barcode,
|
||||
repositoryEntity.CatalogNumber,
|
||||
repositoryEntity.CatalogNumbers.Count > 0 ? [.. repositoryEntity.CatalogNumbers.Select(catalogNumber => catalogNumber.CatalogNumber)] : null,
|
||||
repositoryEntity.Label,
|
||||
repositoryEntity.ASIN,
|
||||
repositoryEntity.MusicBrainzReleaseId,
|
||||
repositoryEntity.MusicBrainzReleaseGroupId,
|
||||
repositoryEntity.MusicBrainzReleaseArtistId,
|
||||
|
||||
+8
-2
@@ -33,7 +33,9 @@ public static class AlbumMapping
|
||||
LibraryId = libraryId,
|
||||
Title = domainEntity.Metadata.Title,
|
||||
OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null,
|
||||
ReleaseTitle = domainEntity.Metadata.ReleaseTitle.HasValue ? domainEntity.Metadata.ReleaseTitle.Value : null,
|
||||
Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null,
|
||||
Disambiguation = domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.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,
|
||||
@@ -46,15 +48,19 @@ public static class AlbumMapping
|
||||
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.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.NativeName.Value : null,
|
||||
Script = domainEntity.Script.HasValue ? domainEntity.Script.Value : null,
|
||||
Genres = [.. domainEntity.Metadata.Genres.ToRepositoryEntities()],
|
||||
Tags = [.. domainEntity.Metadata.Tags.ToRepositoryEntities()],
|
||||
ReleaseType = domainEntity.Metadata.ReleaseType.HasValue ? domainEntity.Metadata.ReleaseType.Value : null,
|
||||
ReleaseTypes = [.. domainEntity.Metadata.ReleaseTypes.Select(releaseType => new AlbumReleaseTypeEntity(releaseType))],
|
||||
ReleaseStatus = domainEntity.Metadata.ReleaseStatus.HasValue ? domainEntity.Metadata.ReleaseStatus.Value : null,
|
||||
TotalDiscs = domainEntity.Metadata.TotalDiscs.HasValue ? domainEntity.Metadata.TotalDiscs.Value : null,
|
||||
TotalTracks = domainEntity.Metadata.TotalTracks,
|
||||
MediaFormat = domainEntity.MediaFormat.HasValue ? domainEntity.MediaFormat.Value : null,
|
||||
Packaging = domainEntity.Packaging.HasValue ? domainEntity.Packaging.Value : null,
|
||||
Barcode = domainEntity.Barcode.HasValue ? domainEntity.Barcode.Value.Value : null,
|
||||
CatalogNumber = domainEntity.CatalogNumber.HasValue ? domainEntity.CatalogNumber.Value : null,
|
||||
CatalogNumbers = [.. domainEntity.CatalogNumbers.Select(catalogNumber => new AlbumCatalogNumberEntity(catalogNumber))],
|
||||
Label = domainEntity.Label.HasValue ? domainEntity.Label.Value : null,
|
||||
ASIN = domainEntity.ASIN.HasValue ? domainEntity.ASIN.Value : null,
|
||||
MusicBrainzReleaseId = domainEntity.MusicBrainzReleaseId.HasValue ? domainEntity.MusicBrainzReleaseId.Value.Value : null,
|
||||
MusicBrainzReleaseGroupId = domainEntity.MusicBrainzReleaseGroupId.HasValue ? domainEntity.MusicBrainzReleaseGroupId.Value.Value : null,
|
||||
MusicBrainzReleaseArtistId = domainEntity.MusicBrainzReleaseArtistId.HasValue ? domainEntity.MusicBrainzReleaseArtistId.Value.Value : null,
|
||||
|
||||
+106
-16
@@ -1,9 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
@@ -18,42 +23,126 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibra
|
||||
/// </summary>
|
||||
public static class AlbumMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies the metadata of <paramref name="dto"/> to <paramref name="album"/>, through the owning <paramref name="artist"/> aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="dto">The album metadata to apply.</param>
|
||||
/// <param name="artist">The artist aggregate that owns the album.</param>
|
||||
/// <param name="album">The album entity to update.</param>
|
||||
/// <param name="contributors">The media contributors of the album, already resolved to their persisted identifiers.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Updated> ApplyTo(this AlbumMetadataDto dto, Artist artist, Album album, IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
Result<AlbumMetadata> metadataResult = dto.ToDomainValueObject(album.Metadata.ReleaseInfo);
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
List<AudioRating> ratings = [];
|
||||
foreach (AudioRatingDto rating in dto.Ratings ?? [])
|
||||
{
|
||||
Result<AudioRating> ratingResult = rating.ToDomainValueObject();
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
ratings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
Optional<Barcode> barcode = Optional<Barcode>.None();
|
||||
if (!string.IsNullOrWhiteSpace(dto.Barcode))
|
||||
{
|
||||
Result<Barcode> barcodeResult = Barcode.Create(dto.Barcode);
|
||||
if (barcodeResult.IsFailure)
|
||||
return barcodeResult.Errors;
|
||||
barcode = barcodeResult.Value;
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzReleaseId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzReleaseId is not null)
|
||||
musicBrainzReleaseId = MusicBrainzId.Create(dto.MusicBrainzReleaseId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzReleaseGroupId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzReleaseGroupId is not null)
|
||||
musicBrainzReleaseGroupId = MusicBrainzId.Create(dto.MusicBrainzReleaseGroupId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzReleaseArtistId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzReleaseArtistId is not null)
|
||||
musicBrainzReleaseArtistId = MusicBrainzId.Create(dto.MusicBrainzReleaseArtistId.Value);
|
||||
|
||||
return artist.UpdateAlbum(
|
||||
album,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(dto.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(dto.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(dto.Packaging),
|
||||
Optional<string>.FromNullable(dto.Script),
|
||||
barcode,
|
||||
dto.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(dto.Label),
|
||||
Optional<string>.FromNullable(dto.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AlbumMetadata"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <param name="existingReleaseInfo">The release information already stored for the album, used as a fallback for the fields the metadata does not provide.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AlbumMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AlbumMetadata> ToDomainEntity(this AlbumMetadataDto dto)
|
||||
private static Result<AlbumMetadata> ToDomainValueObject(this AlbumMetadataDto dto, ReleaseInfo existingReleaseInfo)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
|
||||
// The enrichment must not erase a release date that the tags already provided, so a date that the metadata does not carry falls back to the stored one.
|
||||
DateOnly? originalReleaseDate = releaseInfoDto?.OriginalReleaseDate;
|
||||
int? originalReleaseYear = releaseInfoDto?.OriginalReleaseYear;
|
||||
if (originalReleaseDate is null && originalReleaseYear is null)
|
||||
{
|
||||
originalReleaseDate = existingReleaseInfo.OriginalReleaseDate.HasValue ? existingReleaseInfo.OriginalReleaseDate.Value : null;
|
||||
originalReleaseYear = existingReleaseInfo.OriginalReleaseYear.HasValue ? existingReleaseInfo.OriginalReleaseYear.Value : null;
|
||||
}
|
||||
|
||||
DateOnly? reReleaseDate = releaseInfoDto?.ReReleaseDate;
|
||||
int? reReleaseYear = releaseInfoDto?.ReReleaseYear;
|
||||
if (reReleaseDate is null && reReleaseYear is null)
|
||||
{
|
||||
reReleaseDate = existingReleaseInfo.ReReleaseDate.HasValue ? existingReleaseInfo.ReReleaseDate.Value : null;
|
||||
reReleaseYear = existingReleaseInfo.ReReleaseYear.HasValue ? existingReleaseInfo.ReReleaseYear.Value : null;
|
||||
}
|
||||
|
||||
ReleaseCountry? releaseCountry = releaseInfoDto?.ReleaseCountry ?? (existingReleaseInfo.ReleaseCountry.HasValue ? existingReleaseInfo.ReleaseCountry.Value : null);
|
||||
string? releaseVersion = releaseInfoDto?.ReleaseVersion ?? (existingReleaseInfo.ReleaseVersion.HasValue ? existingReleaseInfo.ReleaseVersion.Value : null);
|
||||
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
Optional<DateOnly>.FromNullable(originalReleaseDate),
|
||||
Optional<int>.FromNullable(originalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(reReleaseDate),
|
||||
Optional<int>.FromNullable(reReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseCountry),
|
||||
Optional<string>.FromNullable(releaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
List<Genre> genres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainEntity();
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
genres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
List<Tag> tags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainEntity();
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
tags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
@@ -67,13 +156,14 @@ public static class AlbumMetadataDtoMapping
|
||||
return AlbumMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
Optional<string>.FromNullable(dto.ReleaseTitle),
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
releaseInfoResult.Value,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
genres,
|
||||
tags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<MusicReleaseType>.FromNullable(dto.ReleaseType),
|
||||
dto.ReleaseTypes is null ? [] : [.. dto.ReleaseTypes],
|
||||
Optional<MusicReleaseStatus>.FromNullable(dto.ReleaseStatus),
|
||||
Optional<int>.FromNullable(dto.TotalDiscs),
|
||||
dto.TotalTracks ?? 0);
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicAlbumMetadataDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicAlbumMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AlbumMetadata"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AlbumMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AlbumMetadata> ToDomainValueObject(this MusicAlbumMetadataDto dto)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
if (dto.Language is not null && dto.Language.LanguageCode is not null && dto.Language.LanguageName is not null)
|
||||
language = LanguageInfo.Create(dto.Language.LanguageCode, dto.Language.LanguageName, Optional<string>.FromNullable(dto.Language.NativeName));
|
||||
|
||||
Optional<LanguageInfo> originalLanguage = Optional<LanguageInfo>.None();
|
||||
if (dto.OriginalLanguage is not null && dto.OriginalLanguage.LanguageCode is not null && dto.OriginalLanguage.LanguageName is not null)
|
||||
originalLanguage = LanguageInfo.Create(dto.OriginalLanguage.LanguageCode, dto.OriginalLanguage.LanguageName, Optional<string>.FromNullable(dto.OriginalLanguage.NativeName));
|
||||
|
||||
return AlbumMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
Optional<string>.FromNullable(dto.ReleaseTitle),
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
releaseInfoResult.Value,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
language,
|
||||
originalLanguage,
|
||||
dto.ReleaseTypes is null ? [] : [.. dto.ReleaseTypes],
|
||||
Optional<MusicReleaseStatus>.FromNullable(dto.ReleaseStatus),
|
||||
Optional<int>.FromNullable(dto.TotalDiscs),
|
||||
dto.TotalTracks ?? 0);
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.UpdateAlbum;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
@@ -31,16 +32,17 @@ public static class UpdateAlbumCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this UpdateAlbumCommand command, Artist artist)
|
||||
{
|
||||
Result<AlbumMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicAlbumMetadataDto metadata = command.Metadata!;
|
||||
Result<AlbumMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -72,9 +74,14 @@ public static class UpdateAlbumCommandMapping
|
||||
Result<Updated> updateResult = artist.UpdateAlbum(
|
||||
album,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
Optional<MusicReleasePackaging>.FromNullable(command.Packaging),
|
||||
Optional<string>.FromNullable(metadata.Script),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(command.CatalogNumber),
|
||||
command.CatalogNumbers ?? [],
|
||||
Optional<string>.FromNullable(command.Label),
|
||||
Optional<string>.FromNullable(command.ASIN),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
|
||||
+4
-1
@@ -26,8 +26,11 @@ public static class UpdateAlbumRequestMapping
|
||||
albumId,
|
||||
request.Metadata,
|
||||
request.MediaFormat,
|
||||
request.Packaging,
|
||||
request.Barcode,
|
||||
request.CatalogNumber,
|
||||
request.CatalogNumbers,
|
||||
request.Label,
|
||||
request.ASIN,
|
||||
request.MusicBrainzReleaseId,
|
||||
request.MusicBrainzReleaseGroupId,
|
||||
request.MusicBrainzReleaseArtistId,
|
||||
|
||||
+57
-4
@@ -1,12 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.AddArtist;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -29,8 +35,10 @@ public static class AddArtistCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this AddArtistCommand command, Guid libraryId)
|
||||
{
|
||||
MusicArtistMetadataDto metadata = command.Metadata!;
|
||||
|
||||
// Map the media contributors referenced by the user to their domain counterparts; a contributor is identified by its id and carries the role it played.
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -41,16 +49,61 @@ public static class AddArtistCommandMapping
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<string> website = Optional<string>.FromNullable(command.Website);
|
||||
IEnumerable<Result<Genre>> domainGenresResult = (metadata.Genres ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Tag>> domainTagsResult = (metadata.Tags ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<Optional<MusicArea>> areaResult = metadata.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
Result<Optional<MusicArea>> beginAreaResult = metadata.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
Result<Optional<MusicArea>> endAreaResult = metadata.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
|
||||
Result<List<MusicArtistAlias>> aliasesResult = metadata.Aliases.ToDomainValueObjects();
|
||||
if (aliasesResult.IsFailure)
|
||||
return aliasesResult.Errors;
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
|
||||
return Artist.Create(
|
||||
LibraryId.Create(libraryId),
|
||||
command.Name!,
|
||||
website,
|
||||
metadata.Name!,
|
||||
Optional<string>.FromNullable(metadata.SortName),
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(metadata.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(metadata.Gender),
|
||||
Optional<string>.FromNullable(metadata.Country),
|
||||
areaResult.Value,
|
||||
beginAreaResult.Value,
|
||||
endAreaResult.Value,
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanEnd),
|
||||
metadata.IsEnded,
|
||||
Optional<string>.FromNullable(command.Website),
|
||||
musicBrainzArtistId,
|
||||
[.. (command.Ipis ?? [])],
|
||||
[.. (command.Isnis ?? [])],
|
||||
aliasesResult.Value,
|
||||
[.. domainGenresResult.Select(genreResult => genreResult.Value)],
|
||||
[.. domainTagsResult.Select(tagResult => tagResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)],
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainAlbumsResult.Select(albumResult => albumResult.Value)]);
|
||||
}
|
||||
|
||||
+4
-1
@@ -22,10 +22,13 @@ public static class AddArtistRequestMapping
|
||||
{
|
||||
return new AddArtistCommand(
|
||||
libraryId,
|
||||
request.Name,
|
||||
request.Metadata,
|
||||
request.Website,
|
||||
request.MusicBrainzArtistId,
|
||||
request.Ipis,
|
||||
request.Isnis,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.Albums?.ToCommands(libraryId, null).ToList());
|
||||
}
|
||||
}
|
||||
+100
-4
@@ -1,16 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -36,6 +42,60 @@ public static class ArtistEntityMapping
|
||||
if (repositoryEntity.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(repositoryEntity.MusicBrainzArtistId.Value);
|
||||
|
||||
Optional<MusicArea> area = Optional<MusicArea>.None();
|
||||
if (repositoryEntity.Area is not null)
|
||||
{
|
||||
Result<MusicArea> areaResult = repositoryEntity.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
area = areaResult.Value;
|
||||
}
|
||||
Optional<MusicArea> beginArea = Optional<MusicArea>.None();
|
||||
if (repositoryEntity.BeginArea is not null)
|
||||
{
|
||||
Result<MusicArea> beginAreaResult = repositoryEntity.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
beginArea = beginAreaResult.Value;
|
||||
}
|
||||
Optional<MusicArea> endArea = Optional<MusicArea>.None();
|
||||
if (repositoryEntity.EndArea is not null)
|
||||
{
|
||||
Result<MusicArea> endAreaResult = repositoryEntity.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
endArea = endAreaResult.Value;
|
||||
}
|
||||
|
||||
Result<List<MusicArtistAlias>> domainAliasesResult = repositoryEntity.Aliases.ToDomainValueObjects();
|
||||
if (domainAliasesResult.IsFailure)
|
||||
return domainAliasesResult.Errors;
|
||||
List<MusicArtistAlias> domainAliases = domainAliasesResult.Value;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainValueObjects())
|
||||
{
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainValueObjects())
|
||||
{
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
List<AudioRating> domainRatings = [];
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainValueObjects())
|
||||
{
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
domainRatings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
List<MusicMediaContributor> domainContributors = [];
|
||||
foreach (ArtistContributorEntity contributorEntity in repositoryEntity.Contributors)
|
||||
{
|
||||
@@ -58,8 +118,25 @@ public static class ArtistEntityMapping
|
||||
ArtistId.Create(repositoryEntity.Id),
|
||||
LibraryId.Create(repositoryEntity.LibraryId),
|
||||
repositoryEntity.Name,
|
||||
Optional<string>.FromNullable(repositoryEntity.SortName),
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(repositoryEntity.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(repositoryEntity.Gender),
|
||||
Optional<string>.FromNullable(repositoryEntity.Country),
|
||||
area,
|
||||
beginArea,
|
||||
endArea,
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.LifeSpanEnd),
|
||||
repositoryEntity.IsEnded,
|
||||
Optional<string>.FromNullable(repositoryEntity.Website),
|
||||
musicBrainzArtistId,
|
||||
[.. repositoryEntity.Ipis.Select(ipi => ipi.Value)],
|
||||
[.. repositoryEntity.Isnis.Select(isni => isni.Value)],
|
||||
domainAliases,
|
||||
domainGenres,
|
||||
domainTags,
|
||||
domainRatings,
|
||||
domainContributors,
|
||||
domainAlbums,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
@@ -73,16 +150,35 @@ public static class ArtistEntityMapping
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static ArtistResponse ToResponse(this ArtistEntity repositoryEntity)
|
||||
{
|
||||
MusicArtistMetadataDto metadata = new(
|
||||
repositoryEntity.Name,
|
||||
repositoryEntity.SortName,
|
||||
repositoryEntity.Disambiguation,
|
||||
repositoryEntity.Type,
|
||||
repositoryEntity.Gender,
|
||||
repositoryEntity.Country,
|
||||
repositoryEntity.Area.ToResponse(),
|
||||
repositoryEntity.BeginArea.ToResponse(),
|
||||
repositoryEntity.EndArea.ToResponse(),
|
||||
repositoryEntity.LifeSpanBegin,
|
||||
repositoryEntity.LifeSpanEnd,
|
||||
repositoryEntity.IsEnded,
|
||||
[.. repositoryEntity.Genres.ToResponses()],
|
||||
[.. repositoryEntity.Tags.ToResponses()],
|
||||
[.. repositoryEntity.Aliases.Select(alias => new MusicArtistAliasDto(alias.Name, alias.SortName, alias.Type, alias.Locale, alias.IsPrimary, alias.BeginDate, alias.EndDate, alias.IsEnded))]);
|
||||
return new ArtistResponse(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.Name,
|
||||
metadata,
|
||||
repositoryEntity.Website,
|
||||
repositoryEntity.MusicBrainzArtistId,
|
||||
[.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))],
|
||||
[.. repositoryEntity.Albums.Select(album => album.ToResponse())],
|
||||
[.. repositoryEntity.Ipis.Select(ipi => ipi.Value)],
|
||||
[.. repositoryEntity.Isnis.Select(isni => isni.Value)],
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
repositoryEntity.UpdatedOnUtc);
|
||||
repositoryEntity.UpdatedOnUtc,
|
||||
[.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))],
|
||||
[.. repositoryEntity.Ratings.ToResponses()],
|
||||
[.. repositoryEntity.Albums.Select(album => album.ToResponse())]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+19
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -25,8 +27,25 @@ public static class ArtistMapping
|
||||
Id = domainEntity.Id.Value,
|
||||
LibraryId = domainEntity.LibraryId.Value,
|
||||
Name = domainEntity.Name,
|
||||
SortName = domainEntity.SortName.HasValue ? domainEntity.SortName.Value : null,
|
||||
Disambiguation = domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.Value : null,
|
||||
Type = domainEntity.Type.HasValue ? domainEntity.Type.Value : null,
|
||||
Gender = domainEntity.Gender.HasValue ? domainEntity.Gender.Value : null,
|
||||
Country = domainEntity.Country.HasValue ? domainEntity.Country.Value : null,
|
||||
LifeSpanBegin = domainEntity.LifeSpanBegin.HasValue ? domainEntity.LifeSpanBegin.Value : null,
|
||||
LifeSpanEnd = domainEntity.LifeSpanEnd.HasValue ? domainEntity.LifeSpanEnd.Value : null,
|
||||
IsEnded = domainEntity.IsEnded,
|
||||
Website = domainEntity.Website.HasValue ? domainEntity.Website.Value : null,
|
||||
MusicBrainzArtistId = domainEntity.MusicBrainzArtistId.HasValue ? domainEntity.MusicBrainzArtistId.Value.Value : null,
|
||||
Area = domainEntity.Area.HasValue ? domainEntity.Area.Value.ToRepositoryEntity() : null,
|
||||
BeginArea = domainEntity.BeginArea.HasValue ? domainEntity.BeginArea.Value.ToRepositoryEntity() : null,
|
||||
EndArea = domainEntity.EndArea.HasValue ? domainEntity.EndArea.Value.ToRepositoryEntity() : null,
|
||||
Aliases = [.. domainEntity.Aliases.ToRepositoryEntities()],
|
||||
Ipis = [.. domainEntity.Ipis.Select(ipi => new ArtistIpiEntity(ipi))],
|
||||
Isnis = [.. domainEntity.Isnis.Select(isni => new ArtistIsniEntity(isni))],
|
||||
Genres = [.. domainEntity.Genres.ToRepositoryEntities()],
|
||||
Tags = [.. domainEntity.Tags.ToRepositoryEntities()],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new ArtistContributorEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ArtistMetadataDto"/>.
|
||||
/// </summary>
|
||||
public static class ArtistMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies the metadata of <paramref name="dto"/> to <paramref name="artist"/>, through the aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="dto">The artist metadata to apply.</param>
|
||||
/// <param name="artist">The artist aggregate the metadata is applied to.</param>
|
||||
/// <param name="contributors">The media contributors that make up the artist, already resolved to their persisted identifiers.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Updated> ApplyTo(this ArtistMetadataDto dto, Artist artist, IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
Result<Optional<MusicArea>> areaResult = dto.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
Result<Optional<MusicArea>> beginAreaResult = dto.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
Result<Optional<MusicArea>> endAreaResult = dto.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
Result<List<MusicArtistAlias>> aliasesResult = dto.Aliases.ToDomainValueObjects();
|
||||
if (aliasesResult.IsFailure)
|
||||
return aliasesResult.Errors;
|
||||
|
||||
List<Genre> genres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
genres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> tags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
tags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
List<AudioRating> ratings = [];
|
||||
foreach (AudioRatingDto rating in dto.Ratings ?? [])
|
||||
{
|
||||
Result<AudioRating> ratingResult = rating.ToDomainValueObject();
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
ratings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(dto.MusicBrainzArtistId.Value);
|
||||
|
||||
// The website is only replaced when the provider returned one, so a locally captured website is never cleared.
|
||||
Optional<string> website = string.IsNullOrWhiteSpace(dto.Website) ? artist.Website : Optional<string>.FromNullable(dto.Website);
|
||||
Result<Updated> updateDetailsResult = artist.UpdateDetails(
|
||||
string.IsNullOrWhiteSpace(dto.Name) ? artist.Name : dto.Name,
|
||||
Optional<string>.FromNullable(dto.SortName),
|
||||
Optional<string>.FromNullable(dto.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(dto.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(dto.Gender),
|
||||
Optional<string>.FromNullable(dto.Country),
|
||||
areaResult.Value,
|
||||
beginAreaResult.Value,
|
||||
endAreaResult.Value,
|
||||
Optional<DateOnly>.FromNullable(dto.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(dto.LifeSpanEnd),
|
||||
dto.IsEnded,
|
||||
website,
|
||||
musicBrainzArtistId);
|
||||
if (updateDetailsResult.IsFailure)
|
||||
return updateDetailsResult.Errors;
|
||||
|
||||
artist.UpdateAliases(aliasesResult.Value);
|
||||
artist.UpdateIpis([.. dto.Ipis ?? []]);
|
||||
artist.UpdateIsnis([.. dto.Isnis ?? []]);
|
||||
artist.UpdateGenres(genres);
|
||||
artist.UpdateTags(tags);
|
||||
artist.UpdateRatings(ratings);
|
||||
artist.UpdateContributors(contributors);
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -26,8 +26,11 @@ public static class UpdateArtistAlbumRequestMapping
|
||||
artistId,
|
||||
request.Metadata,
|
||||
request.MediaFormat,
|
||||
request.Packaging,
|
||||
request.Barcode,
|
||||
request.CatalogNumber,
|
||||
request.CatalogNumbers,
|
||||
request.Label,
|
||||
request.ASIN,
|
||||
request.MusicBrainzReleaseId,
|
||||
request.MusicBrainzReleaseGroupId,
|
||||
request.MusicBrainzReleaseArtistId,
|
||||
|
||||
+68
-6
@@ -1,11 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.UpdateArtist;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -28,8 +34,10 @@ public static class UpdateArtistCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this UpdateArtistCommand command, Artist artist)
|
||||
{
|
||||
MusicArtistMetadataDto metadata = command.Metadata!;
|
||||
|
||||
// Map the media contributors that make up the artist to their domain counterparts.
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -40,15 +48,64 @@ public static class UpdateArtistCommandMapping
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<string> website = Optional<string>.FromNullable(command.Website);
|
||||
IEnumerable<Result<Genre>> domainGenresResult = (metadata.Genres ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Tag>> domainTagsResult = (metadata.Tags ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<Optional<MusicArea>> areaResult = metadata.Area.ToDomainValueObject();
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
Result<Optional<MusicArea>> beginAreaResult = metadata.BeginArea.ToDomainValueObject();
|
||||
if (beginAreaResult.IsFailure)
|
||||
return beginAreaResult.Errors;
|
||||
Result<Optional<MusicArea>> endAreaResult = metadata.EndArea.ToDomainValueObject();
|
||||
if (endAreaResult.IsFailure)
|
||||
return endAreaResult.Errors;
|
||||
|
||||
Result<List<MusicArtistAlias>> aliasesResult = metadata.Aliases.ToDomainValueObjects();
|
||||
if (aliasesResult.IsFailure)
|
||||
return aliasesResult.Errors;
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
|
||||
// The details and the media contributors of the artist are replaced in place, preserving its identity and creation metadata.
|
||||
Result<Updated> updateDetailsResult = artist.UpdateDetails(command.Name!, website, musicBrainzArtistId);
|
||||
// The details and the media library collections of the artist are replaced in place, preserving its identity and creation metadata.
|
||||
Result<Updated> updateDetailsResult = artist.UpdateDetails(
|
||||
metadata.Name!,
|
||||
Optional<string>.FromNullable(metadata.SortName),
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
Optional<MusicArtistType>.FromNullable(metadata.Type),
|
||||
Optional<MusicArtistGender>.FromNullable(metadata.Gender),
|
||||
Optional<string>.FromNullable(metadata.Country),
|
||||
areaResult.Value,
|
||||
beginAreaResult.Value,
|
||||
endAreaResult.Value,
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanBegin),
|
||||
Optional<DateOnly>.FromNullable(metadata.LifeSpanEnd),
|
||||
metadata.IsEnded,
|
||||
Optional<string>.FromNullable(command.Website),
|
||||
musicBrainzArtistId);
|
||||
if (updateDetailsResult.IsFailure)
|
||||
return updateDetailsResult.Errors;
|
||||
|
||||
artist.UpdateAliases(aliasesResult.Value);
|
||||
artist.UpdateIpis([.. (command.Ipis ?? [])]);
|
||||
artist.UpdateIsnis([.. (command.Isnis ?? [])]);
|
||||
artist.UpdateGenres([.. domainGenresResult.Select(genreResult => genreResult.Value)]);
|
||||
artist.UpdateTags([.. domainTagsResult.Select(tagResult => tagResult.Value)]);
|
||||
artist.UpdateRatings([.. domainRatingsResult.Select(ratingResult => ratingResult.Value)]);
|
||||
artist.UpdateContributors([.. domainContributorsResult.Select(contributorResult => contributorResult.Value)]);
|
||||
|
||||
List<Album> domainAlbums = [.. domainAlbumsResult.Select(albumResult => albumResult.Value)];
|
||||
@@ -70,9 +127,14 @@ public static class UpdateArtistCommandMapping
|
||||
Result<Updated> updateAlbumResult = artist.UpdateAlbum(
|
||||
existingAlbum,
|
||||
domainAlbum.Metadata,
|
||||
domainAlbum.Disambiguation,
|
||||
domainAlbum.MediaFormat,
|
||||
domainAlbum.Packaging,
|
||||
domainAlbum.Script,
|
||||
domainAlbum.Barcode,
|
||||
domainAlbum.CatalogNumber,
|
||||
[.. domainAlbum.CatalogNumbers],
|
||||
domainAlbum.Label,
|
||||
domainAlbum.ASIN,
|
||||
domainAlbum.MusicBrainzReleaseId,
|
||||
domainAlbum.MusicBrainzReleaseGroupId,
|
||||
domainAlbum.MusicBrainzReleaseArtistId,
|
||||
@@ -103,10 +165,10 @@ public static class UpdateArtistCommandMapping
|
||||
domainTrack.Script,
|
||||
domainTrack.Key,
|
||||
domainTrack.Bpm,
|
||||
domainTrack.IsVideo,
|
||||
domainTrack.Work,
|
||||
domainTrack.MusicBrainzRecordingId,
|
||||
domainTrack.MusicBrainzTrackId,
|
||||
domainTrack.MusicBrainzWorkId,
|
||||
domainTrack.Moods,
|
||||
domainTrack.Isrcs,
|
||||
domainTrack.Contributors,
|
||||
|
||||
+4
-1
@@ -23,10 +23,13 @@ public static class UpdateArtistRequestMapping
|
||||
return new UpdateArtistCommand(
|
||||
libraryId,
|
||||
artistId,
|
||||
request.Name,
|
||||
request.Metadata,
|
||||
request.Website,
|
||||
request.MusicBrainzArtistId,
|
||||
request.Ipis,
|
||||
request.Isnis,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.Albums?.ToCommands(libraryId, artistId).ToList());
|
||||
}
|
||||
}
|
||||
-1
@@ -36,7 +36,6 @@ public static class UpdateArtistTrackRequestMapping
|
||||
request.Work,
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Moods,
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ArtistAliasEntity"/>.
|
||||
/// </summary>
|
||||
public static class ArtistAliasEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MusicArtistAlias"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArtistAlias> ToDomainValueObject(this ArtistAliasEntity repositoryEntity)
|
||||
{
|
||||
return MusicArtistAlias.Create(
|
||||
repositoryEntity.Name,
|
||||
Optional<string>.FromNullable(repositoryEntity.SortName),
|
||||
Optional<string>.FromNullable(repositoryEntity.Type),
|
||||
Optional<string>.FromNullable(repositoryEntity.Locale),
|
||||
repositoryEntity.IsPrimary,
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.BeginDate),
|
||||
Optional<DateOnly>.FromNullable(repositoryEntity.EndDate),
|
||||
repositoryEntity.IsEnded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted aliases, or an error message.
|
||||
/// </returns>
|
||||
public static Result<List<MusicArtistAlias>> ToDomainValueObjects(this IEnumerable<ArtistAliasEntity> repositoryEntities)
|
||||
{
|
||||
List<MusicArtistAlias> aliases = [];
|
||||
foreach (ArtistAliasEntity repositoryEntity in repositoryEntities)
|
||||
{
|
||||
Result<MusicArtistAlias> aliasResult = repositoryEntity.ToDomainValueObject();
|
||||
if (aliasResult.IsFailure)
|
||||
return aliasResult.Errors;
|
||||
aliases.Add(aliasResult.Value);
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -21,7 +21,7 @@ public static class AudioRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioRating> ToDomainEntity(this AudioRatingDto dto)
|
||||
public static Result<AudioRating> ToDomainValueObject(this AudioRatingDto dto)
|
||||
{
|
||||
return AudioRating.Create(
|
||||
dto.Value ?? default,
|
||||
@@ -38,8 +38,8 @@ public static class AudioRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainEntities(this IEnumerable<AudioRatingDto> dtos)
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainValueObjects(this IEnumerable<AudioRatingDto> dtos)
|
||||
{
|
||||
return dtos.Select(dto => dto.ToDomainEntity());
|
||||
return dtos.Select(dto => dto.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -47,7 +47,7 @@ public static class AudioRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioRating> ToDomainEntity(this AudioRatingEntity repositoryEntity)
|
||||
public static Result<AudioRating> ToDomainValueObject(this AudioRatingEntity repositoryEntity)
|
||||
{
|
||||
return AudioRating.Create(
|
||||
repositoryEntity.Value ?? default,
|
||||
@@ -64,8 +64,8 @@ public static class AudioRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="AudioRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainEntities(this IEnumerable<AudioRatingEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<AudioRating>> ToDomainValueObjects(this IEnumerable<AudioRatingEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -20,7 +20,7 @@ public static class IsrcDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isrc> ToDomainEntity(this IsrcDto dto)
|
||||
public static Result<Isrc> ToDomainValueObject(this IsrcDto dto)
|
||||
{
|
||||
return Isrc.Create(dto.Value!);
|
||||
}
|
||||
@@ -32,8 +32,8 @@ public static class IsrcDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isrc>> ToDomainEntities(this IEnumerable<IsrcDto> dtos)
|
||||
public static IEnumerable<Result<Isrc>> ToDomainValueObjects(this IEnumerable<IsrcDto> dtos)
|
||||
{
|
||||
return dtos.Select(dto => dto.ToDomainEntity());
|
||||
return dtos.Select(dto => dto.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -43,7 +43,7 @@ public static class IsrcEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isrc> ToDomainEntity(this TrackIsrcEntity repositoryEntity)
|
||||
public static Result<Isrc> ToDomainValueObject(this TrackIsrcEntity repositoryEntity)
|
||||
{
|
||||
return Isrc.Create(repositoryEntity.Value!);
|
||||
}
|
||||
@@ -55,8 +55,8 @@ public static class IsrcEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isrc>> ToDomainEntities(this IEnumerable<TrackIsrcEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Isrc>> ToDomainValueObjects(this IEnumerable<TrackIsrcEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -20,7 +20,7 @@ public static class MoodDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Mood> ToDomainEntity(this MoodDto dto)
|
||||
public static Result<Mood> ToDomainValueObject(this MoodDto dto)
|
||||
{
|
||||
return Mood.Create(dto.Name!);
|
||||
}
|
||||
@@ -32,8 +32,8 @@ public static class MoodDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Mood>> ToDomainEntities(this IEnumerable<MoodDto> dtos)
|
||||
public static IEnumerable<Result<Mood>> ToDomainValueObjects(this IEnumerable<MoodDto> dtos)
|
||||
{
|
||||
return dtos.Select(dto => dto.ToDomainEntity());
|
||||
return dtos.Select(dto => dto.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -43,7 +43,7 @@ public static class MoodEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Mood> ToDomainEntity(this TrackMoodEntity repositoryEntity)
|
||||
public static Result<Mood> ToDomainValueObject(this TrackMoodEntity repositoryEntity)
|
||||
{
|
||||
return Mood.Create(repositoryEntity.Name!);
|
||||
}
|
||||
@@ -55,8 +55,8 @@ public static class MoodEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Mood"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Mood>> ToDomainEntities(this IEnumerable<TrackMoodEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Mood>> ToDomainValueObjects(this IEnumerable<TrackMoodEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicAreaDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicAreaDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="areaDto"/> to a domain <see cref="MusicArea"/>, wrapped in an <see cref="Optional{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="areaDto">The area data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted optional area, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Optional<MusicArea>> ToDomainValueObject(this MusicAreaDto? areaDto)
|
||||
{
|
||||
if (areaDto is null || areaDto.MusicBrainzAreaId is null)
|
||||
return Optional<MusicArea>.None();
|
||||
|
||||
Result<MusicArea> areaResult = MusicArea.Create(
|
||||
MusicBrainzId.Create(areaDto.MusicBrainzAreaId.Value),
|
||||
areaDto.Name!,
|
||||
Optional<string>.FromNullable(areaDto.SortName),
|
||||
Optional<string>.FromNullable(areaDto.Disambiguation),
|
||||
Optional<string>.FromNullable(areaDto.Type),
|
||||
Optional<string>.FromNullable(areaDto.Iso3166Code));
|
||||
if (areaResult.IsFailure)
|
||||
return areaResult.Errors;
|
||||
return Optional<MusicArea>.Some(areaResult.Value);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicAreaEntity"/>.
|
||||
/// </summary>
|
||||
public static class MusicAreaEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MusicArea"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MusicArea"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArea> ToDomainValueObject(this MusicAreaEntity repositoryEntity)
|
||||
{
|
||||
return MusicArea.Create(
|
||||
MusicBrainzId.Create(repositoryEntity.MusicBrainzAreaId),
|
||||
repositoryEntity.Name,
|
||||
Optional<string>.FromNullable(repositoryEntity.SortName),
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
Optional<string>.FromNullable(repositoryEntity.Type),
|
||||
Optional<string>.FromNullable(repositoryEntity.Iso3166Code));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MusicAreaDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted data transfer object, or <see langword="null"/> when the repository entity is <see langword="null"/>.</returns>
|
||||
public static MusicAreaDto? ToResponse(this MusicAreaEntity? repositoryEntity)
|
||||
{
|
||||
return repositoryEntity is null
|
||||
? null
|
||||
: new MusicAreaDto(repositoryEntity.MusicBrainzAreaId, repositoryEntity.Name, repositoryEntity.SortName, repositoryEntity.Disambiguation, repositoryEntity.Type, repositoryEntity.Iso3166Code);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicArea"/>.
|
||||
/// </summary>
|
||||
public static class MusicAreaMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="MusicAreaEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static MusicAreaEntity ToRepositoryEntity(this MusicArea domainEntity)
|
||||
{
|
||||
return new MusicAreaEntity(
|
||||
domainEntity.MusicBrainzAreaId.Value,
|
||||
domainEntity.Name,
|
||||
domainEntity.SortName.HasValue ? domainEntity.SortName.Value : null,
|
||||
domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.Value : null,
|
||||
domainEntity.Type.HasValue ? domainEntity.Type.Value : null,
|
||||
domainEntity.Iso3166Code.HasValue ? domainEntity.Iso3166Code.Value : null);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicArtistAliasDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicArtistAliasDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="aliasDto"/> to a domain <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="aliasDto">The alias data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted alias, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicArtistAlias> ToDomainValueObject(this MusicArtistAliasDto aliasDto)
|
||||
{
|
||||
return MusicArtistAlias.Create(
|
||||
aliasDto.Name!,
|
||||
Optional<string>.FromNullable(aliasDto.SortName),
|
||||
Optional<string>.FromNullable(aliasDto.Type),
|
||||
Optional<string>.FromNullable(aliasDto.Locale),
|
||||
aliasDto.IsPrimary,
|
||||
Optional<DateOnly>.FromNullable(aliasDto.BeginDate),
|
||||
Optional<DateOnly>.FromNullable(aliasDto.EndDate),
|
||||
aliasDto.IsEnded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="aliasDtos"/> to a collection of domain <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
/// <param name="aliasDtos">The alias data transfer objects to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted aliases, or an error message.
|
||||
/// </returns>
|
||||
public static Result<List<MusicArtistAlias>> ToDomainValueObjects(this IEnumerable<MusicArtistAliasDto>? aliasDtos)
|
||||
{
|
||||
List<MusicArtistAlias> aliases = [];
|
||||
foreach (MusicArtistAliasDto aliasDto in aliasDtos ?? [])
|
||||
{
|
||||
Result<MusicArtistAlias> aliasResult = aliasDto.ToDomainValueObject();
|
||||
if (aliasResult.IsFailure)
|
||||
return aliasResult.Errors;
|
||||
aliases.Add(aliasResult.Value);
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicArtistAlias"/>.
|
||||
/// </summary>
|
||||
public static class MusicArtistAliasMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="ArtistAliasEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static ArtistAliasEntity ToRepositoryEntity(this MusicArtistAlias domainEntity)
|
||||
{
|
||||
return new ArtistAliasEntity(
|
||||
domainEntity.Name,
|
||||
domainEntity.SortName.HasValue ? domainEntity.SortName.Value : null,
|
||||
domainEntity.Type.HasValue ? domainEntity.Type.Value : null,
|
||||
domainEntity.Locale.HasValue ? domainEntity.Locale.Value : null,
|
||||
domainEntity.IsPrimary,
|
||||
domainEntity.BeginDate.HasValue ? domainEntity.BeginDate.Value : null,
|
||||
domainEntity.EndDate.HasValue ? domainEntity.EndDate.Value : null,
|
||||
domainEntity.IsEnded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="ArtistAliasEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntities">The domain entities to be converted.</param>
|
||||
/// <returns>The converted repository entities.</returns>
|
||||
public static List<ArtistAliasEntity> ToRepositoryEntities(this IEnumerable<MusicArtistAlias> domainEntities)
|
||||
{
|
||||
return [.. domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity())];
|
||||
}
|
||||
}
|
||||
+22
-12
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.AddTrack;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
@@ -29,39 +30,46 @@ public static class AddTrackCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Track> ToDomainEntity(this AddTrackCommand command)
|
||||
{
|
||||
Result<AudioMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicTrackMetadataDto metadata = command.Metadata!;
|
||||
Result<AudioMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<MusicWork> work = Optional<MusicWork>.None();
|
||||
if (command.Work is not null)
|
||||
{
|
||||
Result<MusicWork> workResult = command.Work.ToDomainValueObject();
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzRecordingId is not null)
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzWorkId is not null)
|
||||
musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
|
||||
List<Mood> moods = [.. domainMoodsResult.Select(moodResult => moodResult.Value)];
|
||||
List<Isrc> isrcs = [.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)];
|
||||
@@ -74,17 +82,18 @@ public static class AddTrackCommandMapping
|
||||
TrackId.Create(command.TrackId.Value),
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
command.TrackNumber!.Value,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
metadata.IsVideo,
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings,
|
||||
DateTime.UtcNow,
|
||||
@@ -93,17 +102,18 @@ public static class AddTrackCommandMapping
|
||||
return Track.Create(
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
command.TrackNumber!.Value,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
metadata.IsVideo,
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
-1
@@ -36,7 +36,6 @@ public static class AddTrackRequestMapping
|
||||
request.Work,
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Moods,
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
|
||||
+164
-35
@@ -1,10 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,65 +24,188 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibra
|
||||
public static class AudioMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AudioMetadata"/>.
|
||||
/// Applies the metadata of <paramref name="dto"/> to <paramref name="track"/>, through the owning <paramref name="artist"/> aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="dto">The audio metadata to apply.</param>
|
||||
/// <param name="artist">The artist aggregate that owns the album of the track.</param>
|
||||
/// <param name="album">The album the track belongs to.</param>
|
||||
/// <param name="track">The track entity to update.</param>
|
||||
/// <param name="contributors">The media contributors of the track, already resolved to their persisted identifiers.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Updated> ApplyTo(this AudioMetadataDto dto, Artist artist, Album album, Track track, IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
Result<AudioMetadata> metadataResult = dto.ToDomainValueObject(track);
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
List<AudioRating> ratings = [];
|
||||
foreach (AudioRatingDto rating in dto.Ratings ?? [])
|
||||
{
|
||||
Result<AudioRating> ratingResult = rating.ToDomainValueObject();
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
ratings.Add(ratingResult.Value);
|
||||
}
|
||||
|
||||
// The work, the moods and the ISRCs of the track are only replaced when the provider returned values, so locally extracted data is never cleared.
|
||||
Optional<MusicWork> work = track.Work;
|
||||
if (dto.Work is not null)
|
||||
{
|
||||
Result<MusicWork> workResult = dto.Work.ToDomainValueObject();
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
List<Mood> moods = [.. track.Moods];
|
||||
if (dto.Moods is { Count: > 0 })
|
||||
{
|
||||
moods = [];
|
||||
foreach (MoodDto mood in dto.Moods)
|
||||
{
|
||||
Result<Mood> moodResult = mood.ToDomainValueObject();
|
||||
if (moodResult.IsFailure)
|
||||
return moodResult.Errors;
|
||||
moods.Add(moodResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
List<Isrc> isrcs = [.. track.Isrcs];
|
||||
if (dto.Isrcs is { Count: > 0 })
|
||||
{
|
||||
isrcs = [];
|
||||
foreach (IsrcDto isrc in dto.Isrcs)
|
||||
{
|
||||
Result<Isrc> isrcResult = isrc.ToDomainValueObject();
|
||||
if (isrcResult.IsFailure)
|
||||
return isrcResult.Errors;
|
||||
isrcs.Add(isrcResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Optional<string> script = Optional<string>.FromNullable(dto.Script);
|
||||
if (!script.HasValue)
|
||||
script = track.Script;
|
||||
Optional<MusicKey> key = Optional<MusicKey>.FromNullable(dto.Key);
|
||||
if (!key.HasValue)
|
||||
key = track.Key;
|
||||
Optional<int> bpm = Optional<int>.FromNullable(dto.Bpm);
|
||||
if (!bpm.HasValue)
|
||||
bpm = track.Bpm;
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzRecordingId is not null)
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(dto.MusicBrainzRecordingId.Value);
|
||||
else
|
||||
musicBrainzRecordingId = track.MusicBrainzRecordingId;
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (dto.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(dto.MusicBrainzTrackId.Value);
|
||||
else
|
||||
musicBrainzTrackId = track.MusicBrainzTrackId;
|
||||
|
||||
return artist.UpdateTrackInAlbum(
|
||||
album,
|
||||
track,
|
||||
track.Path,
|
||||
metadataResult.Value,
|
||||
track.TrackNumber,
|
||||
track.DiscNumber,
|
||||
script,
|
||||
key,
|
||||
bpm,
|
||||
dto.IsVideo,
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
moods,
|
||||
isrcs,
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AudioMetadata"/>, keeping the locally extracted audio properties that the provider did not return.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <param name="track">The existing track whose locally extracted properties are preserved for the fields the provider left empty.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioMetadata> ToDomainEntity(this AudioMetadataDto dto)
|
||||
private static Result<AudioMetadata> ToDomainValueObject(this AudioMetadataDto dto, Track track)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
Result<ReleaseInfo> releaseInfoResult = dto.ReleaseInfo is null
|
||||
? ReleaseInfo.Create(
|
||||
track.Metadata.ReleaseInfo.OriginalReleaseDate,
|
||||
track.Metadata.ReleaseInfo.OriginalReleaseYear,
|
||||
track.Metadata.ReleaseInfo.ReReleaseDate,
|
||||
track.Metadata.ReleaseInfo.ReReleaseYear,
|
||||
track.Metadata.ReleaseInfo.ReleaseCountry,
|
||||
track.Metadata.ReleaseInfo.ReleaseVersion)
|
||||
: ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(dto.ReleaseInfo.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(dto.ReleaseInfo.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(dto.ReleaseInfo.ReReleaseDate),
|
||||
Optional<int>.FromNullable(dto.ReleaseInfo.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(dto.ReleaseInfo.ReleaseCountry),
|
||||
Optional<string>.FromNullable(dto.ReleaseInfo.ReleaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
List<Genre> genres = [.. track.Metadata.Genres];
|
||||
if (dto.Genres is { Count: > 0 })
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainEntity();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
genres = [];
|
||||
foreach (GenreDto genre in dto.Genres)
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
genres.Add(genreResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
List<Tag> tags = [.. track.Metadata.Tags];
|
||||
if (dto.Tags is { Count: > 0 })
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainEntity();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
tags = [];
|
||||
foreach (TagDto tag in dto.Tags)
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
tags.Add(tagResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
Optional<LanguageInfo> language = track.Metadata.Language;
|
||||
if (dto.Language is not null && dto.Language.LanguageCode is not null && dto.Language.LanguageName is not null)
|
||||
language = LanguageInfo.Create(dto.Language.LanguageCode, dto.Language.LanguageName, Optional<string>.FromNullable(dto.Language.NativeName));
|
||||
|
||||
Optional<LanguageInfo> originalLanguage = Optional<LanguageInfo>.None();
|
||||
Optional<LanguageInfo> originalLanguage = track.Metadata.OriginalLanguage;
|
||||
if (dto.OriginalLanguage is not null && dto.OriginalLanguage.LanguageCode is not null && dto.OriginalLanguage.LanguageName is not null)
|
||||
originalLanguage = LanguageInfo.Create(dto.OriginalLanguage.LanguageCode, dto.OriginalLanguage.LanguageName, Optional<string>.FromNullable(dto.OriginalLanguage.NativeName));
|
||||
|
||||
return AudioMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
dto.DurationInSeconds ?? 0,
|
||||
dto.SampleRate ?? 0,
|
||||
dto.Channels ?? 0,
|
||||
string.IsNullOrWhiteSpace(dto.Title) ? track.Metadata.Title : dto.Title,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle).HasValue ? Optional<string>.FromNullable(dto.OriginalTitle) : track.Metadata.OriginalTitle,
|
||||
dto.DurationInSeconds is > 0 ? dto.DurationInSeconds.Value : track.Metadata.DurationInSeconds,
|
||||
dto.SampleRate is > 0 ? dto.SampleRate.Value : track.Metadata.SampleRate,
|
||||
dto.Channels is > 0 ? dto.Channels.Value : track.Metadata.Channels,
|
||||
releaseInfoResult.Value,
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
domainGenres,
|
||||
domainTags,
|
||||
Optional<string>.FromNullable(dto.Description).HasValue ? Optional<string>.FromNullable(dto.Description) : track.Metadata.Description,
|
||||
genres,
|
||||
tags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<int>.FromNullable(dto.BitDepth),
|
||||
Optional<string>.FromNullable(dto.AudioCodec),
|
||||
Optional<int>.FromNullable(dto.Bitrate));
|
||||
Optional<int>.FromNullable(dto.BitDepth).HasValue ? Optional<int>.FromNullable(dto.BitDepth) : track.Metadata.BitDepth,
|
||||
Optional<string>.FromNullable(dto.AudioCodec).HasValue ? Optional<string>.FromNullable(dto.AudioCodec) : track.Metadata.AudioCodec,
|
||||
Optional<int>.FromNullable(dto.Bitrate).HasValue ? Optional<int>.FromNullable(dto.Bitrate) : track.Metadata.Bitrate,
|
||||
track.Metadata.AcoustId,
|
||||
track.Metadata.ReplayGainTrackGain,
|
||||
track.Metadata.ReplayGainTrackPeak,
|
||||
track.Metadata.ReplayGainAlbumGain,
|
||||
track.Metadata.ReplayGainAlbumPeak);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicTrackMetadataDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicTrackMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="AudioMetadata"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="AudioMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<AudioMetadata> ToDomainValueObject(this MusicTrackMetadataDto dto)
|
||||
{
|
||||
ReleaseInfoDto? releaseInfoDto = dto.ReleaseInfo;
|
||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.OriginalReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.OriginalReleaseYear),
|
||||
Optional<DateOnly>.FromNullable(releaseInfoDto?.ReReleaseDate),
|
||||
Optional<int>.FromNullable(releaseInfoDto?.ReReleaseYear),
|
||||
Optional<ReleaseCountry>.FromNullable(releaseInfoDto?.ReleaseCountry),
|
||||
Optional<string>.FromNullable(releaseInfoDto?.ReleaseVersion));
|
||||
if (releaseInfoResult.IsFailure)
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (GenreDto genre in dto.Genres ?? [])
|
||||
{
|
||||
Result<Genre> genreResult = genre.ToDomainValueObject();
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
domainGenres.Add(genreResult.Value);
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (TagDto tag in dto.Tags ?? [])
|
||||
{
|
||||
Result<Tag> tagResult = tag.ToDomainValueObject();
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
domainTags.Add(tagResult.Value);
|
||||
}
|
||||
|
||||
Optional<LanguageInfo> language = Optional<LanguageInfo>.None();
|
||||
if (dto.Language is not null && dto.Language.LanguageCode is not null && dto.Language.LanguageName is not null)
|
||||
language = LanguageInfo.Create(dto.Language.LanguageCode, dto.Language.LanguageName, Optional<string>.FromNullable(dto.Language.NativeName));
|
||||
|
||||
Optional<LanguageInfo> originalLanguage = Optional<LanguageInfo>.None();
|
||||
if (dto.OriginalLanguage is not null && dto.OriginalLanguage.LanguageCode is not null && dto.OriginalLanguage.LanguageName is not null)
|
||||
originalLanguage = LanguageInfo.Create(dto.OriginalLanguage.LanguageCode, dto.OriginalLanguage.LanguageName, Optional<string>.FromNullable(dto.OriginalLanguage.NativeName));
|
||||
|
||||
return AudioMetadata.Create(
|
||||
dto.Title!,
|
||||
Optional<string>.FromNullable(dto.OriginalTitle),
|
||||
dto.DurationInSeconds ?? 0,
|
||||
dto.SampleRate ?? 0,
|
||||
dto.Channels ?? 0,
|
||||
releaseInfoResult.Value,
|
||||
Optional<string>.FromNullable(dto.Description),
|
||||
domainGenres,
|
||||
domainTags,
|
||||
language,
|
||||
originalLanguage,
|
||||
Optional<int>.FromNullable(dto.BitDepth),
|
||||
Optional<string>.FromNullable(dto.AudioCodec),
|
||||
Optional<int>.FromNullable(dto.Bitrate),
|
||||
Optional<string>.FromNullable(dto.AcoustId),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainTrackGain),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainTrackPeak),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainAlbumGain),
|
||||
Optional<decimal>.FromNullable(dto.ReplayGainAlbumPeak));
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MusicWorkDto"/>.
|
||||
/// </summary>
|
||||
public static class MusicWorkDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="dto"/> to a domain <see cref="MusicWork"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The data transfer object to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MusicWork"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicWork> ToDomainValueObject(this MusicWorkDto dto)
|
||||
{
|
||||
if (dto.MusicBrainzWorkId is null)
|
||||
return Domain.Common.Errors.Errors.Music.MusicBrainzIdInvalidFormat;
|
||||
if (string.IsNullOrWhiteSpace(dto.Title))
|
||||
return Domain.Common.Errors.Errors.Music.WorkTitleCannotBeEmpty;
|
||||
|
||||
List<LanguageInfo> languages = [];
|
||||
foreach (LanguageInfoDto languageDto in dto.Languages ?? [])
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(languageDto.LanguageCode) || string.IsNullOrWhiteSpace(languageDto.LanguageName))
|
||||
continue;
|
||||
languages.Add(LanguageInfo.Create(languageDto.LanguageCode, languageDto.LanguageName, Optional<string>.FromNullable(languageDto.NativeName)));
|
||||
}
|
||||
|
||||
List<string> iswcs = [.. (dto.Iswcs ?? []).Where(iswc => !string.IsNullOrWhiteSpace(iswc)).Select(iswc => iswc.Trim())];
|
||||
|
||||
return MusicWork.Create(
|
||||
MusicBrainzId.Create(dto.MusicBrainzWorkId.Value),
|
||||
dto.Title,
|
||||
Optional<string>.FromNullable(dto.Type),
|
||||
languages,
|
||||
iswcs);
|
||||
}
|
||||
}
|
||||
+54
-16
@@ -8,7 +8,6 @@ using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
@@ -48,7 +47,7 @@ public static class TrackEntityMapping
|
||||
return releaseInfoResult.Errors;
|
||||
|
||||
List<Genre> domainGenres = [];
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainEntities())
|
||||
foreach (Result<Genre> genreResult in repositoryEntity.Genres.ToDomainValueObjects())
|
||||
{
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
@@ -56,7 +55,7 @@ public static class TrackEntityMapping
|
||||
}
|
||||
|
||||
List<Tag> domainTags = [];
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainEntities())
|
||||
foreach (Result<Tag> tagResult in repositoryEntity.Tags.ToDomainValueObjects())
|
||||
{
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
@@ -85,7 +84,12 @@ public static class TrackEntityMapping
|
||||
originalLanguage,
|
||||
Optional<int>.FromNullable(repositoryEntity.BitDepth),
|
||||
Optional<string>.FromNullable(repositoryEntity.AudioCodec),
|
||||
Optional<int>.FromNullable(repositoryEntity.Bitrate));
|
||||
Optional<int>.FromNullable(repositoryEntity.Bitrate),
|
||||
Optional<string>.FromNullable(repositoryEntity.AcoustId),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainTrackGain),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainTrackPeak),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainAlbumGain),
|
||||
Optional<decimal>.FromNullable(repositoryEntity.ReplayGainAlbumPeak));
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
@@ -95,12 +99,27 @@ public static class TrackEntityMapping
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(repositoryEntity.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzWorkId is not null)
|
||||
musicBrainzWorkId = MusicBrainzId.Create(repositoryEntity.MusicBrainzWorkId.Value);
|
||||
|
||||
Optional<MusicWork> work = Optional<MusicWork>.None();
|
||||
if (repositoryEntity.MusicBrainzWorkId is not null && !string.IsNullOrWhiteSpace(repositoryEntity.WorkTitle))
|
||||
{
|
||||
List<LanguageInfo> workLanguages = [];
|
||||
foreach (TrackWorkLanguageEntity workLanguage in repositoryEntity.WorkLanguages)
|
||||
workLanguages.Add(LanguageInfo.Create(workLanguage.LanguageCode, workLanguage.LanguageName, Optional<string>.FromNullable(workLanguage.NativeName)));
|
||||
|
||||
Result<MusicWork> workResult = MusicWork.Create(
|
||||
MusicBrainzId.Create(repositoryEntity.MusicBrainzWorkId.Value),
|
||||
repositoryEntity.WorkTitle,
|
||||
Optional<string>.FromNullable(repositoryEntity.WorkType),
|
||||
workLanguages,
|
||||
[.. repositoryEntity.WorkIswcs.Select(workIswc => workIswc.Value)]);
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
List<Mood> domainMoods = [];
|
||||
foreach (Result<Mood> moodResult in repositoryEntity.Moods.ToDomainEntities())
|
||||
foreach (Result<Mood> moodResult in repositoryEntity.Moods.ToDomainValueObjects())
|
||||
{
|
||||
if (moodResult.IsFailure)
|
||||
return moodResult.Errors;
|
||||
@@ -108,7 +127,7 @@ public static class TrackEntityMapping
|
||||
}
|
||||
|
||||
List<Isrc> domainIsrcs = [];
|
||||
foreach (Result<Isrc> isrcResult in repositoryEntity.Isrcs.ToDomainEntities())
|
||||
foreach (Result<Isrc> isrcResult in repositoryEntity.Isrcs.ToDomainValueObjects())
|
||||
{
|
||||
if (isrcResult.IsFailure)
|
||||
return isrcResult.Errors;
|
||||
@@ -116,7 +135,7 @@ public static class TrackEntityMapping
|
||||
}
|
||||
|
||||
List<AudioRating> domainRatings = [];
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainEntities())
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainValueObjects())
|
||||
{
|
||||
if (ratingResult.IsFailure)
|
||||
return ratingResult.Errors;
|
||||
@@ -136,17 +155,18 @@ public static class TrackEntityMapping
|
||||
TrackId.Create(repositoryEntity.Id),
|
||||
repositoryEntity.Path,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(repositoryEntity.Disambiguation),
|
||||
repositoryEntity.TrackNumber,
|
||||
Optional<int>.FromNullable(repositoryEntity.DiscNumber),
|
||||
domainMoods,
|
||||
Optional<string>.FromNullable(repositoryEntity.Script),
|
||||
Optional<MusicKey>.FromNullable(repositoryEntity.Key),
|
||||
Optional<int>.FromNullable(repositoryEntity.Bpm),
|
||||
repositoryEntity.IsVideo,
|
||||
domainIsrcs,
|
||||
Optional<string>.FromNullable(repositoryEntity.Work),
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
domainContributors,
|
||||
domainRatings,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
@@ -185,21 +205,40 @@ public static class TrackEntityMapping
|
||||
repositoryEntity.OriginalLanguageName,
|
||||
repositoryEntity.OriginalLanguageNativeName
|
||||
) : null;
|
||||
AudioMetadataDto metadata = new(
|
||||
MusicWorkDto? work = null;
|
||||
if (repositoryEntity.MusicBrainzWorkId is not null && !string.IsNullOrWhiteSpace(repositoryEntity.WorkTitle))
|
||||
work = new MusicWorkDto(
|
||||
repositoryEntity.MusicBrainzWorkId,
|
||||
repositoryEntity.WorkTitle,
|
||||
repositoryEntity.WorkType,
|
||||
repositoryEntity.WorkLanguages.Count > 0
|
||||
? [.. repositoryEntity.WorkLanguages.Select(workLanguage => new LanguageInfoDto(workLanguage.LanguageCode, workLanguage.LanguageName, workLanguage.NativeName))]
|
||||
: null,
|
||||
repositoryEntity.WorkIswcs.Count > 0
|
||||
? [.. repositoryEntity.WorkIswcs.Select(workIswc => workIswc.Value)]
|
||||
: null);
|
||||
MusicTrackMetadataDto metadata = new(
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.OriginalTitle,
|
||||
repositoryEntity.Description,
|
||||
repositoryEntity.Disambiguation,
|
||||
releaseInfo,
|
||||
languageInfo,
|
||||
originalLanguageInfo,
|
||||
[.. repositoryEntity.Tags.ToResponses()],
|
||||
[.. repositoryEntity.Genres.ToResponses()],
|
||||
repositoryEntity.IsVideo,
|
||||
repositoryEntity.DurationInSeconds,
|
||||
repositoryEntity.SampleRate,
|
||||
repositoryEntity.Channels,
|
||||
repositoryEntity.BitDepth,
|
||||
repositoryEntity.AudioCodec,
|
||||
repositoryEntity.Bitrate
|
||||
repositoryEntity.Bitrate,
|
||||
repositoryEntity.AcoustId,
|
||||
repositoryEntity.ReplayGainTrackGain,
|
||||
repositoryEntity.ReplayGainTrackPeak,
|
||||
repositoryEntity.ReplayGainAlbumGain,
|
||||
repositoryEntity.ReplayGainAlbumPeak
|
||||
);
|
||||
return new TrackResponse(
|
||||
repositoryEntity.Id,
|
||||
@@ -212,10 +251,9 @@ public static class TrackEntityMapping
|
||||
repositoryEntity.Script,
|
||||
repositoryEntity.Key,
|
||||
repositoryEntity.Bpm,
|
||||
repositoryEntity.Work,
|
||||
work,
|
||||
repositoryEntity.MusicBrainzRecordingId,
|
||||
repositoryEntity.MusicBrainzTrackId,
|
||||
repositoryEntity.MusicBrainzWorkId,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
repositoryEntity.UpdatedOnUtc,
|
||||
[.. repositoryEntity.Moods.ToResponses()],
|
||||
|
||||
+16
-3
@@ -5,7 +5,6 @@ using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibrary
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
@@ -33,6 +32,7 @@ public static class TrackMapping
|
||||
Title = domainEntity.Metadata.Title,
|
||||
OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null,
|
||||
Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null,
|
||||
Disambiguation = domainEntity.Disambiguation.HasValue ? domainEntity.Disambiguation.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,
|
||||
@@ -53,15 +53,22 @@ public static class TrackMapping
|
||||
BitDepth = domainEntity.Metadata.BitDepth.HasValue ? domainEntity.Metadata.BitDepth.Value : null,
|
||||
AudioCodec = domainEntity.Metadata.AudioCodec.HasValue ? domainEntity.Metadata.AudioCodec.Value : null,
|
||||
Bitrate = domainEntity.Metadata.Bitrate.HasValue ? domainEntity.Metadata.Bitrate.Value : null,
|
||||
AcoustId = domainEntity.Metadata.AcoustId.HasValue ? domainEntity.Metadata.AcoustId.Value : null,
|
||||
ReplayGainTrackGain = domainEntity.Metadata.ReplayGainTrackGain.HasValue ? domainEntity.Metadata.ReplayGainTrackGain.Value : null,
|
||||
ReplayGainTrackPeak = domainEntity.Metadata.ReplayGainTrackPeak.HasValue ? domainEntity.Metadata.ReplayGainTrackPeak.Value : null,
|
||||
ReplayGainAlbumGain = domainEntity.Metadata.ReplayGainAlbumGain.HasValue ? domainEntity.Metadata.ReplayGainAlbumGain.Value : null,
|
||||
ReplayGainAlbumPeak = domainEntity.Metadata.ReplayGainAlbumPeak.HasValue ? domainEntity.Metadata.ReplayGainAlbumPeak.Value : null,
|
||||
TrackNumber = domainEntity.TrackNumber,
|
||||
DiscNumber = domainEntity.DiscNumber.HasValue ? domainEntity.DiscNumber.Value : null,
|
||||
Script = domainEntity.Script.HasValue ? domainEntity.Script.Value : null,
|
||||
Key = domainEntity.Key.HasValue ? domainEntity.Key.Value : null,
|
||||
Bpm = domainEntity.Bpm.HasValue ? domainEntity.Bpm.Value : null,
|
||||
Work = domainEntity.Work.HasValue ? domainEntity.Work.Value : null,
|
||||
IsVideo = domainEntity.IsVideo,
|
||||
WorkTitle = domainEntity.Work.HasValue ? domainEntity.Work.Value.Title : null,
|
||||
WorkType = domainEntity.Work.HasValue && domainEntity.Work.Value.Type.HasValue ? domainEntity.Work.Value.Type.Value : null,
|
||||
MusicBrainzRecordingId = domainEntity.MusicBrainzRecordingId.HasValue ? domainEntity.MusicBrainzRecordingId.Value.Value : null,
|
||||
MusicBrainzTrackId = domainEntity.MusicBrainzTrackId.HasValue ? domainEntity.MusicBrainzTrackId.Value.Value : null,
|
||||
MusicBrainzWorkId = domainEntity.MusicBrainzWorkId.HasValue ? domainEntity.MusicBrainzWorkId.Value.Value : null,
|
||||
MusicBrainzWorkId = domainEntity.Work.HasValue ? domainEntity.Work.Value.MusicBrainzWorkId.Value : null,
|
||||
Contributors = [.. domainEntity.Contributors.Select(contributor => new TrackContributorEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
@@ -74,6 +81,12 @@ public static class TrackMapping
|
||||
})],
|
||||
Moods = [.. domainEntity.Moods.ToRepositoryEntities()],
|
||||
Isrcs = [.. domainEntity.Isrcs.ToRepositoryEntities()],
|
||||
WorkLanguages = domainEntity.Work.HasValue
|
||||
? [.. domainEntity.Work.Value.Languages.Select(language => new TrackWorkLanguageEntity(language.LanguageCode, language.LanguageName, language.NativeName.HasValue ? language.NativeName.Value : null))]
|
||||
: [],
|
||||
WorkIswcs = domainEntity.Work.HasValue
|
||||
? [.. domainEntity.Work.Value.Iswcs.Select(iswc => new TrackWorkIswcEntity(iswc))]
|
||||
: [],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
|
||||
+18
-10
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.UpdateTrack;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
@@ -32,39 +33,46 @@ public static class UpdateTrackCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Artist> ToDomainEntity(this UpdateTrackCommand command, Artist artist)
|
||||
{
|
||||
Result<AudioMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
MusicTrackMetadataDto metadata = command.Metadata!;
|
||||
Result<AudioMetadata> metadataResult = metadata.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainValueObjects();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<MusicWork> work = Optional<MusicWork>.None();
|
||||
if (command.Work is not null)
|
||||
{
|
||||
Result<MusicWork> workResult = command.Work.ToDomainValueObject();
|
||||
if (workResult.IsFailure)
|
||||
return workResult.Errors;
|
||||
work = workResult.Value;
|
||||
}
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzRecordingId is not null)
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzTrackId is not null)
|
||||
musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzWorkId is not null)
|
||||
musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
|
||||
// The album and the track are entities inside the artist aggregate, so they are referenced by object, not by id; the aggregate members are located here and passed through.
|
||||
Album? album = artist.Albums.FirstOrDefault(album => album.Id.Value == Guid.Parse(command.AlbumId!));
|
||||
@@ -84,10 +92,10 @@ public static class UpdateTrackCommandMapping
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
metadata.IsVideo,
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
[.. domainMoodsResult.Select(moodResult => moodResult.Value)],
|
||||
[.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)],
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
|
||||
-1
@@ -36,7 +36,6 @@ public static class UpdateTrackRequestMapping
|
||||
request.Work,
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Moods,
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
|
||||
+3
-3
@@ -32,17 +32,17 @@ public static class AddBookCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Book> ToDomainEntity(this AddBookCommand command, Guid libraryId)
|
||||
{
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainValueObjects();
|
||||
errors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsFailure).SelectMany(isbnResult => isbnResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
|
||||
+4
-4
@@ -40,22 +40,22 @@ public static class BookEntityMapping
|
||||
/// </returns>
|
||||
public static Result<Book> ToDomainEntity(this BookEntity repositoryEntity)
|
||||
{
|
||||
IEnumerable<Result<Tag>> tagsResult = repositoryEntity.Tags.ToDomainEntities();
|
||||
IEnumerable<Result<Tag>> tagsResult = repositoryEntity.Tags.ToDomainValueObjects();
|
||||
foreach (Result<Tag> tagResult in tagsResult)
|
||||
if (tagResult.IsFailure)
|
||||
return tagResult.Errors;
|
||||
|
||||
IEnumerable<Result<Genre>> genresResult = repositoryEntity.Genres.ToDomainEntities();
|
||||
IEnumerable<Result<Genre>> genresResult = repositoryEntity.Genres.ToDomainValueObjects();
|
||||
foreach (Result<Genre> genreResult in genresResult)
|
||||
if (genreResult.IsFailure)
|
||||
return genreResult.Errors;
|
||||
|
||||
IEnumerable<Result<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainValueObjects();
|
||||
foreach (Result<Isbn> isbnResult in isbnsResult)
|
||||
if (isbnResult.IsFailure)
|
||||
return isbnResult.Errors;
|
||||
|
||||
IEnumerable<Result<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainValueObjects();
|
||||
foreach (Result<BookRating> bookRatingResult in bookRatingsResult)
|
||||
if (bookRatingResult.IsFailure)
|
||||
return bookRatingResult.Errors;
|
||||
|
||||
+3
-3
@@ -33,17 +33,17 @@ public static class UpdateBookCommandMapping
|
||||
/// </returns>
|
||||
public static Result<Book> ToDomainEntity(this UpdateBookCommand command, BookEntity existingBook)
|
||||
{
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
IEnumerable<Result<BookRating>> domainRatingsResult = command.Ratings!.ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainEntities();
|
||||
IEnumerable<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ToDomainValueObjects();
|
||||
errors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsFailure).SelectMany(isbnResult => isbnResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
Result<WrittenContentMetadata> metadataResult = command.Metadata!.ToDomainValueObject();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ public static class BookRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<BookRating> ToDomainEntity(this BookRatingDto dto)
|
||||
public static Result<BookRating> ToDomainValueObject(this BookRatingDto dto)
|
||||
{
|
||||
return BookRating.Create(
|
||||
dto.Value ?? default,
|
||||
@@ -39,8 +39,8 @@ public static class BookRatingDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<BookRating>> ToDomainEntities(this IEnumerable<BookRatingDto> dtos)
|
||||
public static IEnumerable<Result<BookRating>> ToDomainValueObjects(this IEnumerable<BookRatingDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -48,7 +48,7 @@ public static class BookRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<BookRating> ToDomainEntity(this BookRatingEntity repositoryEntity)
|
||||
public static Result<BookRating> ToDomainValueObject(this BookRatingEntity repositoryEntity)
|
||||
{
|
||||
return BookRating.Create(
|
||||
repositoryEntity.Value ?? default,
|
||||
@@ -65,8 +65,8 @@ public static class BookRatingEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<BookRating>> ToDomainEntities(this IEnumerable<BookRatingEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<BookRating>> ToDomainValueObjects(this IEnumerable<BookRatingEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -21,7 +21,7 @@ public static class IsbnDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isbn> ToDomainEntity(this IsbnDto dto)
|
||||
public static Result<Isbn> ToDomainValueObject(this IsbnDto dto)
|
||||
{
|
||||
return Isbn.Create(
|
||||
dto.Value!,
|
||||
@@ -36,8 +36,8 @@ public static class IsbnDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isbn>> ToDomainEntities(this IEnumerable<IsbnDto> dtos)
|
||||
public static IEnumerable<Result<Isbn>> ToDomainValueObjects(this IEnumerable<IsbnDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -44,7 +44,7 @@ public static class IsbnEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
|
||||
public static Result<Isbn> ToDomainValueObject(this IsbnEntity repositoryEntity)
|
||||
{
|
||||
return Isbn.Create(
|
||||
repositoryEntity.Value!,
|
||||
@@ -59,8 +59,8 @@ public static class IsbnEntityMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<Result<Isbn>> ToDomainEntities(this IEnumerable<IsbnEntity> repositoryEntities)
|
||||
public static IEnumerable<Result<Isbn>> ToDomainValueObjects(this IEnumerable<IsbnEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainValueObject());
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -22,28 +22,28 @@ public static class WrittenContentMetadataDtoMapping
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="WrittenContentMetadata"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<WrittenContentMetadata> ToDomainEntity(this WrittenContentMetadataDto dto)
|
||||
public static Result<WrittenContentMetadata> ToDomainValueObject(this WrittenContentMetadataDto dto)
|
||||
{
|
||||
|
||||
Result<ReleaseInfo>? domainReleaseInfoResult = dto.ReleaseInfo!.ToDomainEntity();
|
||||
Result<ReleaseInfo>? domainReleaseInfoResult = dto.ReleaseInfo!.ToDomainValueObject();
|
||||
if (domainReleaseInfoResult.Value.IsFailure)
|
||||
return domainReleaseInfoResult.Value.Errors;
|
||||
|
||||
IEnumerable<Result<Genre>> domainGenresResult = dto.Genres!.ToDomainEntities();
|
||||
IEnumerable<Result<Genre>> domainGenresResult = dto.Genres!.ToDomainValueObjects();
|
||||
List<Error> errors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Tag>> domainTagsResult = dto.Tags!.ToDomainEntities();
|
||||
IEnumerable<Result<Tag>> domainTagsResult = dto.Tags!.ToDomainValueObjects();
|
||||
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Result<LanguageInfo>? domainLanguageInfoResult = dto.Language?.ToDomainEntity();
|
||||
Result<LanguageInfo>? domainLanguageInfoResult = dto.Language?.ToDomainValueObject();
|
||||
if (domainLanguageInfoResult.HasValue && domainLanguageInfoResult.Value.IsFailure)
|
||||
return domainLanguageInfoResult.Value.Errors;
|
||||
|
||||
Result<LanguageInfo>? domainOriginalLanguageInfoResult = dto.OriginalLanguage?.ToDomainEntity();
|
||||
Result<LanguageInfo>? domainOriginalLanguageInfoResult = dto.OriginalLanguage?.ToDomainValueObject();
|
||||
if (domainOriginalLanguageInfoResult.HasValue && domainOriginalLanguageInfoResult.Value.IsFailure)
|
||||
return domainOriginalLanguageInfoResult.Value.Errors;
|
||||
|
||||
|
||||
Reference in new issue
Block a user