Separates application validation errors from domain business rules

Moves the user settings, user id, scheduler display preference and thumbnail quality validation errors to the application error catalogs, leaves only business-rule errors in the domain catalogs, and records the domain-expert test for error ownership.
This commit is contained in:
BinaryAlley committed 2026-11-22 12:00:00 +03:00
1 parent 6e1253d3d5
commit 7f701ea3cc
30 files changed
+311 -273

No files matched your search

@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Errors;
/// <summary>
/// Application scheduling related error types.
/// </summary>
public static partial class Errors
{
/// <summary>
/// Error types for application scheduling operations.
/// </summary>
public static class Scheduling
{
/// <summary>
/// Gets the error that reports that the scheduler display time span must be a positive value.
/// </summary>
public static Error SchedulerDisplayTimeSpanMustBePositive => Error.Validation(description: nameof(SchedulerDisplayTimeSpanMustBePositive));
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Errors;
/// <summary>
/// Application thumbnails related error types.
/// </summary>
public static partial class Errors
{
/// <summary>
/// Error types for application thumbnail operations.
/// </summary>
public static class Thumbnails
{
/// <summary>
/// Gets the error that reports that the image quality must be between 0 and 100.
/// </summary>
public static Error ImageQualityMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(ImageQualityMustBeBetweenZeroAndOneHundred));
}
}
@@ -0,0 +1,167 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Errors;
/// <summary>
/// Application user settings related error types.
/// </summary>
public static partial class Errors
{
/// <summary>
/// Error types for application user settings operations.
/// </summary>
/// <remarks>
/// The playback and VU meter bounds in this catalog are deliberately application-level validation: they constrain the shape and presentation range of the
/// settings a caller submits, not business invariants of the user settings aggregate. A rule that becomes a business invariant must move to the aggregate
/// and its error back to <c>Domain/Common/Errors</c>.
/// </remarks>
public static class UserSettings
{
/// <summary>
/// Gets the error that reports that the number of items shown per page must be greater than zero.
/// </summary>
public static Error ItemsPerPageMustBeGreaterThanZero => Error.Validation(description: nameof(ItemsPerPageMustBeGreaterThanZero));
/// <summary>
/// Gets the error that reports that the playback volume cannot be <see langword="null"/>.
/// </summary>
public static Error VolumeCannotBeNull => Error.Validation(description: nameof(VolumeCannotBeNull));
/// <summary>
/// Gets the error that reports that the playback volume must be between 0 and 1, inclusive.
/// </summary>
public static Error VolumeMustBeBetweenZeroAndOne => Error.Validation(description: nameof(VolumeMustBeBetweenZeroAndOne));
/// <summary>
/// Gets the error that reports that the mute state cannot be <see langword="null"/>.
/// </summary>
public static Error IsMutedCannotBeNull => Error.Validation(description: nameof(IsMutedCannotBeNull));
/// <summary>
/// Gets the error that reports that the option to keep downloading while playback is paused cannot be <see langword="null"/>.
/// </summary>
public static Error ShouldKeepDownloadingWhilePausedCannotBeNull => Error.Validation(description: nameof(ShouldKeepDownloadingWhilePausedCannotBeNull));
/// <summary>
/// Gets the error that reports that the autoplay option cannot be <see langword="null"/>.
/// </summary>
public static Error ShouldAutoplayCannotBeNull => Error.Validation(description: nameof(ShouldAutoplayCannotBeNull));
/// <summary>
/// Gets the error that reports that the gapless playback option cannot be <see langword="null"/>.
/// </summary>
public static Error IsGaplessPlaybackEnabledCannotBeNull => Error.Validation(description: nameof(IsGaplessPlaybackEnabledCannotBeNull));
/// <summary>
/// Gets the error that reports that the replay gain mode cannot be <see langword="null"/>.
/// </summary>
public static Error ReplayGainModeCannotBeNull => Error.Validation(description: nameof(ReplayGainModeCannotBeNull));
/// <summary>
/// Gets the error that reports that the streaming quality cannot be <see langword="null"/>.
/// </summary>
public static Error StreamingQualityCannotBeNull => Error.Validation(description: nameof(StreamingQualityCannotBeNull));
/// <summary>
/// Gets the error that reports that the replay gain mode is not a recognized value.
/// </summary>
public static Error InvalidReplayGainMode => Error.Validation(description: nameof(InvalidReplayGainMode));
/// <summary>
/// Gets the error that reports that the streaming quality is not a recognized value.
/// </summary>
public static Error InvalidStreamingQuality => Error.Validation(description: nameof(InvalidStreamingQuality));
/// <summary>
/// Gets the error that reports that the VU meter orientation cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterOrientationCannotBeNull => Error.Validation(description: nameof(VuMeterOrientationCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter orientation is not a recognized value.
/// </summary>
public static Error InvalidVuMeterOrientation => Error.Validation(description: nameof(InvalidVuMeterOrientation));
/// <summary>
/// Gets the error that reports that the VU meter segment count cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterSegmentCountCannotBeNull => Error.Validation(description: nameof(VuMeterSegmentCountCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter segment count must be between 1 and 128, inclusive.
/// </summary>
public static Error VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight => Error.Validation(description: nameof(VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight));
/// <summary>
/// Gets the error that reports that the VU meter segment gap cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterSegmentGapCannotBeNull => Error.Validation(description: nameof(VuMeterSegmentGapCannotBeNull));
/// <summary>
/// Gets the error that reports that the gap between the VU meter segments, in pixels, must be between 0 and 32, inclusive.
/// </summary>
public static Error VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo => Error.Validation(description: nameof(VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo));
/// <summary>
/// Gets the error that reports that the VU meter medium threshold cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterMediumThresholdCannotBeNull => Error.Validation(description: nameof(VuMeterMediumThresholdCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter medium threshold must be between 0 and 1, inclusive.
/// </summary>
public static Error VuMeterMediumThresholdMustBeBetweenZeroAndOne => Error.Validation(description: nameof(VuMeterMediumThresholdMustBeBetweenZeroAndOne));
/// <summary>
/// Gets the error that reports that the VU meter high threshold cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterHighThresholdCannotBeNull => Error.Validation(description: nameof(VuMeterHighThresholdCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter high threshold must be between 0 and 1, inclusive.
/// </summary>
public static Error VuMeterHighThresholdMustBeBetweenZeroAndOne => Error.Validation(description: nameof(VuMeterHighThresholdMustBeBetweenZeroAndOne));
/// <summary>
/// Gets the error that reports that the VU meter high threshold is lower than its medium threshold.
/// </summary>
public static Error VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold => Error.Validation(description: nameof(VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold));
/// <summary>
/// Gets the error that reports that the option to show the VU meter peak cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterShowPeakCannotBeNull => Error.Validation(description: nameof(VuMeterShowPeakCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter peak hold duration cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterPeakHoldDurationCannotBeNull => Error.Validation(description: nameof(VuMeterPeakHoldDurationCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter peak hold duration, in milliseconds, must be between 0 and 10000, inclusive.
/// </summary>
public static Error VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds => Error.Validation(description: nameof(VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds));
/// <summary>
/// Gets the error that reports that the VU meter release rate per second cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterReleasePerSecondCannotBeNull => Error.Validation(description: nameof(VuMeterReleasePerSecondCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter release rate per second must be between 0 and 100, inclusive.
/// </summary>
public static Error VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred));
/// <summary>
/// Gets the error that reports that the VU meter peak release rate per second cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterPeakReleasePerSecondCannotBeNull => Error.Validation(description: nameof(VuMeterPeakReleasePerSecondCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter peak release rate per second must be between 0 and 100, inclusive.
/// </summary>
public static Error VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred));
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Errors;
/// <summary>
/// Application users related error types.
/// </summary>
public static partial class Errors
{
/// <summary>
/// Error types for application user operations.
/// </summary>
public static class Users
{
/// <summary>
/// Gets the error that reports that the user identifier cannot be empty.
/// </summary>
public static Error UserIdCannotBeEmpty => Error.Validation(description: nameof(UserIdCannotBeEmpty));
}
}
@@ -1,7 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
@@ -18,10 +19,10 @@ public class GetThumbnailQueryValidator : AbstractValidator<GetThumbnailQuery>
{
RuleFor(query => query.Path)
.NotEmpty()
.WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
.WithError(DomainErrors.FileSystemManagement.PathCannotBeEmpty);
RuleFor(query => query.Quality)
.InclusiveBetween(0, 100)
.WithError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
.WithError(ApplicationErrors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.Scheduling.Commands.UpdateSchedulerDisplayPreferences;
@@ -3,7 +3,6 @@ using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using System;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
@@ -20,9 +19,9 @@ public class UpdateUserRoleAndPermissionsCommandValidator : AbstractValidator<Up
{
RuleFor(command => command.UserId)
.NotEmpty()
.WithError(DomainErrors.Users.UserIdCannotBeEmpty)
.WithError(ApplicationErrors.Users.UserIdCannotBeEmpty)
.Must(id => id != Guid.Empty)
.WithError(DomainErrors.Users.UserIdCannotBeEmpty);
.WithError(ApplicationErrors.Users.UserIdCannotBeEmpty);
// Validate each permission Id when the list is provided.
RuleForEach(command => command.Permissions)
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.UsersManagement.Settings.Commands.UpdatePlaybackState;
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.UsersManagement.Settings.Commands.UpdateUserSettings;
@@ -78,10 +78,5 @@ public static partial class Errors
/// Gets the error that reports that the schedule type is not a defined value.
/// </summary>
public static Error InvalidScheduleType => Error.Validation(description: nameof(InvalidScheduleType));
/// <summary>
/// Gets the error that reports that the scheduler display time span must be a positive value.
/// </summary>
public static Error SchedulerDisplayTimeSpanMustBePositive => Error.Validation(description: nameof(SchedulerDisplayTimeSpanMustBePositive));
}
}
@@ -18,10 +18,5 @@ public static partial class Errors
/// Gets the error that reports that no thumbnail is available for the requested media item.
/// </summary>
public static Error NoThumbnail => Error.Failure(description: nameof(NoThumbnail));
/// <summary>
/// Gets the error that reports that the image quality must be between 0 and 100.
/// </summary>
public static Error ImageQualityMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(ImageQualityMustBeBetweenZeroAndOneHundred));
}
}
@@ -23,150 +23,5 @@ public static partial class Errors
/// Gets the error that reports that no settings exist for the requested user.
/// </summary>
public static Error UserSettingsNotFound => Error.NotFound(description: nameof(UserSettingsNotFound));
/// <summary>
/// Gets the error that reports that the number of items shown per page must be greater than zero.
/// </summary>
public static Error ItemsPerPageMustBeGreaterThanZero => Error.Validation(description: nameof(ItemsPerPageMustBeGreaterThanZero));
/// <summary>
/// Gets the error that reports that the playback volume cannot be <see langword="null"/>.
/// </summary>
public static Error VolumeCannotBeNull => Error.Validation(description: nameof(VolumeCannotBeNull));
/// <summary>
/// Gets the error that reports that the playback volume must be between 0 and 1, inclusive.
/// </summary>
public static Error VolumeMustBeBetweenZeroAndOne => Error.Validation(description: nameof(VolumeMustBeBetweenZeroAndOne));
/// <summary>
/// Gets the error that reports that the mute state cannot be <see langword="null"/>.
/// </summary>
public static Error IsMutedCannotBeNull => Error.Validation(description: nameof(IsMutedCannotBeNull));
/// <summary>
/// Gets the error that reports that the option to keep downloading while playback is paused cannot be <see langword="null"/>.
/// </summary>
public static Error ShouldKeepDownloadingWhilePausedCannotBeNull => Error.Validation(description: nameof(ShouldKeepDownloadingWhilePausedCannotBeNull));
/// <summary>
/// Gets the error that reports that the autoplay option cannot be <see langword="null"/>.
/// </summary>
public static Error ShouldAutoplayCannotBeNull => Error.Validation(description: nameof(ShouldAutoplayCannotBeNull));
/// <summary>
/// Gets the error that reports that the gapless playback option cannot be <see langword="null"/>.
/// </summary>
public static Error IsGaplessPlaybackEnabledCannotBeNull => Error.Validation(description: nameof(IsGaplessPlaybackEnabledCannotBeNull));
/// <summary>
/// Gets the error that reports that the replay gain mode cannot be <see langword="null"/>.
/// </summary>
public static Error ReplayGainModeCannotBeNull => Error.Validation(description: nameof(ReplayGainModeCannotBeNull));
/// <summary>
/// Gets the error that reports that the streaming quality cannot be <see langword="null"/>.
/// </summary>
public static Error StreamingQualityCannotBeNull => Error.Validation(description: nameof(StreamingQualityCannotBeNull));
/// <summary>
/// Gets the error that reports that the replay gain mode is not a recognized value.
/// </summary>
public static Error InvalidReplayGainMode => Error.Validation(description: nameof(InvalidReplayGainMode));
/// <summary>
/// Gets the error that reports that the streaming quality is not a recognized value.
/// </summary>
public static Error InvalidStreamingQuality => Error.Validation(description: nameof(InvalidStreamingQuality));
/// <summary>
/// Gets the error that reports that the VU meter orientation cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterOrientationCannotBeNull => Error.Validation(description: nameof(VuMeterOrientationCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter orientation is not a recognized value.
/// </summary>
public static Error InvalidVuMeterOrientation => Error.Validation(description: nameof(InvalidVuMeterOrientation));
/// <summary>
/// Gets the error that reports that the VU meter segment count cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterSegmentCountCannotBeNull => Error.Validation(description: nameof(VuMeterSegmentCountCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter segment count must be between 1 and 128, inclusive.
/// </summary>
public static Error VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight => Error.Validation(description: nameof(VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight));
/// <summary>
/// Gets the error that reports that the VU meter segment gap cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterSegmentGapCannotBeNull => Error.Validation(description: nameof(VuMeterSegmentGapCannotBeNull));
/// <summary>
/// Gets the error that reports that the gap between the VU meter segments, in pixels, must be between 0 and 32, inclusive.
/// </summary>
public static Error VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo => Error.Validation(description: nameof(VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo));
/// <summary>
/// Gets the error that reports that the VU meter medium threshold cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterMediumThresholdCannotBeNull => Error.Validation(description: nameof(VuMeterMediumThresholdCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter medium threshold must be between 0 and 1, inclusive.
/// </summary>
public static Error VuMeterMediumThresholdMustBeBetweenZeroAndOne => Error.Validation(description: nameof(VuMeterMediumThresholdMustBeBetweenZeroAndOne));
/// <summary>
/// Gets the error that reports that the VU meter high threshold cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterHighThresholdCannotBeNull => Error.Validation(description: nameof(VuMeterHighThresholdCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter high threshold must be between 0 and 1, inclusive.
/// </summary>
public static Error VuMeterHighThresholdMustBeBetweenZeroAndOne => Error.Validation(description: nameof(VuMeterHighThresholdMustBeBetweenZeroAndOne));
/// <summary>
/// Gets the error that reports that the VU meter high threshold is lower than its medium threshold.
/// </summary>
public static Error VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold => Error.Validation(description: nameof(VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold));
/// <summary>
/// Gets the error that reports that the option to show the VU meter peak cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterShowPeakCannotBeNull => Error.Validation(description: nameof(VuMeterShowPeakCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter peak hold duration cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterPeakHoldDurationCannotBeNull => Error.Validation(description: nameof(VuMeterPeakHoldDurationCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter peak hold duration, in milliseconds, must be between 0 and 10000, inclusive.
/// </summary>
public static Error VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds => Error.Validation(description: nameof(VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds));
/// <summary>
/// Gets the error that reports that the VU meter release rate per second cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterReleasePerSecondCannotBeNull => Error.Validation(description: nameof(VuMeterReleasePerSecondCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter release rate per second must be between 0 and 100, inclusive.
/// </summary>
public static Error VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred));
/// <summary>
/// Gets the error that reports that the VU meter peak release rate per second cannot be <see langword="null"/>.
/// </summary>
public static Error VuMeterPeakReleasePerSecondCannotBeNull => Error.Validation(description: nameof(VuMeterPeakReleasePerSecondCannotBeNull));
/// <summary>
/// Gets the error that reports that the VU meter peak release rate per second must be between 0 and 100, inclusive.
/// </summary>
public static Error VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred));
}
}
@@ -23,10 +23,5 @@ public static partial class Errors
/// Gets the error that reports that the requested user does not exist.
/// </summary>
public static Error UserDoesNotExist => Error.NotFound(description: nameof(UserDoesNotExist));
/// <summary>
/// Gets the error that reports that the user identifier cannot be empty.
/// </summary>
public static Error UserIdCannotBeEmpty => Error.Validation(description: nameof(UserIdCannotBeEmpty));
}
}