mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 20:11:10 +00:00
Adds the music library commands and their validators
This commit is contained in:
1 parent
b7db29eee5
commit
1fad9316ce
30 files changed
+700
-256
No files matched your search
+10
-3
@@ -19,22 +19,29 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.
|
||||
/// <param name="ArtistId">The Id of the artist the album belongs to, taken from the route.</param>
|
||||
/// <param name="Metadata">The album metadata of the album.</param>
|
||||
/// <param name="MediaFormat">The physical or digital medium of the album, if applicable.</param>
|
||||
/// <param name="Packaging">The outermost physical packaging of the album, if applicable.</param>
|
||||
/// <param name="Barcode">The barcode of the album, if applicable.</param>
|
||||
/// <param name="CatalogNumber">The catalog number of the album, if applicable.</param>
|
||||
/// <param name="CatalogNumbers">The catalog numbers of the album, if applicable.</param>
|
||||
/// <param name="Label">The name of the label that issued the album, if applicable.</param>
|
||||
/// <param name="ASIN">The ASIN (Amazon Standard Identification Number) of the album, if applicable.</param>
|
||||
/// <param name="MusicBrainzReleaseId">The MusicBrainz identifier of the release, if applicable.</param>
|
||||
/// <param name="MusicBrainzReleaseGroupId">The MusicBrainz identifier of the release group, if applicable.</param>
|
||||
/// <param name="MusicBrainzReleaseArtistId">The MusicBrainz identifier of the release artist, if applicable.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the album.</param>
|
||||
/// <param name="Ratings">The list of ratings for this album.</param>
|
||||
/// <param name="Tracks">The list of tracks of the album.</param>
|
||||
/// <param name="AlbumId">The Id of the album, when the album already exists.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record AddAlbumCommand(
|
||||
string? LibraryId,
|
||||
string? ArtistId,
|
||||
AlbumMetadataDto? Metadata,
|
||||
MusicAlbumMetadataDto? Metadata,
|
||||
MusicMediaFormat? MediaFormat,
|
||||
MusicReleasePackaging? Packaging,
|
||||
string? Barcode,
|
||||
string? CatalogNumber,
|
||||
List<string>? CatalogNumbers,
|
||||
string? Label,
|
||||
string? ASIN,
|
||||
Guid? MusicBrainzReleaseId,
|
||||
Guid? MusicBrainzReleaseGroupId,
|
||||
Guid? MusicBrainzReleaseArtistId,
|
||||
|
||||
+29
-13
@@ -3,6 +3,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.AddAlbum;
|
||||
@@ -37,7 +38,7 @@ public class AddAlbumCommandValidator : AbstractValidator<AddAlbumCommand>
|
||||
.When(command => command.ArtistId is not null && command.ArtistId.Length > 0)
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
|
||||
// Validates the metadata of the album: title, lengths, release type and status, disc and track counts, release information, languages, genres and tags.
|
||||
// Validates the metadata of the album: title, lengths, release types and status, disc and track counts, release information, languages, genres and tags.
|
||||
RuleFor(command => command.Metadata)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.MetadataCannotBeNull)
|
||||
@@ -60,9 +61,13 @@ public class AddAlbumCommandValidator : AbstractValidator<AddAlbumCommand>
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseType)
|
||||
metadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleForEach(m => m!.ReleaseTypes)
|
||||
.IsInEnum()
|
||||
.When(m => m!.ReleaseType is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleaseType);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseStatus)
|
||||
@@ -196,15 +201,20 @@ public class AddAlbumCommandValidator : AbstractValidator<AddAlbumCommand>
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the physical characteristics of the album: format and catalog number.
|
||||
// Validates the physical characteristics of the album: format, packaging, catalog number and barcode.
|
||||
RuleFor(command => command.MediaFormat)
|
||||
.IsInEnum()
|
||||
.When(command => command.MediaFormat is not null)
|
||||
.WithError(Errors.Music.UnknownMusicMediaFormat);
|
||||
|
||||
RuleFor(command => command.CatalogNumber)
|
||||
RuleFor(command => command.Packaging)
|
||||
.IsInEnum()
|
||||
.When(command => command.Packaging is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleasePackaging);
|
||||
|
||||
RuleForEach(command => command.CatalogNumbers)
|
||||
.MaximumLength(50)
|
||||
.When(command => command.CatalogNumber is not null)
|
||||
.When(command => command.CatalogNumbers is not null)
|
||||
.WithError(Errors.Music.CatalogNumberMustBeMaximum50CharactersLong);
|
||||
|
||||
RuleFor(command => command.Barcode)
|
||||
@@ -313,6 +323,11 @@ public class AddAlbumCommandValidator : AbstractValidator<AddAlbumCommand>
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.ReleaseInfo)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.ReleaseInfoCannotBeNull)
|
||||
@@ -440,11 +455,6 @@ public class AddAlbumCommandValidator : AbstractValidator<AddAlbumCommand>
|
||||
.When(t => t!.MusicBrainzTrackId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
track.RuleFor(t => t!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzWorkId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
track.RuleFor(t => t!.TrackNumber)
|
||||
.NotNull()
|
||||
@@ -475,11 +485,17 @@ public class AddAlbumCommandValidator : AbstractValidator<AddAlbumCommand>
|
||||
.When(t => t!.Bpm.HasValue)
|
||||
.WithError(Errors.Music.BpmMustBeGreaterThanZero);
|
||||
|
||||
track.RuleFor(t => t!.Work)
|
||||
// Validates the work the track is a recording of.
|
||||
track.RuleFor(t => t!.Work!.Title)
|
||||
.MaximumLength(255)
|
||||
.When(t => t!.Work is not null)
|
||||
.When(t => t!.Work is not null && t.Work.Title is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
track.RuleFor(t => t!.Work!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId is null || musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.Work is not null)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the media contributors that performed on the track.
|
||||
track.RuleFor(t => t!.Contributors)
|
||||
.NotNull()
|
||||
|
||||
+9
-3
@@ -19,8 +19,11 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.
|
||||
/// <param name="AlbumId">The unique identifier of the album, taken from the route.</param>
|
||||
/// <param name="Metadata">The album metadata of the album.</param>
|
||||
/// <param name="MediaFormat">The physical or digital medium of the album, if applicable.</param>
|
||||
/// <param name="Packaging">The outermost physical packaging of the album, if applicable.</param>
|
||||
/// <param name="Barcode">The barcode of the album, if applicable.</param>
|
||||
/// <param name="CatalogNumber">The catalog number of the album, if applicable.</param>
|
||||
/// <param name="CatalogNumbers">The catalog numbers of the album, if applicable.</param>
|
||||
/// <param name="Label">The name of the label that issued the album, if applicable.</param>
|
||||
/// <param name="ASIN">The ASIN (Amazon Standard Identification Number) of the album, if applicable.</param>
|
||||
/// <param name="MusicBrainzReleaseId">The MusicBrainz identifier of the release, if applicable.</param>
|
||||
/// <param name="MusicBrainzReleaseGroupId">The MusicBrainz identifier of the release group, if applicable.</param>
|
||||
/// <param name="MusicBrainzReleaseArtistId">The MusicBrainz identifier of the release artist, if applicable.</param>
|
||||
@@ -31,10 +34,13 @@ public record UpdateAlbumCommand(
|
||||
string? LibraryId,
|
||||
string? ArtistId,
|
||||
string? AlbumId,
|
||||
AlbumMetadataDto? Metadata,
|
||||
MusicAlbumMetadataDto? Metadata,
|
||||
MusicMediaFormat? MediaFormat,
|
||||
MusicReleasePackaging? Packaging,
|
||||
string? Barcode,
|
||||
string? CatalogNumber,
|
||||
List<string>? CatalogNumbers,
|
||||
string? Label,
|
||||
string? ASIN,
|
||||
Guid? MusicBrainzReleaseId,
|
||||
Guid? MusicBrainzReleaseGroupId,
|
||||
Guid? MusicBrainzReleaseArtistId,
|
||||
|
||||
+15
-6
@@ -47,7 +47,7 @@ public class UpdateAlbumCommandValidator : AbstractValidator<UpdateAlbumCommand>
|
||||
.When(command => command.AlbumId is not null && command.AlbumId.Length > 0)
|
||||
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
|
||||
|
||||
// Validates the metadata of the album: title, lengths, release type and status, disc and track counts, release information, languages, genres and tags.
|
||||
// Validates the metadata of the album: title, lengths, release types and status, disc and track counts, release information, languages, genres and tags.
|
||||
RuleFor(command => command.Metadata)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.MetadataCannotBeNull)
|
||||
@@ -70,9 +70,13 @@ public class UpdateAlbumCommandValidator : AbstractValidator<UpdateAlbumCommand>
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseType)
|
||||
metadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleForEach(m => m!.ReleaseTypes)
|
||||
.IsInEnum()
|
||||
.When(m => m!.ReleaseType is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleaseType);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseStatus)
|
||||
@@ -206,15 +210,20 @@ public class UpdateAlbumCommandValidator : AbstractValidator<UpdateAlbumCommand>
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the physical characteristics of the album: format and catalog number.
|
||||
// Validates the physical characteristics of the album: format, packaging, catalog number and barcode.
|
||||
RuleFor(command => command.MediaFormat)
|
||||
.IsInEnum()
|
||||
.When(command => command.MediaFormat is not null)
|
||||
.WithError(Errors.Music.UnknownMusicMediaFormat);
|
||||
|
||||
RuleFor(command => command.CatalogNumber)
|
||||
RuleFor(command => command.Packaging)
|
||||
.IsInEnum()
|
||||
.When(command => command.Packaging is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleasePackaging);
|
||||
|
||||
RuleForEach(command => command.CatalogNumbers)
|
||||
.MaximumLength(50)
|
||||
.When(command => command.CatalogNumber is not null)
|
||||
.When(command => command.CatalogNumbers is not null)
|
||||
.WithError(Errors.Music.CatalogNumberMustBeMaximum50CharactersLong);
|
||||
|
||||
RuleFor(command => command.Barcode)
|
||||
|
||||
+11
-3
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.AddAlbum;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -13,17 +15,23 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// Command for adding an artist, together with the albums of the artist and the tracks of those albums.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library this artist belongs to, taken from the route.</param>
|
||||
/// <param name="Name">The name of the artist.</param>
|
||||
/// <param name="Metadata">The metadata of the artist.</param>
|
||||
/// <param name="Website">The website of the artist, if applicable.</param>
|
||||
/// <param name="MusicBrainzArtistId">The MusicBrainz identifier of the artist, if applicable.</param>
|
||||
/// <param name="Ipis">The list of IPI codes of the artist.</param>
|
||||
/// <param name="Isnis">The list of ISNI codes of the artist.</param>
|
||||
/// <param name="Contributors">The list of media contributors that make up the artist.</param>
|
||||
/// <param name="Ratings">The list of ratings for the artist.</param>
|
||||
/// <param name="Albums">The list of albums of the artist, each with its own list of tracks.</param>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
[DebuggerDisplay("Name: {Metadata.Name}")]
|
||||
public record AddArtistCommand(
|
||||
string? LibraryId,
|
||||
string? Name,
|
||||
MusicArtistMetadataDto? Metadata,
|
||||
string? Website,
|
||||
Guid? MusicBrainzArtistId,
|
||||
List<string>? Ipis,
|
||||
List<string>? Isnis,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<AddAlbumCommand>? Albums
|
||||
) : ICommand;
|
||||
+171
-18
@@ -28,13 +28,115 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifying details of the artist.
|
||||
RuleFor(command => command.Name)
|
||||
RuleFor(command => command.Metadata)
|
||||
.NotNull()
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
.WithError(Errors.Metadata.MetadataCannotBeNull)
|
||||
.ChildRules(metadata =>
|
||||
{
|
||||
metadata.RuleFor(m => m!.Name)
|
||||
.NotNull()
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.SortName)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.SortName is not null)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.Type)
|
||||
.IsInEnum()
|
||||
.When(m => m!.Type is not null)
|
||||
.WithError(Errors.Music.UnknownMusicArtistType);
|
||||
|
||||
metadata.RuleFor(m => m!.Gender)
|
||||
.IsInEnum()
|
||||
.When(m => m!.Gender is not null)
|
||||
.WithError(Errors.Music.UnknownMusicArtistGender);
|
||||
|
||||
metadata.RuleFor(m => m!.Country)
|
||||
.Length(2)
|
||||
.When(m => m!.Country is not null)
|
||||
.WithError(Errors.Music.CountryMustBeMaximum2CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.Area!.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AreaNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.AreaNameMustBeMaximum255CharactersLong)
|
||||
.When(m => m!.Area is not null);
|
||||
|
||||
metadata.RuleFor(m => m!.BeginArea!.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AreaNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.AreaNameMustBeMaximum255CharactersLong)
|
||||
.When(m => m!.BeginArea is not null);
|
||||
|
||||
metadata.RuleFor(m => m!.EndArea!.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AreaNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.AreaNameMustBeMaximum255CharactersLong)
|
||||
.When(m => m!.EndArea is not null);
|
||||
|
||||
metadata.RuleForEach(m => m!.Aliases)
|
||||
.ChildRules(alias =>
|
||||
{
|
||||
alias.RuleFor(a => a.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistAliasNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.ArtistAliasNameMustBeMaximum255CharactersLong);
|
||||
|
||||
alias.RuleFor(a => a.SortName)
|
||||
.MaximumLength(255)
|
||||
.When(a => a.SortName is not null)
|
||||
.WithError(Errors.Music.ArtistAliasNameMustBeMaximum255CharactersLong);
|
||||
|
||||
alias.RuleFor(a => a.Type)
|
||||
.MaximumLength(50)
|
||||
.When(a => a.Type is not null)
|
||||
.WithError(Errors.Music.ScriptMustBeMaximum50CharactersLong);
|
||||
|
||||
alias.RuleFor(a => a.Locale)
|
||||
.MaximumLength(20)
|
||||
.When(a => a.Locale is not null)
|
||||
.WithError(Errors.Music.ScriptMustBeMaximum50CharactersLong);
|
||||
});
|
||||
|
||||
metadata.RuleFor(m => m!.Genres)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.GenresListCannotBeNull);
|
||||
|
||||
metadata.RuleForEach(m => m!.Genres)
|
||||
.ChildRules(genre =>
|
||||
genre.RuleFor(g => g.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.GenreNameCannotBeEmpty)
|
||||
.MaximumLength(50)
|
||||
.WithError(Errors.Metadata.GenreNameMustBeMaximum50CharactersLong));
|
||||
|
||||
metadata.RuleFor(m => m!.Tags)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.TagsListCannotBeNull);
|
||||
|
||||
metadata.RuleForEach(m => m!.Tags)
|
||||
.ChildRules(tag =>
|
||||
tag.RuleFor(t => t.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.TagNameCannotBeEmpty)
|
||||
.MaximumLength(50)
|
||||
.WithError(Errors.Metadata.TagNameMustBeMaximum50CharactersLong));
|
||||
});
|
||||
|
||||
// Validates the website and the MusicBrainz identifiers of the artist.
|
||||
RuleFor(command => command.Website)
|
||||
.MaximumLength(2048)
|
||||
.When(command => command.Website is not null)
|
||||
@@ -45,6 +147,18 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(command => command.MusicBrainzArtistId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
RuleForEach(command => command.Ipis)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IpiValueCannotBeEmpty)
|
||||
.MaximumLength(20)
|
||||
.WithError(Errors.Music.IpiValueMustBeMaximum20CharactersLong);
|
||||
|
||||
RuleForEach(command => command.Isnis)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsniValueCannotBeEmpty)
|
||||
.MaximumLength(20)
|
||||
.WithError(Errors.Music.IsniValueMustBeMaximum20CharactersLong);
|
||||
|
||||
// Validates the media contributors that make up the artist.
|
||||
RuleFor(command => command.Contributors)
|
||||
.NotNull()
|
||||
@@ -64,6 +178,30 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.WithError(Errors.MediaContributor.UnknownMediaContributorRole);
|
||||
});
|
||||
|
||||
// Validates the ratings of the artist.
|
||||
RuleFor(command => command.Ratings)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.RatingsListCannotBeNull);
|
||||
|
||||
RuleForEach(command => command.Ratings)
|
||||
.ChildRules(rating =>
|
||||
{
|
||||
rating.RuleFor(r => r.Value)
|
||||
.GreaterThan(0)
|
||||
.WithError(Errors.Metadata.RatingValueMustBePositive)
|
||||
.Must((ratingInstance, value) => value <= ratingInstance.MaxValue)
|
||||
.WithError(Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue);
|
||||
|
||||
rating.RuleFor(r => r.MaxValue)
|
||||
.GreaterThan(0)
|
||||
.WithError(Errors.Metadata.RatingMaxValueMustBePositive);
|
||||
|
||||
rating.RuleFor(r => r.VoteCount)
|
||||
.GreaterThanOrEqualTo(0)
|
||||
.When(r => r.VoteCount.HasValue)
|
||||
.WithError(Errors.Metadata.RatingVoteCountMustBePositive);
|
||||
});
|
||||
|
||||
// Validates each album created together with the artist, when the request carries albums.
|
||||
RuleFor(command => command.Albums)
|
||||
.NotNull()
|
||||
@@ -72,7 +210,7 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
RuleForEach(command => command.Albums)
|
||||
.ChildRules(album =>
|
||||
{
|
||||
// Validates the metadata of the album: title, lengths, release type and status, and disc and track counts.
|
||||
// Validates the metadata of the album: title, lengths, release types and status, and disc and track counts.
|
||||
album.RuleFor(a => a!.Metadata)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.MetadataCannotBeNull)
|
||||
@@ -95,9 +233,13 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseType)
|
||||
metadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleForEach(m => m!.ReleaseTypes)
|
||||
.IsInEnum()
|
||||
.When(m => m!.ReleaseType is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleaseType);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseStatus)
|
||||
@@ -231,15 +373,20 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the physical characteristics of the album: format and catalog number.
|
||||
// Validates the physical characteristics of the album: format, packaging, catalog number and barcode.
|
||||
album.RuleFor(a => a!.MediaFormat)
|
||||
.IsInEnum()
|
||||
.When(a => a!.MediaFormat is not null)
|
||||
.WithError(Errors.Music.UnknownMusicMediaFormat);
|
||||
|
||||
album.RuleFor(a => a!.CatalogNumber)
|
||||
album.RuleFor(a => a!.Packaging)
|
||||
.IsInEnum()
|
||||
.When(a => a!.Packaging is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleasePackaging);
|
||||
|
||||
album.RuleForEach(a => a!.CatalogNumbers)
|
||||
.MaximumLength(50)
|
||||
.When(a => a!.CatalogNumber is not null)
|
||||
.When(a => a!.CatalogNumbers is not null)
|
||||
.WithError(Errors.Music.CatalogNumberMustBeMaximum50CharactersLong);
|
||||
|
||||
album.RuleFor(a => a!.Barcode)
|
||||
@@ -349,6 +496,11 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.ReleaseInfo)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.ReleaseInfoCannotBeNull)
|
||||
@@ -476,11 +628,6 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(t => t!.MusicBrainzTrackId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
track.RuleFor(t => t!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzWorkId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
track.RuleFor(t => t!.TrackNumber)
|
||||
.NotNull()
|
||||
@@ -511,11 +658,17 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(t => t!.Bpm.HasValue)
|
||||
.WithError(Errors.Music.BpmMustBeGreaterThanZero);
|
||||
|
||||
track.RuleFor(t => t!.Work)
|
||||
// Validates the work the track is a recording of.
|
||||
track.RuleFor(t => t!.Work!.Title)
|
||||
.MaximumLength(255)
|
||||
.When(t => t!.Work is not null)
|
||||
.When(t => t!.Work is not null && t.Work.Title is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
track.RuleFor(t => t!.Work!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId is null || musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.Work is not null)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
track.RuleForEach(t => t!.Moods)
|
||||
.ChildRules(mood =>
|
||||
|
||||
+11
-3
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.AddAlbum;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -14,18 +16,24 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library this artist belongs to, taken from the route.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist, taken from the route.</param>
|
||||
/// <param name="Name">The name of the artist.</param>
|
||||
/// <param name="Metadata">The metadata of the artist.</param>
|
||||
/// <param name="Website">The website of the artist, if applicable.</param>
|
||||
/// <param name="MusicBrainzArtistId">The MusicBrainz identifier of the artist, if applicable.</param>
|
||||
/// <param name="Ipis">The list of IPI codes of the artist.</param>
|
||||
/// <param name="Isnis">The list of ISNI codes of the artist.</param>
|
||||
/// <param name="Contributors">The list of media contributors that make up the artist.</param>
|
||||
/// <param name="Ratings">The list of ratings for the artist.</param>
|
||||
/// <param name="Albums">The list of albums of the artist, each with its own list of tracks.</param>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
[DebuggerDisplay("Name: {Metadata.Name}")]
|
||||
public record UpdateArtistCommand(
|
||||
string? LibraryId,
|
||||
string? ArtistId,
|
||||
string? Name,
|
||||
MusicArtistMetadataDto? Metadata,
|
||||
string? Website,
|
||||
Guid? MusicBrainzArtistId,
|
||||
List<string>? Ipis,
|
||||
List<string>? Isnis,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<AddAlbumCommand>? Albums
|
||||
) : ICommand;
|
||||
+173
-20
@@ -17,7 +17,7 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
/// </summary>
|
||||
public UpdateArtistCommandValidator()
|
||||
{
|
||||
// Validates the identifier of the media library that owns the artist, taken from the route.
|
||||
// Validates the identifier of the media library that will own the artist, taken from the route.
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
@@ -38,13 +38,115 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifying details of the artist.
|
||||
RuleFor(command => command.Name)
|
||||
RuleFor(command => command.Metadata)
|
||||
.NotNull()
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
.WithError(Errors.Metadata.MetadataCannotBeNull)
|
||||
.ChildRules(metadata =>
|
||||
{
|
||||
metadata.RuleFor(m => m!.Name)
|
||||
.NotNull()
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.SortName)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.SortName is not null)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Music.ArtistNameMustBeMaximum255CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.Type)
|
||||
.IsInEnum()
|
||||
.When(m => m!.Type is not null)
|
||||
.WithError(Errors.Music.UnknownMusicArtistType);
|
||||
|
||||
metadata.RuleFor(m => m!.Gender)
|
||||
.IsInEnum()
|
||||
.When(m => m!.Gender is not null)
|
||||
.WithError(Errors.Music.UnknownMusicArtistGender);
|
||||
|
||||
metadata.RuleFor(m => m!.Country)
|
||||
.Length(2)
|
||||
.When(m => m!.Country is not null)
|
||||
.WithError(Errors.Music.CountryMustBeMaximum2CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.Area!.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AreaNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.AreaNameMustBeMaximum255CharactersLong)
|
||||
.When(m => m!.Area is not null);
|
||||
|
||||
metadata.RuleFor(m => m!.BeginArea!.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AreaNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.AreaNameMustBeMaximum255CharactersLong)
|
||||
.When(m => m!.BeginArea is not null);
|
||||
|
||||
metadata.RuleFor(m => m!.EndArea!.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AreaNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.AreaNameMustBeMaximum255CharactersLong)
|
||||
.When(m => m!.EndArea is not null);
|
||||
|
||||
metadata.RuleForEach(m => m!.Aliases)
|
||||
.ChildRules(alias =>
|
||||
{
|
||||
alias.RuleFor(a => a.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistAliasNameCannotBeEmpty)
|
||||
.MaximumLength(255)
|
||||
.WithError(Errors.Music.ArtistAliasNameMustBeMaximum255CharactersLong);
|
||||
|
||||
alias.RuleFor(a => a.SortName)
|
||||
.MaximumLength(255)
|
||||
.When(a => a.SortName is not null)
|
||||
.WithError(Errors.Music.ArtistAliasNameMustBeMaximum255CharactersLong);
|
||||
|
||||
alias.RuleFor(a => a.Type)
|
||||
.MaximumLength(50)
|
||||
.When(a => a.Type is not null)
|
||||
.WithError(Errors.Music.ScriptMustBeMaximum50CharactersLong);
|
||||
|
||||
alias.RuleFor(a => a.Locale)
|
||||
.MaximumLength(20)
|
||||
.When(a => a.Locale is not null)
|
||||
.WithError(Errors.Music.ScriptMustBeMaximum50CharactersLong);
|
||||
});
|
||||
|
||||
metadata.RuleFor(m => m!.Genres)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.GenresListCannotBeNull);
|
||||
|
||||
metadata.RuleForEach(m => m!.Genres)
|
||||
.ChildRules(genre =>
|
||||
genre.RuleFor(g => g.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.GenreNameCannotBeEmpty)
|
||||
.MaximumLength(50)
|
||||
.WithError(Errors.Metadata.GenreNameMustBeMaximum50CharactersLong));
|
||||
|
||||
metadata.RuleFor(m => m!.Tags)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.TagsListCannotBeNull);
|
||||
|
||||
metadata.RuleForEach(m => m!.Tags)
|
||||
.ChildRules(tag =>
|
||||
tag.RuleFor(t => t.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.TagNameCannotBeEmpty)
|
||||
.MaximumLength(50)
|
||||
.WithError(Errors.Metadata.TagNameMustBeMaximum50CharactersLong));
|
||||
});
|
||||
|
||||
// Validates the website and the MusicBrainz identifiers of the artist.
|
||||
RuleFor(command => command.Website)
|
||||
.MaximumLength(2048)
|
||||
.When(command => command.Website is not null)
|
||||
@@ -55,6 +157,18 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(command => command.MusicBrainzArtistId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
RuleForEach(command => command.Ipis)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IpiValueCannotBeEmpty)
|
||||
.MaximumLength(20)
|
||||
.WithError(Errors.Music.IpiValueMustBeMaximum20CharactersLong);
|
||||
|
||||
RuleForEach(command => command.Isnis)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsniValueCannotBeEmpty)
|
||||
.MaximumLength(20)
|
||||
.WithError(Errors.Music.IsniValueMustBeMaximum20CharactersLong);
|
||||
|
||||
// Validates the media contributors that make up the artist.
|
||||
RuleFor(command => command.Contributors)
|
||||
.NotNull()
|
||||
@@ -74,7 +188,31 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.WithError(Errors.MediaContributor.UnknownMediaContributorRole);
|
||||
});
|
||||
|
||||
// Validates each album updated together with the artist, when the request carries albums.
|
||||
// Validates the ratings of the artist.
|
||||
RuleFor(command => command.Ratings)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.RatingsListCannotBeNull);
|
||||
|
||||
RuleForEach(command => command.Ratings)
|
||||
.ChildRules(rating =>
|
||||
{
|
||||
rating.RuleFor(r => r.Value)
|
||||
.GreaterThan(0)
|
||||
.WithError(Errors.Metadata.RatingValueMustBePositive)
|
||||
.Must((ratingInstance, value) => value <= ratingInstance.MaxValue)
|
||||
.WithError(Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue);
|
||||
|
||||
rating.RuleFor(r => r.MaxValue)
|
||||
.GreaterThan(0)
|
||||
.WithError(Errors.Metadata.RatingMaxValueMustBePositive);
|
||||
|
||||
rating.RuleFor(r => r.VoteCount)
|
||||
.GreaterThanOrEqualTo(0)
|
||||
.When(r => r.VoteCount.HasValue)
|
||||
.WithError(Errors.Metadata.RatingVoteCountMustBePositive);
|
||||
});
|
||||
|
||||
// Validates each album created together with the artist, when the request carries albums.
|
||||
RuleFor(command => command.Albums)
|
||||
.NotNull()
|
||||
.WithError(Errors.Music.AlbumsListCannotBeNull);
|
||||
@@ -88,7 +226,7 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(a => a!.AlbumId.HasValue)
|
||||
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
|
||||
|
||||
// Validates the metadata of the album: title, lengths, release type and status, and disc and track counts.
|
||||
// Validates the metadata of the album: title, lengths, release types and status, and disc and track counts.
|
||||
album.RuleFor(a => a!.Metadata)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.MetadataCannotBeNull)
|
||||
@@ -111,9 +249,13 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseType)
|
||||
metadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
metadata.RuleForEach(m => m!.ReleaseTypes)
|
||||
.IsInEnum()
|
||||
.When(m => m!.ReleaseType is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleaseType);
|
||||
|
||||
metadata.RuleFor(m => m!.ReleaseStatus)
|
||||
@@ -247,15 +389,20 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the physical characteristics of the album: format and catalog number.
|
||||
// Validates the physical characteristics of the album: format, packaging, catalog number and barcode.
|
||||
album.RuleFor(a => a!.MediaFormat)
|
||||
.IsInEnum()
|
||||
.When(a => a!.MediaFormat is not null)
|
||||
.WithError(Errors.Music.UnknownMusicMediaFormat);
|
||||
|
||||
album.RuleFor(a => a!.CatalogNumber)
|
||||
album.RuleFor(a => a!.Packaging)
|
||||
.IsInEnum()
|
||||
.When(a => a!.Packaging is not null)
|
||||
.WithError(Errors.Music.UnknownMusicReleasePackaging);
|
||||
|
||||
album.RuleForEach(a => a!.CatalogNumbers)
|
||||
.MaximumLength(50)
|
||||
.When(a => a!.CatalogNumber is not null)
|
||||
.When(a => a!.CatalogNumbers is not null)
|
||||
.WithError(Errors.Music.CatalogNumberMustBeMaximum50CharactersLong);
|
||||
|
||||
album.RuleFor(a => a!.Barcode)
|
||||
@@ -371,6 +518,11 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.ReleaseInfo)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.ReleaseInfoCannotBeNull)
|
||||
@@ -498,11 +650,6 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(t => t!.MusicBrainzTrackId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
track.RuleFor(t => t!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzWorkId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
track.RuleFor(t => t!.TrackNumber)
|
||||
.NotNull()
|
||||
@@ -533,11 +680,17 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(t => t!.Bpm.HasValue)
|
||||
.WithError(Errors.Music.BpmMustBeGreaterThanZero);
|
||||
|
||||
track.RuleFor(t => t!.Work)
|
||||
// Validates the work the track is a recording of.
|
||||
track.RuleFor(t => t!.Work!.Title)
|
||||
.MaximumLength(255)
|
||||
.When(t => t!.Work is not null)
|
||||
.When(t => t!.Work is not null && t.Work.Title is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
track.RuleFor(t => t!.Work!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId is null || musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.Work is not null)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
track.RuleForEach(t => t!.Moods)
|
||||
.ChildRules(mood =>
|
||||
|
||||
+4
-5
@@ -25,30 +25,29 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.
|
||||
/// <param name="Script">The script used by the language of the track, if applicable.</param>
|
||||
/// <param name="Key">The musical key of the track, if applicable.</param>
|
||||
/// <param name="Bpm">The tempo of the track in beats per minute, if applicable.</param>
|
||||
/// <param name="Work">The title of the work the track is a recording of, if applicable.</param>
|
||||
/// <param name="Work">The work the track is a recording of, if applicable.</param>
|
||||
/// <param name="MusicBrainzRecordingId">The MusicBrainz identifier of the recording, if applicable.</param>
|
||||
/// <param name="MusicBrainzTrackId">The MusicBrainz identifier of the track, if applicable.</param>
|
||||
/// <param name="MusicBrainzWorkId">The MusicBrainz identifier of the work, if applicable.</param>
|
||||
/// <param name="Moods">The list of moods of the track.</param>
|
||||
/// <param name="Isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the track.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track.</param>
|
||||
/// <param name="TrackId">The Id of the track, when the track already exists.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record AddTrackCommand(
|
||||
string? LibraryId,
|
||||
string? ArtistId,
|
||||
string? AlbumId,
|
||||
string? Path,
|
||||
AudioMetadataDto? Metadata,
|
||||
MusicTrackMetadataDto? Metadata,
|
||||
int? TrackNumber,
|
||||
int? DiscNumber,
|
||||
string? Script,
|
||||
MusicKey? Key,
|
||||
int? Bpm,
|
||||
string? Work,
|
||||
MusicWorkDto? Work,
|
||||
Guid? MusicBrainzRecordingId,
|
||||
Guid? MusicBrainzTrackId,
|
||||
Guid? MusicBrainzWorkId,
|
||||
List<MoodDto>? Moods,
|
||||
List<IsrcDto>? Isrcs,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
|
||||
+13
-7
@@ -76,6 +76,11 @@ public class AddTrackCommandValidator : AbstractValidator<AddTrackCommand>
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.ReleaseInfo)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.ReleaseInfoCannotBeNull)
|
||||
@@ -203,11 +208,6 @@ public class AddTrackCommandValidator : AbstractValidator<AddTrackCommand>
|
||||
.When(command => command.MusicBrainzTrackId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
RuleFor(command => command.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId != Guid.Empty)
|
||||
.When(command => command.MusicBrainzWorkId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
RuleFor(command => command.TrackNumber)
|
||||
.NotNull()
|
||||
@@ -238,11 +238,17 @@ public class AddTrackCommandValidator : AbstractValidator<AddTrackCommand>
|
||||
.When(command => command.Bpm.HasValue)
|
||||
.WithError(Errors.Music.BpmMustBeGreaterThanZero);
|
||||
|
||||
RuleFor(command => command.Work)
|
||||
// Validates the work the track is a recording of.
|
||||
RuleFor(command => command.Work!.Title)
|
||||
.MaximumLength(255)
|
||||
.When(command => command.Work is not null)
|
||||
.When(command => command.Work is not null && command.Work.Title is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
RuleFor(command => command.Work!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId is null || musicBrainzWorkId != Guid.Empty)
|
||||
.When(command => command.Work is not null)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
RuleForEach(command => command.Moods)
|
||||
.ChildRules(mood =>
|
||||
|
||||
+3
-5
@@ -26,10 +26,9 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.
|
||||
/// <param name="Script">The script used by the language of the track, if applicable.</param>
|
||||
/// <param name="Key">The musical key of the track, if applicable.</param>
|
||||
/// <param name="Bpm">The tempo of the track in beats per minute, if applicable.</param>
|
||||
/// <param name="Work">The title of the work the track is a recording of, if applicable.</param>
|
||||
/// <param name="Work">The work the track is a recording of, if applicable.</param>
|
||||
/// <param name="MusicBrainzRecordingId">The MusicBrainz identifier of the recording, if applicable.</param>
|
||||
/// <param name="MusicBrainzTrackId">The MusicBrainz identifier of the track, if applicable.</param>
|
||||
/// <param name="MusicBrainzWorkId">The MusicBrainz identifier of the work, if applicable.</param>
|
||||
/// <param name="Moods">The list of moods of the track.</param>
|
||||
/// <param name="Isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the track.</param>
|
||||
@@ -41,16 +40,15 @@ public record UpdateTrackCommand(
|
||||
string? AlbumId,
|
||||
string? TrackId,
|
||||
string? Path,
|
||||
AudioMetadataDto? Metadata,
|
||||
MusicTrackMetadataDto? Metadata,
|
||||
int? TrackNumber,
|
||||
int? DiscNumber,
|
||||
string? Script,
|
||||
MusicKey? Key,
|
||||
int? Bpm,
|
||||
string? Work,
|
||||
MusicWorkDto? Work,
|
||||
Guid? MusicBrainzRecordingId,
|
||||
Guid? MusicBrainzTrackId,
|
||||
Guid? MusicBrainzWorkId,
|
||||
List<MoodDto>? Moods,
|
||||
List<IsrcDto>? Isrcs,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
|
||||
+13
-7
@@ -86,6 +86,11 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
||||
.When(m => m!.Description is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.Disambiguation)
|
||||
.MaximumLength(255)
|
||||
.When(m => m!.Disambiguation is not null)
|
||||
.WithError(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong);
|
||||
|
||||
trackMetadata.RuleFor(m => m!.ReleaseInfo)
|
||||
.NotNull()
|
||||
.WithError(Errors.Metadata.ReleaseInfoCannotBeNull)
|
||||
@@ -213,11 +218,6 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
||||
.When(command => command.MusicBrainzTrackId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
RuleFor(command => command.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId != Guid.Empty)
|
||||
.When(command => command.MusicBrainzWorkId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
RuleFor(command => command.TrackNumber)
|
||||
.NotNull()
|
||||
@@ -248,11 +248,17 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
||||
.When(command => command.Bpm.HasValue)
|
||||
.WithError(Errors.Music.BpmMustBeGreaterThanZero);
|
||||
|
||||
RuleFor(command => command.Work)
|
||||
// Validates the work the track is a recording of.
|
||||
RuleFor(command => command.Work!.Title)
|
||||
.MaximumLength(255)
|
||||
.When(command => command.Work is not null)
|
||||
.When(command => command.Work is not null && command.Work.Title is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
RuleFor(command => command.Work!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId is null || musicBrainzWorkId != Guid.Empty)
|
||||
.When(command => command.Work is not null)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
RuleForEach(command => command.Moods)
|
||||
.ChildRules(mood =>
|
||||
|
||||
Reference in new issue
Block a user