diff --git a/src/Lumina.Application/Common/Behaviors/ValidationBehavior.cs b/src/Lumina.Application/Common/Behaviors/ValidationBehavior.cs
deleted file mode 100644
index de644cc6..00000000
--- a/src/Lumina.Application/Common/Behaviors/ValidationBehavior.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using FluentValidation;
-using Mediator;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-#endregion
-
-namespace Lumina.Application.Common.Behaviors;
-
-///
-/// Represents a validation behavior in the Mediator pipeline for handling requests and responses.
-///
-/// The type representing a request. It should implement .
-/// The type representing a response. It should implement interface.
-public class ValidationBehavior : IPipelineBehavior where TRequest : IRequest
- where TResponse : IErrorOr
-{
- private readonly IValidator? _validator;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The validator used in this behavior pipeline for the Mediator commands and queries.
- public ValidationBehavior(IValidator? validator = null)
- {
- _validator = validator;
- }
-
- ///
- /// Pipeline handler. Perform any additional behavior and await the delegate as necessary.
- ///
- /// Incoming request.
- /// Awaitable delegate for the next action in the pipeline. Eventually this delegate represents the handler.
- /// Cancellation token that can be used to stop the execution.
- public async ValueTask Handle(TRequest request, MessageHandlerDelegate next, CancellationToken cancellationToken)
- {
- // if there is no validator, just invoke the handler
- if (_validator is null)
- return await next(request, cancellationToken).ConfigureAwait(false);
- // before the handler of the command is executed
- FluentValidation.Results.ValidationResult validationResult = await _validator.ValidateAsync(request, cancellationToken).ConfigureAwait(false);
- // if there are no validation errors, invoke the command handler
- if (validationResult.IsValid)
- return await next(request, cancellationToken).ConfigureAwait(false);
- // after the command handler is executed
- List errors = validationResult.Errors.ConvertAll(validationFailure => Error.Validation(description: validationFailure.ErrorMessage));
- // the compiler doesn't know there is an implicit converter from a list of errors to the ErrorOr object, and unfortunately, there is no way around this but to use some magic
- // this is acceptable because we DO know that we will always have a list of errors of type ErrorOr (check the generic constraint at the top of the class!)
- return (dynamic)errors;
- }
-}
diff --git a/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs
index 2887a02b..4b6c6e71 100644
--- a/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs
+++ b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs
@@ -1,7 +1,4 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
-using Lumina.Application.Common.Behaviors;
-using Mediator;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
@@ -25,44 +22,39 @@ public static class ApplicationLayerServices
/// The updated .
public static IServiceCollection AddApplicationLayerServices(this IServiceCollection services)
{
- // register Mediator
+ // register the Mediator publisher used for publishing domain events
services.AddMediator(options =>
{
options.ServiceLifetime = ServiceLifetime.Scoped;
});
- // register the validation behavior
- services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
-
- // register fluent validators
- services.AddValidatorsFromAssembly(typeof(ApplicationLayerServices).Assembly);
-
- Type[] handlers =
+ Type[] handlerContractTypes =
[
typeof(CQRS.ICommandHandler<,>),
typeof(CQRS.IQueryHandler<,>),
typeof(Infrastructure.Validation.IValidator<>),
];
- IEnumerable types = Assembly.GetExecutingAssembly()
- .GetTypes()
- .Where(type => !type.IsInterface && !type.IsAbstract);
+ IEnumerable concreteTypes = Assembly.GetExecutingAssembly()
+ .GetTypes()
+ .Where(type => !type.IsInterface && !type.IsAbstract && !type.IsGenericTypeDefinition);
- var registrations = types
- .SelectMany(type => type.GetInterfaces(),
- (implementation, service) => new { Service = service, Implmentation = implementation })
- .Where(type => type.Service.IsGenericType && handlers.Contains(type.Service.GetGenericTypeDefinition()));
+ var handlerRegistrations = concreteTypes
+ .SelectMany(implementation => implementation.GetInterfaces(),
+ (implementation, contract) => new { Contract = contract, Implementation = implementation })
+ .Where(registration => registration.Contract.IsGenericType && handlerContractTypes.Contains(registration.Contract.GetGenericTypeDefinition()));
- foreach (var registration in registrations)
+ foreach (var registration in handlerRegistrations)
{
- if (!services.Any(service => service.ServiceType == registration.Service))
- {
- if (registration.Service.GetGenericTypeDefinition() == typeof(Infrastructure.Validation.IValidator<>))
- services.AddSingleton(registration.Service, registration.Implmentation);
- else
- services.AddScoped(registration.Service, registration.Implmentation);
- }
+ if (services.Any(service => service.ServiceType == registration.Contract))
+ continue;
+
+ if (registration.Contract.GetGenericTypeDefinition() == typeof(Infrastructure.Validation.IValidator<>))
+ services.AddSingleton(registration.Contract, registration.Implementation);
+ else
+ services.AddScoped(registration.Contract, registration.Implementation);
}
+
return services;
}
}
diff --git a/src/Lumina.Application/Common/Infrastructure/Validation/AbstractValidator.cs b/src/Lumina.Application/Common/Infrastructure/Validation/AbstractValidator.cs
index 275cc1a7..cb40c867 100644
--- a/src/Lumina.Application/Common/Infrastructure/Validation/AbstractValidator.cs
+++ b/src/Lumina.Application/Common/Infrastructure/Validation/AbstractValidator.cs
@@ -20,7 +20,7 @@ public abstract class AbstractValidator : IValidator
/// The type of the property being validated.
/// A function that selects the property to validate from the request instance.
/// An instance to configure the rule fluently.
- protected IRuleBuilder RuleFor(Func propertySelector)
+ public IRuleBuilder RuleFor(Func propertySelector)
{
ValidationRule rule = new(propertySelector);
_rules.Add(rule);
@@ -33,7 +33,7 @@ public abstract class AbstractValidator : IValidator
/// The type of the items in the collection being validated.
/// A function that selects the collection to validate from the request instance.
/// An instance to configure the per-item rule fluently.
- protected IRuleBuilder RuleForEach(Func?> collectionSelector)
+ public IRuleBuilder RuleForEach(Func?> collectionSelector)
{
ValidationRuleForEach rule = new(collectionSelector);
_rules.Add(rule);
diff --git a/src/Lumina.Application/Common/Infrastructure/Validation/IRuleBuilder.cs b/src/Lumina.Application/Common/Infrastructure/Validation/IRuleBuilder.cs
index 8da4fcfb..771dcf73 100644
--- a/src/Lumina.Application/Common/Infrastructure/Validation/IRuleBuilder.cs
+++ b/src/Lumina.Application/Common/Infrastructure/Validation/IRuleBuilder.cs
@@ -19,6 +19,13 @@ public interface IRuleBuilder
/// The current instance for method chaining.
IRuleBuilder Must(Func predicate);
+ ///
+ /// Specifies a condition that both the request instance and the property value must satisfy to be considered valid.
+ ///
+ /// A function to test the request instance together with the property value.
+ /// The current instance for method chaining.
+ IRuleBuilder Must(Func predicate);
+
///
/// Specifies a condition that must be met for the validation rule to be executed.
///
@@ -32,4 +39,11 @@ public interface IRuleBuilder
/// The specific error to return upon failure.
/// The current instance for method chaining.
IRuleBuilder WithError(Error error);
+
+ ///
+ /// Defines nested validation rules for the complex property being validated.
+ ///
+ /// An action used to configure the inline validator for the property.
+ /// The current instance for method chaining.
+ IRuleBuilder ChildRules(Action> configure);
}
diff --git a/src/Lumina.Application/Common/Infrastructure/Validation/InlineValidator.cs b/src/Lumina.Application/Common/Infrastructure/Validation/InlineValidator.cs
new file mode 100644
index 00000000..0a58b385
--- /dev/null
+++ b/src/Lumina.Application/Common/Infrastructure/Validation/InlineValidator.cs
@@ -0,0 +1,12 @@
+#region ========================================================================= USING =====================================================================================
+#endregion
+
+namespace Lumina.Application.Common.Infrastructure.Validation;
+
+///
+/// Concrete used to declare validation rules inline for nested complex properties.
+///
+/// The type of the request (command or query) to be validated.
+public class InlineValidator : AbstractValidator
+{
+}
diff --git a/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRule.cs b/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRule.cs
index bc9352f8..fc07a557 100644
--- a/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRule.cs
+++ b/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRule.cs
@@ -14,10 +14,28 @@ namespace Lumina.Application.Common.Infrastructure.Validation;
internal sealed class ValidationRule : IValidationRule, IRuleBuilder
{
private readonly Func _propertySelector;
+
+ // Predicates and their errors are kept in two parallel lists (rather than a single list of tuples)
+ // so that Must() can append cheaply and WithError() can patch the *last* entry by index, without
+ // having to rebuild a composite struct each time.
private readonly List> _predicates = [];
- private Error error = Error.Validation();
+ private readonly List _predicateErrors = [];
+
+ // instance-aware predicates get their own separate pair of lists instead of being merged into the
+ // lists above, because they have a different delegate signature (TRequest, TProperty) vs (TProperty).
+ // Keeping them separate avoids wrapping every plain predicate in an adapter, just to fit one shape.
+ private readonly List> _instanceAwarePredicates = [];
+ private readonly List _instanceAwarePredicateErrors = [];
+
+ private Error currentError = Error.Validation();
private Func? condition;
+ // Tracks which list WithError() should patch, since it doesn't know on its own whether the
+ // most recent Must() call went to the plain-predicate list or the instance-aware list.
+ private bool lastAddedPredicateIsInstanceAware;
+
+ private AbstractValidator? _childValidator;
+
///
/// Initializes a new instance of the class.
///
@@ -35,6 +53,25 @@ internal sealed class ValidationRule : IValidationRule Must(Func predicate)
{
_predicates.Add(predicate);
+ // Every predicate is paired with whatever error is "current" at the time it's added, so that a
+ // subsequent WithError() call has something concrete to overwrite via index lookup.
+ _predicateErrors.Add(currentError);
+ lastAddedPredicateIsInstanceAware = false;
+ return this;
+ }
+
+ ///
+ /// Adds a condition that the request instance together with the property must satisfy to be considered valid.
+ ///
+ /// A function to test the request instance together with the property value.
+ /// The current instance for method chaining.
+ public IRuleBuilder Must(Func predicate)
+ {
+ // This overload exists for cross-field rules (e.g. "EndDate must be after StartDate") where
+ // the check can't be expressed from the property value alone and needs the whole request.
+ _instanceAwarePredicates.Add(predicate);
+ _instanceAwarePredicateErrors.Add(currentError);
+ lastAddedPredicateIsInstanceAware = true;
return this;
}
@@ -56,7 +93,35 @@ internal sealed class ValidationRule : IValidationRuleThe current instance for method chaining.
public IRuleBuilder WithError(Error error)
{
- this.error = error;
+ // Callers might pass in an error created with the wrong factory (e.g. Error.NotFound()) by mistake.
+ // Rebuilding it as Error.Validation() here guarantees every error surfaced by this class is
+ // consistently typed as a validation error, regardless of what the caller supplied.
+ Error validationError = Error.Validation(description: error.Description);
+ currentError = validationError;
+
+ // WithError() is meant to apply to the predicate that was *just* added via Must(), not to all
+ // predicates registered so far. Since Must() can target either parallel-list pair, we use the
+ // flag set by the last Must() call to figure out which list's last slot to overwrite.
+ if (lastAddedPredicateIsInstanceAware && _instanceAwarePredicateErrors.Count > 0)
+ _instanceAwarePredicateErrors[^1] = validationError;
+ else if (!lastAddedPredicateIsInstanceAware && _predicateErrors.Count > 0)
+ _predicateErrors[^1] = validationError;
+ return this;
+ }
+
+ ///
+ /// Defines nested validation rules for the complex property being validated.
+ ///
+ /// An action used to configure the inline validator for the property.
+ /// The current instance for method chaining.
+ public IRuleBuilder ChildRules(Action> configure)
+ {
+ // Lets a rule delegate to a fully separate validator for a complex nested object (e.g. validating
+ // an Address property's own fields) instead of forcing every nested check to be flattened into
+ // Must() predicates on this rule.
+ InlineValidator childValidator = new();
+ configure(childValidator);
+ _childValidator = childValidator;
return this;
}
@@ -64,7 +129,7 @@ internal sealed class ValidationRule : IValidationRule
/// The request instance to validate.
- /// The if any predicate fails; empty if the rule passes.
+ /// The of every predicate that fails; empty if the rule passes.
public IEnumerable Validate(TRequest instance)
{
// evaluate the condition first, if it returns false, skip validation entirely.
@@ -73,13 +138,19 @@ internal sealed class ValidationRule : IValidationRule predicate in _predicates)
- {
- if (!predicate(value))
- {
- yield return error;
- yield break;
- }
- }
+ // Deliberately does NOT stop at the first failure: every failing predicate contributes its own error,
+ // so a caller sees the full set of problems for // this property in one pass instead of having to fix
+ // and resubmit one error at a time.
+ for (int index = 0; index < _predicates.Count; index++)
+ if (!_predicates[index](value))
+ yield return _predicateErrors[index];
+
+ for (int index = 0; index < _instanceAwarePredicates.Count; index++)
+ if (!_instanceAwarePredicates[index](instance, value))
+ yield return _instanceAwarePredicateErrors[index];
+
+ if (_childValidator is not null && value is not null)
+ foreach (Error childError in _childValidator.Validate(value))
+ yield return childError;
}
}
diff --git a/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRuleForEach.cs b/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRuleForEach.cs
index 560b2712..4a5e08cc 100644
--- a/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRuleForEach.cs
+++ b/src/Lumina.Application/Common/Infrastructure/Validation/ValidationRuleForEach.cs
@@ -15,8 +15,13 @@ internal sealed class ValidationRuleForEach : IValidationRule?> _collectionSelector;
private readonly List> _predicates = [];
- private Error error = Error.Validation();
+ private readonly List _predicateErrors = [];
+ private readonly List> _instanceAwarePredicates = [];
+ private readonly List _instanceAwarePredicateErrors = [];
+ private Error currentError = Error.Validation();
private Func? condition;
+ private bool lastAddedPredicateIsInstanceAware;
+ private AbstractValidator? _childValidator;
///
/// Initializes a new instance of the class.
@@ -35,6 +40,21 @@ internal sealed class ValidationRuleForEach : IValidationRule Must(Func predicate)
{
_predicates.Add(predicate);
+ _predicateErrors.Add(currentError);
+ lastAddedPredicateIsInstanceAware = false;
+ return this;
+ }
+
+ ///
+ /// Adds a condition that the request instance together with each item must satisfy to be considered valid.
+ ///
+ /// A function to test the request instance together with each item value.
+ /// The current instance for method chaining.
+ public IRuleBuilder Must(Func predicate)
+ {
+ _instanceAwarePredicates.Add(predicate);
+ _instanceAwarePredicateErrors.Add(currentError);
+ lastAddedPredicateIsInstanceAware = true;
return this;
}
@@ -56,7 +76,26 @@ internal sealed class ValidationRuleForEach : IValidationRuleThe current instance for method chaining.
public IRuleBuilder WithError(Error error)
{
- this.error = error;
+ // validation rules always produce validation errors, regardless of the error type of the source error
+ Error validationError = Error.Validation(description: error.Description);
+ currentError = validationError;
+ if (lastAddedPredicateIsInstanceAware && _instanceAwarePredicateErrors.Count > 0)
+ _instanceAwarePredicateErrors[^1] = validationError;
+ else if (!lastAddedPredicateIsInstanceAware && _predicateErrors.Count > 0)
+ _predicateErrors[^1] = validationError;
+ return this;
+ }
+
+ ///
+ /// Defines nested validation rules for each item of the collection being validated.
+ ///
+ /// An action used to configure the inline validator for each item.
+ /// The current instance for method chaining.
+ public IRuleBuilder ChildRules(Action> configure)
+ {
+ InlineValidator childValidator = new();
+ configure(childValidator);
+ _childValidator = childValidator;
return this;
}
@@ -64,7 +103,7 @@ internal sealed class ValidationRuleForEach : IValidationRule
/// The request instance to validate.
- /// One per item that fails a predicate; empty if every item passes.
+ /// One per failing predicate, per item; empty if every item passes.
public IEnumerable Validate(TRequest instance)
{
// evaluate the condition first, if it returns false, skip validation entirely.
@@ -77,14 +116,17 @@ internal sealed class ValidationRuleForEach : IValidationRule predicate in _predicates)
- {
- if (!predicate(item))
- {
- yield return error;
- break;
- }
- }
+ for (int index = 0; index < _predicates.Count; index++)
+ if (!_predicates[index](item))
+ yield return _predicateErrors[index];
+
+ for (int index = 0; index < _instanceAwarePredicates.Count; index++)
+ if (!_instanceAwarePredicates[index](instance, item))
+ yield return _instanceAwarePredicateErrors[index];
+
+ if (_childValidator is not null && item is not null)
+ foreach (Error childError in _childValidator.Validate(item))
+ yield return childError;
}
}
}
diff --git a/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs b/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs
index 42b96f5f..86912552 100644
--- a/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs
+++ b/src/Lumina.Application/Common/Utilities/ValidatorUtilities.cs
@@ -1,7 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using System;
-using System.Collections.Generic;
+using System.Collections;
+using System.Text.RegularExpressions;
#endregion
namespace Lumina.Application.Common.Utilities;
@@ -38,6 +39,33 @@ public static class ValidatorUtilities
return ruleBuilder.Must(value => !value.HasValue || value.Value > valueToCompare);
}
+ ///
+ /// Defines a validation rule that ensures the decimal property is greater than the specified value.
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The value that the property must be greater than.
+ /// The current instance for method chaining.
+ public static IRuleBuilder GreaterThan(this IRuleBuilder ruleBuilder, decimal valueToCompare)
+ {
+ return ruleBuilder.Must(value => value > valueToCompare);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the nullable decimal property is greater than the specified value.
+ ///
+ ///
+ /// If the property is , this rule passes (use to check for missing values).
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The value that the property must be greater than.
+ /// The current instance for method chaining.
+ public static IRuleBuilder GreaterThan(this IRuleBuilder ruleBuilder, decimal valueToCompare)
+ {
+ return ruleBuilder.Must(value => !value.HasValue || value.Value > valueToCompare);
+ }
+
///
/// Defines a validation rule that ensures the time span property is greater than the specified value.
///
@@ -50,13 +78,54 @@ public static class ValidatorUtilities
return ruleBuilder.Must(value => value > valueToCompare);
}
+ ///
+ /// Defines a validation rule that ensures the integer property is greater than or equal to the specified value.
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The value that the property must be greater than or equal to.
+ /// The current instance for method chaining.
+ public static IRuleBuilder GreaterThanOrEqualTo(this IRuleBuilder ruleBuilder, int valueToCompare)
+ {
+ return ruleBuilder.Must(value => value >= valueToCompare);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the nullable integer property is greater than or equal to the specified value.
+ ///
+ ///
+ /// If the property is , this rule passes.
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The value that the property must be greater than or equal to.
+ /// The current instance for method chaining.
+ public static IRuleBuilder GreaterThanOrEqualTo(this IRuleBuilder ruleBuilder, int valueToCompare)
+ {
+ return ruleBuilder.Must(value => !value.HasValue || value.Value >= valueToCompare);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the nullable decimal property is greater than or equal to the specified value.
+ ///
+ ///
+ /// If the property is , this rule passes.
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The value that the property must be greater than or equal to.
+ /// The current instance for method chaining.
+ public static IRuleBuilder GreaterThanOrEqualTo(this IRuleBuilder ruleBuilder, decimal valueToCompare)
+ {
+ return ruleBuilder.Must(value => !value.HasValue || value.Value >= valueToCompare);
+ }
+
///
/// Defines a validation rule that ensures the property is not .
///
///
/// This rule checks reference/nullable-value nullness only. Combine with
- /// or
- /// to also reject empty values.
+ /// to also reject empty values.
///
/// The type of the request being validated.
/// The type of the property being validated.
@@ -68,43 +137,27 @@ public static class ValidatorUtilities
}
///
- /// Defines a validation rule that ensures the string property is not empty or consisting only of white-space characters.
+ /// Defines a validation rule that ensures the property is not empty.
///
///
- /// If the property is , this rule passes (use to check for missing values).
+ /// This rule is type-aware: a is checked for white-space only content, a
+ /// is checked against , and any is checked for having at least
+ /// one item. If the property is , this rule fails.
///
/// The type of the request being validated.
+ /// The type of the property being validated.
/// The rule builder instance.
/// The current instance for method chaining.
- public static IRuleBuilder NotEmpty(this IRuleBuilder ruleBuilder)
+ public static IRuleBuilder NotEmpty(this IRuleBuilder ruleBuilder)
{
- return ruleBuilder.Must(value => value is null || value.Trim().Length > 0);
- }
-
- ///
- /// Defines a validation rule that ensures the List property is not empty.
- ///
- ///
- /// If the property is , this rule passes (use to check for missing values).
- ///
- /// The type of the request being validated.
- /// The type of the items in the list being validated.
- /// The rule builder instance.
- /// The current instance for method chaining.
- public static IRuleBuilder> NotEmpty(this IRuleBuilder> ruleBuilder)
- {
- return ruleBuilder.Must(value => value is null || value.Count > 0);
- }
-
- ///
- /// Defines a validation rule that ensures the property is not .
- ///
- /// The type of the request being validated.
- /// The rule builder instance.
- /// The current instance for method chaining.
- public static IRuleBuilder NotEmpty(this IRuleBuilder ruleBuilder)
- {
- return ruleBuilder.Must(value => value != Guid.Empty);
+ return ruleBuilder.Must(value => value switch
+ {
+ null => false,
+ string stringValue => stringValue.Trim().Length > 0,
+ Guid guidValue => guidValue != Guid.Empty,
+ IEnumerable enumerable => enumerable.GetEnumerator().MoveNext(),
+ _ => true
+ });
}
///
@@ -130,4 +183,144 @@ public static class ValidatorUtilities
{
return ruleBuilder.Must(value => value.HasValue && Enum.IsDefined(value.Value));
}
+
+ ///
+ /// Defines a validation rule that ensures the string property does not exceed the specified maximum length.
+ ///
+ ///
+ /// If the property is or not a string, this rule passes.
+ ///
+ /// The type of the request being validated.
+ /// The type of the property being validated.
+ /// The rule builder instance.
+ /// The maximum allowed length of the property.
+ /// The current instance for method chaining.
+ public static IRuleBuilder MaximumLength(this IRuleBuilder ruleBuilder, int maximumLength)
+ {
+ return ruleBuilder.Must(value => value is not string stringValue || stringValue.Length <= maximumLength);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the string property is at least the specified minimum length.
+ ///
+ ///
+ /// If the property is or not a string, this rule fails.
+ ///
+ /// The type of the request being validated.
+ /// The type of the property being validated.
+ /// The rule builder instance.
+ /// The minimum allowed length of the property.
+ /// The current instance for method chaining.
+ public static IRuleBuilder MinimumLength(this IRuleBuilder ruleBuilder, int minimumLength)
+ {
+ return ruleBuilder.Must(value => value is string stringValue && stringValue.Length >= minimumLength);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the string property has exactly the specified length.
+ ///
+ ///
+ /// If the property is or not a string, this rule fails.
+ ///
+ /// The type of the request being validated.
+ /// The type of the property being validated.
+ /// The rule builder instance.
+ /// The exact allowed length of the property.
+ /// The current instance for method chaining.
+ public static IRuleBuilder Length(this IRuleBuilder ruleBuilder, int length)
+ {
+ return ruleBuilder.Must(value => value is string stringValue && stringValue.Length == length);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the string property length is within the specified inclusive range.
+ ///
+ ///
+ /// If the property is or not a string, this rule fails.
+ ///
+ /// The type of the request being validated.
+ /// The type of the property being validated.
+ /// The rule builder instance.
+ /// The minimum allowed length of the property.
+ /// The maximum allowed length of the property.
+ /// The current instance for method chaining.
+ public static IRuleBuilder Length(this IRuleBuilder ruleBuilder, int minimumLength, int maximumLength)
+ {
+ return ruleBuilder.Must(value => value is string stringValue && stringValue.Length >= minimumLength && stringValue.Length <= maximumLength);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the string property matches the specified regular expression pattern.
+ ///
+ ///
+ /// If the property is or not a string, this rule fails (use
+ /// to skip optional properties).
+ ///
+ /// The type of the request being validated.
+ /// The type of the property being validated.
+ /// The rule builder instance.
+ /// The regular expression pattern the property must match.
+ /// The current instance for method chaining.
+ public static IRuleBuilder Matches(this IRuleBuilder ruleBuilder, string regexPattern)
+ {
+ return ruleBuilder.Must(value => value is string stringValue && Regex.IsMatch(stringValue, regexPattern));
+ }
+
+ ///
+ /// Defines a validation rule that ensures the string property matches the regular expression pattern selected from the request instance.
+ ///
+ ///
+ /// If the property is or not a string, this rule fails.
+ ///
+ /// The type of the request being validated.
+ /// The type of the property being validated.
+ /// The rule builder instance.
+ /// A function that selects the regular expression pattern to match against from the request instance.
+ /// The current instance for method chaining.
+ public static IRuleBuilder Matches(this IRuleBuilder ruleBuilder, Func regexPatternSelector)
+ {
+ return ruleBuilder.Must((instance, value) => value is string stringValue && Regex.IsMatch(stringValue, regexPatternSelector(instance)));
+ }
+
+ ///
+ /// Defines a validation rule that ensures the integer property is within the specified inclusive range.
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The minimum allowed value of the property.
+ /// The maximum allowed value of the property.
+ /// The current instance for method chaining.
+ public static IRuleBuilder InclusiveBetween(this IRuleBuilder ruleBuilder, int minimumValue, int maximumValue)
+ {
+ return ruleBuilder.Must(value => value >= minimumValue && value <= maximumValue);
+ }
+
+ ///
+ /// Defines a validation rule that ensures the nullable integer property is within the specified inclusive range.
+ ///
+ ///
+ /// If the property is , this rule passes (use to check for missing values).
+ ///
+ /// The type of the request being validated.
+ /// The rule builder instance.
+ /// The minimum allowed value of the property.
+ /// The maximum allowed value of the property.
+ /// The current instance for method chaining.
+ public static IRuleBuilder InclusiveBetween(this IRuleBuilder ruleBuilder, int minimumValue, int maximumValue)
+ {
+ return ruleBuilder.Must(value => !value.HasValue || (value.Value >= minimumValue && value.Value <= maximumValue));
+ }
+
+ ///
+ /// Defines a validation rule that ensures the property is equal to another property of the request.
+ ///
+ /// The type of the request being validated.
+ /// The type of the property being validated.
+ /// The rule builder instance.
+ /// A function that selects the property the validated property must equal.
+ /// The current instance for method chaining.
+ public static IRuleBuilder Equal(this IRuleBuilder ruleBuilder, Func comparisonSelector)
+ {
+ return ruleBuilder.Must((instance, value) => Equals(value, comparisonSelector(instance)));
+ }
}
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQuery.cs b/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQuery.cs
index 93184771..3acbe0d2 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQuery.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQuery.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.Authorization;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPermissions;
@@ -10,4 +7,4 @@ namespace Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPer
///
/// Query for retrieving the list of authorization permissions.
///
-public record GetPermissionsQuery : IRequest>>;
+public record GetPermissionsQuery : IQuery;
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQueryHandler.cs b/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQueryHandler.cs
index 3b00e28f..c95dddb8 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQueryHandler.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Permissions/Queries/GetPermissions/GetPermissionsQueryHandler.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -8,7 +9,6 @@ using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPer
///
/// Handler for the query to retrieve the list of authorization permissions.
///
-public class GetPermissionsQueryHandler : IRequestHandler>>
+public class GetPermissionsQueryHandler : IQueryHandler>>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
@@ -41,12 +41,12 @@ public class GetPermissionsQueryHandler : IRequestHandler
/// Handles the query to retrieve the list of authorization permissions.
///
- /// The request to be handled.
+ /// The request to be handled.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public async ValueTask>> Handle(GetPermissionsQuery request, CancellationToken cancellationToken)
+ public async Task>> HandleAsync(GetPermissionsQuery query, CancellationToken cancellationToken)
{
// only admins can see the list of authorization permissions
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommand.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommand.cs
index 9cccdad1..af1d3265 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommand.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommand.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System;
using System.Diagnostics;
#endregion
@@ -14,4 +13,4 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
[DebuggerDisplay("RoleId: {RoleId}")]
public record DeleteRoleCommand(
Guid RoleId
-) : IRequest>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandHandler.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandHandler.cs
index df10ee28..a4de4b25 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandHandler.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandHandler.cs
@@ -1,12 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.Authorization;
-using Mediator;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -21,11 +22,12 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
///
/// Handler for the command to delete an authorization role.
///
-public class DeleteRoleCommandHandler : IRequestHandler>
+public class DeleteRoleCommandHandler : ICommandHandler>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUserService _currentUserService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
@@ -33,21 +35,27 @@ public class DeleteRoleCommandHandler : IRequestHandlerInjected service for authorization related functionality.
/// Injected service to retrieve the current user information.
/// Injected unit of work for interacting with the data access layer repositories.
- public DeleteRoleCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork)
+ /// Injected validator for application validation rules.
+ public DeleteRoleCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator validator)
{
_unitOfWork = unitOfWork;
_authorizationService = authorizationService;
_currentUserService = currentUserService;
+ _validator = validator;
}
///
/// Handles the command to delete an authorization role.
///
- /// The request to be handled.
+ /// The request to be handled.
/// Cancellation token that can be used to stop the execution.
/// An representing either a successful operation, or an error.
- public async ValueTask> Handle(DeleteRoleCommand request, CancellationToken cancellationToken)
+ public async Task> HandleAsync(DeleteRoleCommand command, CancellationToken cancellationToken)
{
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
// only admins can delete authorization roles
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
if (!isAdmin)
@@ -55,7 +63,7 @@ public class DeleteRoleCommandHandler : IRequestHandler();
- ErrorOr getExistingRoleResult = await roleRepository.GetByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
+ ErrorOr getExistingRoleResult = await roleRepository.GetByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (getExistingRoleResult.IsError)
return getExistingRoleResult.Errors;
else if (getExistingRoleResult.Value is null)
@@ -63,7 +71,7 @@ public class DeleteRoleCommandHandler : IRequestHandler deleteRoleResult = await roleRepository.DeleteByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
+ ErrorOr deleteRoleResult = await roleRepository.DeleteByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (deleteRoleResult.IsError)
return deleteRoleResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandValidator.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandValidator.cs
index a64205d5..8c5984d2 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandValidator.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/DeleteRole/DeleteRoleCommandValidator.cs
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
using Lumina.Application.Common.Errors;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using System;
#endregion
@@ -16,8 +17,8 @@ public class DeleteRoleCommandValidator : AbstractValidator
///
public DeleteRoleCommandValidator()
{
- RuleFor(x => x.RoleId)
- .NotEmpty().WithMessage(Errors.Authorization.RoleIdCannotBeEmpty.Description)
- .Must(id => id != Guid.Empty).WithMessage(Errors.Authorization.RoleIdCannotBeEmpty.Description);
+ RuleFor(command => command.RoleId)
+ .NotEmpty().WithError(Errors.Authorization.RoleIdCannotBeEmpty)
+ .Must(id => id != Guid.Empty).WithError(Errors.Authorization.RoleIdCannotBeEmpty);
}
}
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommand.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommand.cs
index 98ce2684..0b4fcd67 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommand.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommand.cs
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.Authorization;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -20,4 +18,4 @@ public record UpdateRoleCommand(
Guid RoleId,
string RoleName,
List Permissions
-) : IRequest>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandHandler.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandHandler.cs
index 11ebe913..5534b42b 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandHandler.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandHandler.cs
@@ -1,14 +1,16 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
-using Mediator;
+using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -19,11 +21,12 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
///
/// Handler for the command to update an authorization role.
///
-public class UpdateRoleCommandHandler : IRequestHandler>
+public class UpdateRoleCommandHandler : ICommandHandler>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUserService _currentUserService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
@@ -31,23 +34,29 @@ public class UpdateRoleCommandHandler : IRequestHandlerInjected service for authorization related functionality.
/// Injected service to retrieve the current user information.
/// Injected unit of work for interacting with the data access layer repositories.
- public UpdateRoleCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork)
+ /// Injected validator for application validation rules.
+ public UpdateRoleCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator validator)
{
_unitOfWork = unitOfWork;
_authorizationService = authorizationService;
_currentUserService = currentUserService;
+ _validator = validator;
}
///
/// Handles the command to update an authorization role.
///
- /// The request to be handled.
+ /// The request to be handled.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a successfully updated , or an error message.
///
- public async ValueTask> Handle(UpdateRoleCommand request, CancellationToken cancellationToken)
+ public async Task> HandleAsync(UpdateRoleCommand command, CancellationToken cancellationToken)
{
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
// only admins can update authorization roles
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
if (!isAdmin)
@@ -58,9 +67,9 @@ public class UpdateRoleCommandHandler : IRequestHandler new RolePermissionEntity()
+ Id = command.RoleId,
+ RoleName = command.RoleName,
+ RolePermissions = command.Permissions.Select(permissionId => new RolePermissionEntity()
{
PermissionId = permissionId,
Permission = null!,
@@ -74,7 +83,7 @@ public class UpdateRoleCommandHandler : IRequestHandler getRoleResult = await roleRepository.GetByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
+ ErrorOr getRoleResult = await roleRepository.GetByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (getRoleResult.IsError)
return getRoleResult.Errors;
if (getRoleResult.Value is null)
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandValidator.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandValidator.cs
index 4672ed03..af0253da 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandValidator.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Commands/UpdateRole/UpdateRoleCommandValidator.cs
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
using Lumina.Application.Common.Errors;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using System;
#endregion
@@ -16,19 +17,20 @@ public class UpdateRoleCommandValidator : AbstractValidator
///
public UpdateRoleCommandValidator()
{
- RuleFor(x => x.RoleId)
- .NotEmpty().WithMessage(Errors.Authorization.RoleIdCannotBeEmpty.Description)
- .Must(id => id != Guid.Empty).WithMessage(Errors.Authorization.RoleIdCannotBeEmpty.Description);
+ RuleFor(command => command.RoleId)
+ .NotEmpty().WithError(Errors.Authorization.RoleIdCannotBeEmpty)
+ .Must(id => id != Guid.Empty).WithError(Errors.Authorization.RoleIdCannotBeEmpty);
- RuleFor(x => x.RoleName)
- .NotNull().WithMessage(Errors.Authorization.RoleNameCannotBeNull.Description)
- .NotEmpty().WithMessage(Errors.Authorization.RoleNameCannotBeEmpty.Description);
+ RuleFor(command => command.RoleName)
+ .NotNull().WithError(Errors.Authorization.RoleNameCannotBeNull)
+ .NotEmpty().WithError(Errors.Authorization.RoleNameCannotBeEmpty);
- RuleFor(x => x.Permissions)
- .NotNull().WithMessage(Errors.Authorization.PermissionsListCannotBeNull.Description)
- .NotEmpty().WithMessage(Errors.Authorization.PermissionsListCannotBeEmpty.Description);
- RuleForEach(x => x.Permissions)
- .NotEmpty().WithMessage(Errors.Authorization.PermissionIdCannotBeEmpty.Description)
- .Must(id => id != Guid.Empty).WithMessage(Errors.Authorization.PermissionIdCannotBeEmpty.Description);
+ RuleFor(command => command.Permissions)
+ .NotNull().WithError(Errors.Authorization.PermissionsListCannotBeNull)
+ .NotEmpty().WithError(Errors.Authorization.PermissionsListCannotBeEmpty);
+
+ RuleForEach(command => command.Permissions)
+ .NotEmpty().WithError(Errors.Authorization.PermissionIdCannotBeEmpty)
+ .Must(id => id != Guid.Empty).WithError(Errors.Authorization.PermissionIdCannotBeEmpty);
}
}
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQuery.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQuery.cs
index 6a168b06..df96049a 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQuery.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQuery.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.Authorization;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
@@ -10,4 +7,4 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
///
/// Query for retrieving the list of authorization roles.
///
-public record GetRolesQuery() : IRequest>>;
+public record GetRolesQuery() : IQuery;
diff --git a/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQueryHandler.cs b/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQueryHandler.cs
index 405086ac..db716a4b 100644
--- a/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQueryHandler.cs
+++ b/src/Lumina.Application/Core/Admin/Authorization/Roles/Queries/GetRoles/GetRolesQueryHandler.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -8,7 +9,6 @@ using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
///
/// Handler for the query to retrieve the list of authorization roles.
///
-public class GetRolesQueryHandler : IRequestHandler>>
+public class GetRolesQueryHandler : IQueryHandler>>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
@@ -41,12 +41,12 @@ public class GetRolesQueryHandler : IRequestHandler
/// Handles the query to retrieve the list of authorization roles.
///
- /// The request to be handled.
+ /// The request to be handled.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public async ValueTask>> Handle(GetRolesQuery request, CancellationToken cancellationToken)
+ public async Task>> HandleAsync(GetRolesQuery query, CancellationToken cancellationToken)
{
// only admins can see the list of authorization roles
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQuery.cs
index c4be3e4b..86da3e1c 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQuery.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Directories;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -17,4 +14,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDi
public record GetDirectoriesQuery(
string? Path,
bool IncludeHiddenElements
-) : IRequest>>;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryHandler.cs
index bfda1160..141362f8 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryHandler.cs
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -15,30 +16,37 @@ namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDi
///
/// Handler for the query to get all directories.
///
-public class GetDirectoriesQueryHandler : IRequestHandler>>
+public class GetDirectoriesQueryHandler : IQueryHandler>>
{
private readonly IDirectoryService _directoryService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for handling directories.
- public GetDirectoriesQueryHandler(IDirectoryService directoryService)
+ /// Injected validator for application validation rules.
+ public GetDirectoriesQueryHandler(IDirectoryService directoryService, IValidator validator)
{
_directoryService = directoryService;
+ _validator = validator;
}
///
/// Gets the list of directories at the specified path.
///
- /// The query containing the requested path.
+ /// The query containing the requested path.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public ValueTask>> Handle(GetDirectoriesQuery request, CancellationToken cancellationToken)
+ public Task>> HandleAsync(GetDirectoriesQuery query, CancellationToken cancellationToken)
{
- ErrorOr> getSubdirectoriesResult = _directoryService.GetSubdirectories(request.Path!, request.IncludeHiddenElements);
- return ValueTask.FromResult(getSubdirectoriesResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return Task.FromResult>>(validationResult);
+
+ ErrorOr> getSubdirectoriesResult = _directoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements);
+ return Task.FromResult(getSubdirectoriesResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryValidator.cs
index f7012600..601823c9 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Directories/Queries/GetDirectories/GetDirectoriesQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class GetDirectoriesQueryValidator : AbstractValidator
public GetDirectoriesQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQuery.cs
index 74b2c0b0..a9b8cd0a 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQuery.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Common;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
@@ -10,4 +7,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
///
/// Query for retrieving the list of drives.
///
-public record GetDrivesQuery() : IRequest>>;
\ No newline at end of file
+public record GetDrivesQuery() : IQuery;
\ No newline at end of file
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQueryHandler.cs
index 287c3762..c509b39c 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Drives/Queries/GetDrives/GetDrivesQueryHandler.cs
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -15,7 +15,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
///
/// Handler for the query to get all drives.
///
-public class GetDrivesQueryHandler : IRequestHandler>>
+public class GetDrivesQueryHandler : IQueryHandler>>
{
private readonly IDriveService _driveService;
@@ -31,14 +31,14 @@ public class GetDrivesQueryHandler : IRequestHandler
/// Gets the list of file system drives.
///
- /// The query containing the requested path.
+ /// The query containing the requested path.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public ValueTask>> Handle(GetDrivesQuery request, CancellationToken cancellationToken)
+ public Task>> HandleAsync(GetDrivesQuery query, CancellationToken cancellationToken)
{
ErrorOr> getDrivesResult = _driveService.GetDrives();
- return ValueTask.FromResult(getDrivesResult.Match(values => ErrorOrFactory.From(values.ToTreeNodeResponses()), errors => errors));
+ return Task.FromResult(getDrivesResult.Match(values => ErrorOrFactory.From(values.ToTreeNodeResponses()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQuery.cs
index 512394b6..3ac8ace4 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQuery.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
-using Mediator;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
@@ -8,4 +7,4 @@ namespace Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFil
///
/// Query for retrieving the file system type.
///
-public record GetFileSystemQuery() : IRequest;
+public record GetFileSystemQuery() : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQueryHandler.cs
index 255cafcd..3abb1c43 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/FileSystem/Queries/GetFileSystem/GetFileSystemQueryHandler.cs
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
-using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -11,7 +11,7 @@ namespace Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFil
///
/// Handler for the query to get the file system type.
///
-public class GetFileSystemQueryHandler : IRequestHandler
+public class GetFileSystemQueryHandler : IQueryHandler
{
private readonly IPlatformContext _platformContext;
@@ -27,11 +27,11 @@ public class GetFileSystemQueryHandler : IRequestHandler
/// Gets the type of the file system.
///
- /// The query to be handled.
+ /// The query to be handled.
/// Cancellation token that can be used to stop the execution.
/// The type of the file system.
- public ValueTask Handle(GetFileSystemQuery request, CancellationToken cancellationToken)
+ public Task HandleAsync(GetFileSystemQuery query, CancellationToken cancellationToken)
{
- return ValueTask.FromResult(new FileSystemTypeResponse(_platformContext.Platform));
+ return Task.FromResult(new FileSystemTypeResponse(_platformContext.Platform));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQuery.cs
index 52fc745b..b5351d79 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQuery.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Files;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -17,4 +14,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
public record GetFilesQuery(
string? Path,
bool IncludeHiddenElements
-) : IRequest>>;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryHandler.cs
index 2f37dfa6..45d78a98 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryHandler.cs
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -15,30 +16,37 @@ namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
///
/// Handler for the query to get all files.
///
-public class GetFilesQueryHandler : IRequestHandler>>
+public class GetFilesQueryHandler : IQueryHandler>>
{
private readonly IFileService _fileService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for handling files.
- public GetFilesQueryHandler(IFileService fileService)
+ /// Injected validator for application validation rules.
+ public GetFilesQueryHandler(IFileService fileService, IValidator validator)
{
_fileService = fileService;
+ _validator = validator;
}
///
/// Gets the list of files at the specified path.
///
- /// The query containing the requested path.
+ /// The query containing the requested path.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public ValueTask>> Handle(GetFilesQuery request, CancellationToken cancellationToken)
+ public Task>> HandleAsync(GetFilesQuery query, CancellationToken cancellationToken)
{
- ErrorOr> getFilesResult = _fileService.GetFiles(request.Path!, request.IncludeHiddenElements);
- return ValueTask.FromResult(getFilesResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return Task.FromResult>>(validationResult);
+
+ ErrorOr> getFilesResult = _fileService.GetFiles(query.Path!, query.IncludeHiddenElements);
+ return Task.FromResult(getFilesResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryValidator.cs
index 0e1a77ce..3315dd6f 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetFiles/GetFilesQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class GetFilesQueryValidator : AbstractValidator
///
public GetFilesQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQuery.cs
index b31a5645..452debc6 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQuery.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Common;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -17,4 +14,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFile
public record GetTreeFilesQuery(
string? Path,
bool IncludeHiddenElements
-) : IRequest>>;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryHandler.cs
index 7bdd0799..68651cd0 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryHandler.cs
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -15,30 +16,37 @@ namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFile
///
/// Handler for the query to get all files.
///
-public class GetTreeFilesQueryHandler : IRequestHandler>>
+public class GetTreeFilesQueryHandler : IQueryHandler>>
{
private readonly IFileService _fileService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for handling files.
- public GetTreeFilesQueryHandler(IFileService fileService)
+ /// Injected validator for application validation rules.
+ public GetTreeFilesQueryHandler(IFileService fileService, IValidator validator)
{
_fileService = fileService;
+ _validator = validator;
}
///
/// Gets the list of files at the specified path.
///
- /// The query containing the requested path.
+ /// The query containing the requested path.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public ValueTask>> Handle(GetTreeFilesQuery request, CancellationToken cancellationToken)
+ public Task>> HandleAsync(GetTreeFilesQuery query, CancellationToken cancellationToken)
{
- ErrorOr> getFilesResult = _fileService.GetFiles(request.Path!, request.IncludeHiddenElements);
- return ValueTask.FromResult(getFilesResult.Match(values => ErrorOrFactory.From(values.ToFileSystemTreeNodeResponses()), errors => errors));
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return Task.FromResult>>(validationResult);
+
+ ErrorOr> getFilesResult = _fileService.GetFiles(query.Path!, query.IncludeHiddenElements);
+ return Task.FromResult(getFilesResult.Match(values => ErrorOrFactory.From(values.ToFileSystemTreeNodeResponses()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryValidator.cs
index efbedf60..30c51e7f 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Files/Queries/GetTreeFiles/GetTreeFilesQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class GetTreeFilesQueryValidator : AbstractValidator
///
public GetTreeFilesQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommand.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommand.cs
index 56330289..1a9e66bc 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommand.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommand.cs
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Path;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -16,4 +14,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePat
public record CombinePathCommand(
string? OriginalPath,
string? NewPath
-) : IRequest>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandHandler.cs
index 00bd0d7c..b6d6e233 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandHandler.cs
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
-using Mediator;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -13,30 +15,37 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePat
///
/// Handler for the command to split a file system path.
///
-public class CombinePathCommandHandler : IRequestHandler>
+public class CombinePathCommandHandler : ICommandHandler>
{
private readonly IPathService _pathService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for handling file system paths.
- public CombinePathCommandHandler(IPathService pathService)
+ /// Injected validator for application validation rules.
+ public CombinePathCommandHandler(IPathService pathService, IValidator validator)
{
_pathService = pathService;
+ _validator = validator;
}
///
/// Combines two file system paths.
///
- /// The command containing the requested paths.
+ /// The command containing the requested paths.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a , or an error message.
///
- public ValueTask> Handle(CombinePathCommand request, CancellationToken cancellationToken)
+ public Task> HandleAsync(CombinePathCommand command, CancellationToken cancellationToken)
{
- ErrorOr combinePathResult = _pathService.CombinePath(request.OriginalPath!, request.NewPath!);
- return ValueTask.FromResult(combinePathResult.Match(values => ErrorOrFactory.From(new PathSegmentResponse(combinePathResult.Value)), errors => errors));
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return Task.FromResult>(validationResult);
+
+ ErrorOr combinePathResult = _pathService.CombinePath(command.OriginalPath!, command.NewPath!);
+ return Task.FromResult(combinePathResult.Match(values => ErrorOrFactory.From(new PathSegmentResponse(combinePathResult.Value)), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandValidator.cs
index 4d02f302..bfc496d9 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/CombinePath/CombinePathCommandValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,7 +16,12 @@ public class CombinePathCommandValidator : AbstractValidator
///
public CombinePathCommandValidator()
{
- RuleFor(x => x.OriginalPath).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
- RuleFor(x => x.NewPath).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(command => command.OriginalPath)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
+
+ RuleFor(command => command.NewPath)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommand.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommand.cs
index bc211fe8..07e1ac7d 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommand.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommand.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Path;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -15,4 +12,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
[DebuggerDisplay("Path: {Path}")]
public record SplitPathCommand(
string? Path
-) : IRequest>>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandHandler.cs
index 48f1675f..28332339 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandHandler.cs
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -15,30 +16,37 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
///
/// Handler for the command to split a file system path.
///
-public class SplitPathCommandHandler : IRequestHandler>>
+public class SplitPathCommandHandler : ICommandHandler>>
{
private readonly IPathService _pathService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for handling file system paths.
- public SplitPathCommandHandler(IPathService pathService)
+ /// Injected validator for application validation rules.
+ public SplitPathCommandHandler(IPathService pathService, IValidator validator)
{
_pathService = pathService;
+ _validator = validator;
}
///
/// Gets the path components of the specified path.
///
- /// The command containing the requested path.
+ /// The command containing the requested path.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public ValueTask>> Handle(SplitPathCommand request, CancellationToken cancellationToken)
+ public Task>> HandleAsync(SplitPathCommand command, CancellationToken cancellationToken)
{
- ErrorOr> parsePathResult = _pathService.ParsePath(request.Path!);
- return ValueTask.FromResult(parsePathResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return Task.FromResult>>(validationResult);
+
+ ErrorOr> parsePathResult = _pathService.ParsePath(command.Path!);
+ return Task.FromResult(parsePathResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandValidator.cs
index 897c6e4d..001852f1 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Commands/SplitPath/SplitPathCommandValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class SplitPathCommandValidator : AbstractValidator
///
public SplitPathCommandValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(command => command.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQuery.cs
index 9c3db95b..02ce1e37 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQuery.cs
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Path;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -16,4 +14,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathEx
public record CheckPathExistsQuery(
string? Path,
bool IncludeHiddenElements
-) : IRequest>;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryHandler.cs
index df02b2eb..228cb273 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryHandler.cs
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
-using Mediator;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -12,29 +14,36 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathEx
///
/// Handler for the query to check the existence a file system path.
///
-public class CheckPathExistsQueryHandler : IRequestHandler>
+public class CheckPathExistsQueryHandler : IQueryHandler>
{
private readonly IPathService _pathService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for managing file system paths.
- public CheckPathExistsQueryHandler(IPathService pathService)
+ /// Injected validator for application validation rules.
+ public CheckPathExistsQueryHandler(IPathService pathService, IValidator validator)
{
_pathService = pathService;
+ _validator = validator;
}
///
/// Checks the existence of the specified file system path.
///
- /// The query containing the request.
+ /// The query containing the request.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either if the specified path exists, if it doesn't, or an error message.
///
- public ValueTask> Handle(CheckPathExistsQuery request, CancellationToken cancellationToken)
+ public Task> HandleAsync(CheckPathExistsQuery query, CancellationToken cancellationToken)
{
- return ValueTask.FromResult(ErrorOrFactory.From(new PathExistsResponse(_pathService.Exists(request.Path!, request.IncludeHiddenElements))));
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return Task.FromResult>(validationResult);
+
+ return Task.FromResult(ErrorOrFactory.From(new PathExistsResponse(_pathService.Exists(query.Path!, query.IncludeHiddenElements))));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryValidator.cs
index 0cca72a6..f943d41b 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/CheckPathExists/CheckPathExistsQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class CheckPathExistsQueryValidator : AbstractValidator
public CheckPathExistsQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQuery.cs
index 6be2d6fc..40c35738 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQuery.cs
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Path;
-using Mediator;
-using System.Collections.Generic;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -15,4 +12,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathPare
[DebuggerDisplay("Path: {Path}")]
public record GetPathParentQuery(
string? Path
-) : IRequest>>;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryHandler.cs
index f17ef062..46c0216d 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryHandler.cs
@@ -1,10 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
-using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -15,30 +16,37 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathPare
///
/// Handler for the query to get the parent of a file system path.
///
-public class GetPathParentQueryHandler : IRequestHandler>>
+public class GetPathParentQueryHandler : IQueryHandler>>
{
private readonly IPathService _pathService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for managing file system paths.
- public GetPathParentQueryHandler(IPathService pathService)
+ /// Injected validator for application validation rules.
+ public GetPathParentQueryHandler(IPathService pathService, IValidator validator)
{
_pathService = pathService;
+ _validator = validator;
}
///
/// Gets the parent of the specified file system path.
///
- /// The query containing the requested path.
+ /// The query containing the requested path.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a collection of , or an error message.
///
- public ValueTask>> Handle(GetPathParentQuery request, CancellationToken cancellationToken)
+ public Task>> HandleAsync(GetPathParentQuery query, CancellationToken cancellationToken)
{
- ErrorOr> goUpOneLevelResult = _pathService.GoUpOneLevel(request.Path!);
- return ValueTask.FromResult(goUpOneLevelResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return Task.FromResult>>(validationResult);
+
+ ErrorOr> goUpOneLevelResult = _pathService.GoUpOneLevel(query.Path!);
+ return Task.FromResult(goUpOneLevelResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryValidator.cs
index c74379da..b1b903e1 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathParent/GetPathParentQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class GetPathParentQueryValidator : AbstractValidator
///
public GetPathParentQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQuery.cs
index e3822cfc..0a18a626 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQuery.cs
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Path;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -14,4 +12,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot
[DebuggerDisplay("Path: {Path}")]
public record GetPathRootQuery(
string? Path
-) : IRequest>;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryHandler.cs
index 98732e01..b9a57317 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryHandler.cs
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
-using Mediator;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -14,28 +16,35 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot
///
/// Handler for the query to get the root of a file system path.
///
-public class GetPathRootQueryHandler : IRequestHandler>
+public class GetPathRootQueryHandler : IQueryHandler>
{
private readonly IPathService _pathService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for managing file system paths.
- public GetPathRootQueryHandler(IPathService pathService)
+ /// Injected validator for application validation rules.
+ public GetPathRootQueryHandler(IPathService pathService, IValidator validator)
{
_pathService = pathService;
+ _validator = validator;
}
///
/// Gets the root of the specified file system path.
///
- /// The query containing the requested path.
+ /// The query containing the requested path.
/// Cancellation token that can be used to stop the execution.
/// An containing either the root of the specified path, or an error.
- public ValueTask> Handle(GetPathRootQuery request, CancellationToken cancellationToken)
+ public Task> HandleAsync(GetPathRootQuery query, CancellationToken cancellationToken)
{
- ErrorOr getPathRootResult = _pathService.GetPathRoot(request.Path!);
- return ValueTask.FromResult(getPathRootResult.Match(values => ErrorOrFactory.From(values.ToResponse()), errors => errors));
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return Task.FromResult>(validationResult);
+
+ ErrorOr getPathRootResult = _pathService.GetPathRoot(query.Path!);
+ return Task.FromResult(getPathRootResult.Match(values => ErrorOrFactory.From(values.ToResponse()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryValidator.cs
index a3b6043a..d7d81acb 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathRoot/GetPathRootQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class GetPathRootQueryValidator : AbstractValidator
///
public GetPathRootQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQuery.cs
index e8c318f6..496af4e6 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQuery.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using Lumina.Contracts.Responses.FileSystemManagement.Path;
-using Mediator;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
@@ -8,4 +7,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSepa
///
/// Query for retrieving the file system path separator.
///
-public record GetPathSeparatorQuery() : IRequest;
\ No newline at end of file
+public record GetPathSeparatorQuery() : IQuery;
\ No newline at end of file
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQueryHandler.cs
index e57fc0b9..27bd46c9 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/GetPathSeparator/GetPathSeparatorQueryHandler.cs
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
-using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -11,7 +11,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSepa
///
/// Handler for the query to get the path separator character of a file system path.
///
-public class GetPathSeparatorQueryHandler : IRequestHandler
+public class GetPathSeparatorQueryHandler : IQueryHandler
{
private readonly IPathService _pathService;
@@ -27,11 +27,11 @@ public class GetPathSeparatorQueryHandler : IRequestHandler
/// Gets the path separator character of a file system path.
///
- /// The query containing the request.
+ /// The query containing the request.
/// Cancellation token that can be used to stop the execution.
/// The file system path separator character.
- public ValueTask Handle(GetPathSeparatorQuery request, CancellationToken cancellationToken)
+ public Task HandleAsync(GetPathSeparatorQuery query, CancellationToken cancellationToken)
{
- return ValueTask.FromResult(new PathSeparatorResponse(_pathService.PathSeparator.ToString()));
+ return Task.FromResult(new PathSeparatorResponse(_pathService.PathSeparator.ToString()));
}
}
\ No newline at end of file
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQuery.cs
index c1e35376..f9c6dd0e 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQuery.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using Lumina.Contracts.Responses.FileSystemManagement.Path;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -13,4 +12,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePat
[DebuggerDisplay("Path: {Path}")]
public record ValidatePathQuery(
string? Path
-) : IRequest;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryHandler.cs
index 3553ade7..88e68f0e 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryHandler.cs
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
-using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -11,7 +11,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePat
///
/// Handler for the query to validate a file system path.
///
-public class ValidatePathQueryHandler : IRequestHandler
+public class ValidatePathQueryHandler : IQueryHandler
{
private readonly IPathService _pathService;
@@ -27,13 +27,13 @@ public class ValidatePathQueryHandler : IRequestHandler
/// Validates the specified file system path.
///
- /// The query containing the request.
+ /// The query containing the request.
/// Cancellation token that can be used to stop the execution.
///
/// if the specified path is valid, otherwise.
///
- public ValueTask Handle(ValidatePathQuery request, CancellationToken cancellationToken)
+ public Task HandleAsync(ValidatePathQuery query, CancellationToken cancellationToken)
{
- return ValueTask.FromResult(new PathValidResponse(_pathService.IsValidPath(request.Path!)));
+ return Task.FromResult(new PathValidResponse(_pathService.IsValidPath(query.Path!)));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryValidator.cs
index 7740d025..747a33d0 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Paths/Queries/ValidatePath/ValidatePathQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,6 +16,8 @@ public class ValidatePathQueryValidator : AbstractValidator
///
public ValidatePathQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
-}
\ No newline at end of file
+}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQuery.cs b/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQuery.cs
index 9b658739..3e8699fb 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQuery.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQuery.cs
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
@@ -16,4 +14,4 @@ namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThu
public record GetThumbnailQuery(
string? Path,
int Quality
-) : IRequest>;
+) : IQuery;
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryHandler.cs b/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryHandler.cs
index 1c884438..a7d2072c 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryHandler.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryHandler.cs
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
-using Mediator;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -14,28 +16,35 @@ namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThu
///
/// Handler for the query to get the file thumbnail.
///
-public class GetThumbnailQueryHandler : IRequestHandler>
+public class GetThumbnailQueryHandler : IQueryHandler>
{
private readonly IThumbnailService _thumbnailsService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
///
/// Injected service for handling thumbnails.
- public GetThumbnailQueryHandler(IThumbnailService thumbnailsService)
+ /// Injected validator for application validation rules.
+ public GetThumbnailQueryHandler(IThumbnailService thumbnailsService, IValidator validator)
{
_thumbnailsService = thumbnailsService;
+ _validator = validator;
}
///
/// Gets the thumbnail for a file located at the specified path, with the specified quality.
///
- /// The query to be handled.
+ /// The query to be handled.
/// Cancellation token that can be used to stop the execution.
/// An containing either a thumbnail, or an error.
- public async ValueTask> Handle(GetThumbnailQuery request, CancellationToken cancellationToken)
+ public async Task> HandleAsync(GetThumbnailQuery query, CancellationToken cancellationToken)
{
- ErrorOr getThumbnailResult = await _thumbnailsService.GetThumbnailAsync(request.Path!, request.Quality, cancellationToken);
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ ErrorOr getThumbnailResult = await _thumbnailsService.GetThumbnailAsync(query.Path!, query.Quality, cancellationToken);
return await ValueTask.FromResult(getThumbnailResult.Match(value => ErrorOrFactory.From(value.ToResponse()), errors => errors));
}
}
diff --git a/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryValidator.cs b/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryValidator.cs
index c43cd478..37255df8 100644
--- a/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryValidator.cs
+++ b/src/Lumina.Application/Core/FileSystemManagement/Thumbnails/Queries/GetThumbnail/GetThumbnailQueryValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -15,7 +16,12 @@ public class GetThumbnailQueryValidator : AbstractValidator
///
public GetThumbnailQueryValidator()
{
- RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
- RuleFor(x => x.Quality).InclusiveBetween(0, 100).WithMessage(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred.Description);
+ RuleFor(query => query.Path)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty);
+
+ RuleFor(query => query.Quality)
+ .InclusiveBetween(0, 100)
+ .WithError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
}
}
diff --git a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommand.cs b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommand.cs
index 8d9c161a..dc384283 100644
--- a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommand.cs
+++ b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommand.cs
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.Authentication;
-using Mediator;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
@@ -18,4 +16,4 @@ public record SetupApplicationCommand(
string? Password,
string? PasswordConfirm,
bool Use2fa
-) : IRequest>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs
index 428beefe..c80d4889 100644
--- a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs
+++ b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.Seed;
@@ -8,8 +9,8 @@ using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Security;
using Lumina.Application.Common.Infrastructure.Time;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.Authentication;
-using Mediator;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -22,7 +23,7 @@ namespace Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApp
///
/// Handler for the command to perform the initial application setup.
///
-public class SetupApplicationCommandHandler : IRequestHandler>
+public class SetupApplicationCommandHandler : ICommandHandler>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IPasswordHashService _hashService;
@@ -31,6 +32,7 @@ public class SetupApplicationCommandHandler : IRequestHandler _validator;
///
/// Initializes a new instance of the class.
@@ -42,6 +44,7 @@ public class SetupApplicationCommandHandler : IRequestHandlerInjected service for generating QR codes.
/// Injected service for time related concerns.
/// Injected service for the initial persistence medium data seed.
+ /// Injected validator for application validation rules.
public SetupApplicationCommandHandler(
IUnitOfWork unitOfWork,
IPasswordHashService hashService,
@@ -49,7 +52,8 @@ public class SetupApplicationCommandHandler : IRequestHandler validator)
{
_unitOfWork = unitOfWork;
_hashService = hashService;
@@ -58,18 +62,23 @@ public class SetupApplicationCommandHandler : IRequestHandler
/// Handles the command to perform the initial application setup.
///
- /// The request to be handled.
+ /// The request to be handled.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a successfully created , or an error message.
///
- public async ValueTask> Handle(SetupApplicationCommand request, CancellationToken cancellationToken)
+ public async Task> HandleAsync(SetupApplicationCommand command, CancellationToken cancellationToken)
{
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
// check if any users already exists (admin account is only set once!)
IUserRepository userRepository = _unitOfWork.GetRepository();
ErrorOr> selectUsersResult = await userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
@@ -83,8 +92,8 @@ public class SetupApplicationCommandHandler : IRequestHandler
public SetupApplicationCommandValidator()
{
- RuleFor(x => x.Username).NotEmpty().WithMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
- RuleFor(x => x.Password).NotEmpty().WithMessage(Errors.Authentication.PasswordCannotBeEmpty.Description)
- .Matches("^(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{8,}$").WithMessage(Errors.Authentication.InvalidPassword.Description);
- RuleFor(x => x.PasswordConfirm).NotEmpty().WithMessage(Errors.Authentication.PasswordConfirmCannotBeEmpty.Description);
- RuleFor(x => x.Password).Equal(x => x.PasswordConfirm).WithMessage(Errors.Authentication.PasswordsNotMatch.Description);
+ RuleFor(command => command.Username)
+ .NotEmpty()
+ .WithError(Errors.Authentication.UsernameCannotBeEmpty);
+
+ RuleFor(command => command.Password)
+ .NotEmpty()
+ .WithError(Errors.Authentication.PasswordCannotBeEmpty)
+ .Matches("^(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{8,}$")
+ .WithError(Errors.Authentication.InvalidPassword);
+
+ RuleFor(command => command.PasswordConfirm)
+ .NotEmpty()
+ .WithError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
+
+ RuleFor(command => command.Password)
+ .Equal(command => command.PasswordConfirm)
+ .WithError(Errors.Authentication.PasswordsNotMatch);
}
}
diff --git a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQuery.cs b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQuery.cs
index 3400a137..6177e3c3 100644
--- a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQuery.cs
+++ b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQuery.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using Lumina.Contracts.Responses.UsersManagement;
-using Mediator;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
@@ -8,4 +7,4 @@ namespace Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInit
///
/// Query for checking the initialization of the application.
///
-public record CheckInitializationQuery() : IRequest;
+public record CheckInitializationQuery() : IQuery;
diff --git a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQueryHandler.cs b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQueryHandler.cs
index 4ef82f25..6eec60bf 100644
--- a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQueryHandler.cs
+++ b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Queries/CheckInitialization/CheckInitializationQueryHandler.cs
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Contracts.Responses.UsersManagement;
-using Mediator;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInit
///
/// Handler for the query to check the initialization of the application.
///
-public class CheckInitializationQueryHandler : IRequestHandler
+public class CheckInitializationQueryHandler : IQueryHandler
{
private readonly IUnitOfWork _unitOfWork;
@@ -31,12 +31,12 @@ public class CheckInitializationQueryHandler : IRequestHandler
/// Checks the initialization status of the application.
///
- /// The query containing the request.
+ /// The query containing the request.
/// Cancellation token that can be used to stop the execution.
///
/// if the application is initialized (the admin account is created), otherwise.
///
- public async ValueTask Handle(CheckInitializationQuery request, CancellationToken cancellationToken)
+ public async Task HandleAsync(CheckInitializationQuery query, CancellationToken cancellationToken)
{
IUserRepository userRepository = _unitOfWork.GetRepository();
// if the repository reports an error, or there are no users, the application has not been initialized
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs
index d520d53a..a9345eca 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Lumina.Contracts.Responses.MediaLibrary.Management;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System;
using System.Diagnostics;
#endregion
@@ -31,4 +29,4 @@ public record AddLibraryCommand(
bool DownloadMetadataFromWeb,
bool ShouldSaveMetadataInMediaDirectories,
bool ShouldSkipUnchangedDirectoriesDuringScan
-) : IRequest>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs
index 36f8bbcc..7ce6ce44 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs
@@ -1,11 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
@@ -16,8 +18,8 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
-using Mediator;
using System;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
@@ -29,13 +31,14 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
///
/// Handler for the command to add a media library.
///
-public class AddLibraryCommandHandler : IRequestHandler>
+public class AddLibraryCommandHandler : ICommandHandler>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
private readonly IDomainEventsQueue _domainEventsQueue;
private readonly IEnvironmentContext _environmentContext;
private readonly IAuthorizationService _authorizationService;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
@@ -45,30 +48,36 @@ public class AddLibraryCommandHandler : IRequestHandlerInjected service for the queue of domain events.
/// Injected facade service for environment contextual services.
/// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected validator for application validation rules.
public AddLibraryCommandHandler(
IAuthorizationService authorizationService,
ICurrentUserService currentUserService,
IDomainEventsQueue domainEventsQueue,
IEnvironmentContext environmentContext,
- IUnitOfWork unitOfWork)
+ IUnitOfWork unitOfWork,
+ IValidator validator)
{
_unitOfWork = unitOfWork;
_currentUserService = currentUserService;
_domainEventsQueue = domainEventsQueue;
_environmentContext = environmentContext;
_authorizationService = authorizationService;
+ _validator = validator;
}
///
/// Handles the command to add a media library.
///
- /// The request to be handled.
+ /// The command to be handled.
/// Cancellation token that can be used to stop the execution.
///
/// An containing either a successfully created , or an error message.
///
- public async ValueTask> Handle(AddLibraryCommand request, CancellationToken cancellationToken)
+ public async Task> HandleAsync(AddLibraryCommand command, CancellationToken cancellationToken)
{
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
// if the user that made the request is not an Admin or they don't have the permission to manage media libraries, they do not have the right to create it
if (!await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false) &&
@@ -76,9 +85,9 @@ public class AddLibraryCommandHandler : IRequestHandler fileSystemPathIdResult = FileSystemPathId.Create(request.CoverImage);
+ ErrorOr fileSystemPathIdResult = FileSystemPathId.Create(command.CoverImage);
if (fileSystemPathIdResult.IsError)
return fileSystemPathIdResult.Errors;
@@ -92,15 +101,15 @@ public class AddLibraryCommandHandler : IRequestHandler createLibraryResult = Library.Create(
UserId.Create(_currentUserService.UserId!.Value),
- request.Title!,
- Enum.Parse(request.LibraryType!),
- request.ContentLocations!,
- request.CoverImage,
- request.IsEnabled,
- request.IsLocked,
- request.DownloadMetadataFromWeb,
- request.ShouldSaveMetadataInMediaDirectories,
- request.ShouldSkipUnchangedDirectoriesDuringScan,
+ command.Title!,
+ Enum.Parse(command.LibraryType!),
+ command.ContentLocations!,
+ command.CoverImage,
+ command.IsEnabled,
+ command.IsLocked,
+ command.DownloadMetadataFromWeb,
+ command.ShouldSaveMetadataInMediaDirectories,
+ command.ShouldSkipUnchangedDirectoriesDuringScan,
[]
);
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs
index 8a82e5cf..8e6f0bc2 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using System;
@@ -17,21 +18,28 @@ public class AddLibraryCommandValidator : AbstractValidator
///
public AddLibraryCommandValidator()
{
- RuleFor(x => x.LibraryType)
- .NotNull().WithMessage(Errors.Library.LibraryTypeCannotBeNull.Description)
- .Must(x => Enum.TryParse(x, out _))
- .WithMessage(Errors.Library.UnknownLibraryType.Description);
+ RuleFor(command => command.LibraryType)
+ .NotNull()
+ .WithError(Errors.Library.LibraryTypeCannotBeNull)
+ .Must(libraryType => Enum.TryParse(libraryType, out _))
+ .WithError(Errors.Library.UnknownLibraryType);
- RuleFor(x => x.ContentLocations)
- .NotNull().WithMessage(Errors.Library.PathsListCannotBeNull.Description)
- .NotEmpty().WithMessage(Errors.Library.PathsListCannotBeEmpty.Description);
+ RuleFor(command => command.ContentLocations)
+ .NotNull()
+ .WithError(Errors.Library.PathsListCannotBeNull)
+ .NotEmpty()
+ .WithError(Errors.Library.PathsListCannotBeEmpty);
- RuleForEach(x => x.ContentLocations)
- .NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description)
- .MaximumLength(260).WithMessage(Errors.FileSystemManagement.PathMustBeMaximum260CharactersLong.Description);
+ RuleForEach(command => command.ContentLocations)
+ .NotEmpty()
+ .WithError(Errors.FileSystemManagement.PathCannotBeEmpty)
+ .MaximumLength(260)
+ .WithError(Errors.FileSystemManagement.PathMustBeMaximum260CharactersLong);
- RuleFor(x => x.Title)
- .NotEmpty().WithMessage(Errors.Library.TitleCannotBeEmpty.Description)
- .MaximumLength(255).WithMessage(Errors.Library.TitleMustBeMaximum255CharactersLong.Description);
+ RuleFor(command => command.Title)
+ .NotEmpty()
+ .WithError(Errors.Library.TitleCannotBeEmpty)
+ .MaximumLength(255)
+ .WithError(Errors.Library.TitleMustBeMaximum255CharactersLong);
}
}
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommand.cs
index 1502b0dd..15f56d1d 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommand.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Mediator;
+using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrariesScan;
@@ -8,4 +7,4 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrari
///
/// Command for canceling the previously started scan of all media libraries.
///
-public record CancelLibrariesScanCommand : IRequest>;
+public record CancelLibrariesScanCommand : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommandHandler.cs
index 93c46a87..2d9d60da 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibrariesScan/CancelLibrariesScanCommandHandler.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
@@ -10,7 +11,6 @@ using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation;
-using Mediator;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -22,7 +22,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrari
///
/// Handler for the command for canceling the scan of all media libraries.
///
-public class CancelLibrariesScanCommandHandler : IRequestHandler>
+public class CancelLibrariesScanCommandHandler : ICommandHandler>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
@@ -51,10 +51,10 @@ public class CancelLibrariesScanCommandHandler : IRequestHandler
/// Handles the command for canceling the scan of all media libraries.
///
- /// The request to be handled.
+ /// The command to be handled.
/// Cancellation token that can be used to stop the execution.
/// An representing either a successful operation, or an error.
- public async ValueTask> Handle(CancelLibrariesScanCommand request, CancellationToken cancellationToken)
+ public async Task> HandleAsync(CancelLibrariesScanCommand command, CancellationToken cancellationToken)
{
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository();
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommand.cs
index 5171a9cb..c6761330 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommand.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System;
using System.Diagnostics;
#endregion
@@ -16,4 +15,4 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrary
public record CancelLibraryScanCommand(
Guid LibraryId,
Guid ScanId
-) : IRequest>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandHandler.cs
index f0e7a489..c51a844a 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandHandler.cs
@@ -1,15 +1,17 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
-using Mediator;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
@@ -21,12 +23,13 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrary
///
/// Handler for the command for canceling the scan of a media library.
///
-public class CancelLibraryScanCommandHandler : IRequestHandler>
+public class CancelLibraryScanCommandHandler : ICommandHandler>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
private readonly IDomainEventsQueue _domainEventsQueue;
+ private readonly IValidator _validator;
///
/// Initializes a new instance of the class.
@@ -35,30 +38,37 @@ public class CancelLibraryScanCommandHandler : IRequestHandlerInjected service to retrieve the current user information.
/// Injected service for the queue of domain events.
/// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected validator for application validation rules.
public CancelLibraryScanCommandHandler(
IAuthorizationService authorizationService,
ICurrentUserService currentUserService,
IDomainEventsQueue domainEventsQueue,
- IUnitOfWork unitOfWork)
+ IUnitOfWork unitOfWork,
+ IValidator validator)
{
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_domainEventsQueue = domainEventsQueue;
_unitOfWork = unitOfWork;
+ _validator = validator;
}
///
/// Handles the command for canceling the scan of a media library.
///
- /// The request to be handled.
+ /// The command to be handled.
/// Cancellation token that can be used to stop the execution.
/// An representing either a successful operation, or an error.
- public async ValueTask> Handle(CancelLibraryScanCommand request, CancellationToken cancellationToken)
+ public async Task> HandleAsync(CancelLibraryScanCommand command, CancellationToken cancellationToken)
{
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository();
// get the library scan from the repository
- ErrorOr getLibraryScansResult = await libraryScanRepository.GetByIdAsync(request.ScanId, cancellationToken).ConfigureAwait(false);
+ ErrorOr getLibraryScansResult = await libraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsError)
return getLibraryScansResult.Errors;
if (getLibraryScansResult.Value is null)
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandValidator.cs
index 63d94dc0..05e15b60 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/CancelLibraryScan/CancelLibraryScanCommandValidator.cs
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
-using FluentValidation;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using System;
#endregion
@@ -16,11 +17,16 @@ public class CancelLibraryScanCommandValidator : AbstractValidator
public CancelLibraryScanCommandValidator()
{
- RuleFor(x => x.LibraryId)
- .NotEmpty().WithMessage(Errors.Library.LibraryIdCannotBeEmpty.Description)
- .Must(id => id != Guid.Empty).WithMessage(Errors.Library.LibraryIdCannotBeEmpty.Description);
- RuleFor(x => x.ScanId)
- .NotEmpty().WithMessage(Errors.LibraryScanning.ScanIdCannotBeEmpty.Description)
- .Must(id => id != Guid.Empty).WithMessage(Errors.LibraryScanning.ScanIdCannotBeEmpty.Description);
+ RuleFor(command => command.LibraryId)
+ .NotEmpty()
+ .WithError(Errors.Library.LibraryIdCannotBeEmpty)
+ .Must(id => id != Guid.Empty)
+ .WithError(Errors.Library.LibraryIdCannotBeEmpty);
+
+ RuleFor(command => command.ScanId)
+ .NotEmpty()
+ .WithError(Errors.LibraryScanning.ScanIdCannotBeEmpty)
+ .Must(id => id != Guid.Empty)
+ .WithError(Errors.LibraryScanning.ScanIdCannotBeEmpty);
}
}
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommand.cs
index 0f1932eb..022b4623 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommand.cs
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using ErrorOr;
-using Mediator;
+using Lumina.Application.Common.CQRS;
using System;
using System.Diagnostics;
#endregion
@@ -14,4 +13,4 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary
[DebuggerDisplay("Id: {Id}")]
public record DeleteLibraryCommand(
Guid Id
-) : IRequest>;
+) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs
index 998e77b2..97c63bf2 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/DeleteLibrary/DeleteLibraryCommandHandler.cs
@@ -1,15 +1,17 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
+using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
-using Mediator;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
@@ -21,12 +23,13 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary
///
/// Handler for the command to delete a library by its Id.
///
-public class DeleteLibraryCommandHandler : IRequestHandler>
+public class DeleteLibraryCommandHandler : ICommandHandler>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
private readonly IDomainEventsQueue _domainEventsQueue;
+ private readonly IValidator _validator;
///