mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Fixes ValidatePath query handler to call its validator and updates consuming web client
This commit is contained in:
1 parent
ac318762bf
commit
8c8c96c6db
7 files changed
+276
-40
No files matched your search
+15
-5
@@ -1,7 +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 System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -11,17 +14,20 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePat
|
||||
/// <summary>
|
||||
/// Handler for the query to validate a file system path.
|
||||
/// </summary>
|
||||
public class ValidatePathQueryHandler : IQueryHandler<ValidatePathQuery, PathValidResponse>
|
||||
public class ValidatePathQueryHandler : IQueryHandler<ValidatePathQuery, ErrorOr<PathValidResponse>>
|
||||
{
|
||||
private readonly IPathService _pathService;
|
||||
private readonly IValidator<ValidatePathQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ValidatePathQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pathService">Injected service for managing file system paths.</param>
|
||||
public ValidatePathQueryHandler(IPathService pathService)
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public ValidatePathQueryHandler(IPathService pathService, IValidator<ValidatePathQuery> validator)
|
||||
{
|
||||
_pathService = pathService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -30,10 +36,14 @@ public class ValidatePathQueryHandler : IQueryHandler<ValidatePathQuery, PathVal
|
||||
/// <param name="query">The query containing the request.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if the specified path is valid, <see langword="false"/> otherwise.
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either <see langword="true"/> if the specified path is valid, <see langword="false"/> if it isn't, or an error message.
|
||||
/// </returns>
|
||||
public Task<PathValidResponse> HandleAsync(ValidatePathQuery query, CancellationToken cancellationToken)
|
||||
public Task<ErrorOr<PathValidResponse>> HandleAsync(ValidatePathQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(new PathValidResponse(_pathService.IsValidPath(query.Path!)));
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return Task.FromResult<ErrorOr<PathValidResponse>>(validationResult);
|
||||
|
||||
return Task.FromResult(ErrorOrFactory.From(new PathValidResponse(_pathService.IsValidPath(query.Path!))));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user