Fixes ValidatePath query handler to call its validator and updates consuming web client

This commit is contained in:
BinaryAlley committed 2026-08-13 10:12:32 -07:00
1 parent ac318762bf
commit 8c8c96c6db
7 files changed
+276 -40

No files matched your search

@@ -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!))));
}
}
@@ -1,4 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
@@ -18,13 +19,13 @@ namespace Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.Valid
/// </summary>
public class ValidatePathEndpoint : BaseEndpoint<ValidatePathRequest, IResult>
{
private readonly IQueryHandler<ValidatePathQuery, PathValidResponse> _validatePathQueryHandler;
private readonly IQueryHandler<ValidatePathQuery, ErrorOr<PathValidResponse>> _validatePathQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="ValidatePathEndpoint"/> class.
/// </summary>
/// <param name="validatePathQueryHandler">Injected service for handling validate path queries.</param>
public ValidatePathEndpoint(IQueryHandler<ValidatePathQuery, PathValidResponse> validatePathQueryHandler)
public ValidatePathEndpoint(IQueryHandler<ValidatePathQuery, ErrorOr<PathValidResponse>> validatePathQueryHandler)
{
_validatePathQueryHandler = validatePathQueryHandler;
}
@@ -47,7 +48,7 @@ public class ValidatePathEndpoint : BaseEndpoint<ValidatePathRequest, IResult>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(ValidatePathRequest request, CancellationToken cancellationToken)
{
PathValidResponse result = await _validatePathQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return TypedResults.Ok(result);
ErrorOr<PathValidResponse> result = await _validatePathQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -249,21 +249,26 @@
*/
async function checkPathAsync(path) {
const pathValidResponse = await callApiGetAsync(`${clientBasePath}path/api-validate?path=${encodeURIComponent(path)}`);
if (pathValidResponse !== undefined) {
if (!pathValidResponse.isValid) {
notificationService.show("Specified path is not valid!", NotificationType.ERROR); // TODO: should ask error message from server when translation is implemented
addressBarInput.value = _path;
if (addressBarInput.value !== null && !addressBarInput.value.endsWith(pathSeparator))
addressBarInput.value += pathSeparator;
} else {
const pathExistsResponse = await callApiGetAsync(`${clientBasePath}path/api-check-path-exists?path=${encodeURIComponent(path)}&includeHiddenElements=${showHiddenElements}`);
if (pathExistsResponse !== undefined && !pathExistsResponse.exists) {
notificationService.show("Specified path does not exist!", NotificationType.ERROR); // TODO: should ask error message from server when translation is implemented
return false;
}
}
return pathValidResponse.isValid;
if (pathValidResponse === undefined) {
// the API rejected the path with a validation error (e.g. it is empty), treat it as invalid and restore the address bar
addressBarInput.value = _path;
if (addressBarInput.value !== null && !addressBarInput.value.endsWith(pathSeparator))
addressBarInput.value += pathSeparator;
return false;
}
if (!pathValidResponse.isValid) {
notificationService.show("Specified path is not valid!", NotificationType.ERROR); // TODO: should ask error message from server when translation is implemented
addressBarInput.value = _path;
if (addressBarInput.value !== null && !addressBarInput.value.endsWith(pathSeparator))
addressBarInput.value += pathSeparator;
} else {
const pathExistsResponse = await callApiGetAsync(`${clientBasePath}path/api-check-path-exists?path=${encodeURIComponent(path)}&includeHiddenElements=${showHiddenElements}`);
if (pathExistsResponse !== undefined && !pathExistsResponse.exists) {
notificationService.show("Specified path does not exist!", NotificationType.ERROR); // TODO: should ask error message from server when translation is implemented
return false;
}
}
return pathValidResponse.isValid;
}
/**