Implements directory browser dialog, part 2: path navigator

This commit is contained in:
BinaryAlley committed 2024-09-17 21:27:05 +03:00
1 parent 4e4ecbbfca
commit a4f9199d2c
34 files changed
+1450 -200

No files matched your search

@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Query for retrieving the parent of a file system path.
/// </summary>
/// <param name="Path">The path for which to get the parent.</param>
public record GetPathParentQuery(string Path) : IRequest<ErrorOr<IEnumerable<PathSegmentResponse>>>;
@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using Mapster;
using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Handler for the query to get the parent of a file system path.
/// </summary>
public class GetPathParentQueryHandler : IRequestHandler<GetPathParentQuery, ErrorOr<IEnumerable<PathSegmentResponse>>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IPathService _pathService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetPathParentQueryHandler"/> class.
/// </summary>
/// <param name="pathService">Injected service for managing file system paths.</param>
public GetPathParentQueryHandler(IPathService pathService)
{
_pathService = pathService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the parent of the specified file system path.
/// </summary>
/// <param name="request">The query containing the requested path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="PathSegmentResponse"/>, or an error message.
/// </returns>
public ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>> Handle(GetPathParentQuery request, CancellationToken cancellationToken)
{
ErrorOr<IEnumerable<PathSegment>> result = _pathService.GoUpOneLevel(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<PathSegmentResponse>>()), errors => errors));
}
#endregion
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Validates the needed validation rules for <see cref="GetPathParentQuery"/>.
/// </summary>
public class GetPathParentQueryValidator : AbstractValidator<GetPathParentQuery>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetPathParentQueryValidator"/> class.
/// </summary>
public GetPathParentQueryValidator()
{
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Validates the needed validation rules for <see cref="GetPathRootQuery"/>.
/// </summary>
public class GetPathRootQueryValidator : AbstractValidator<GetPathRootQuery>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetPathRootQueryValidator"/> class.
/// </summary>
public GetPathRootQueryValidator()
{
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}
@@ -0,0 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Query for validating a path.
/// </summary>
/// <param name="Path">The path to be validated.</param>
public record ValidatePathQuery(string Path) : IRequest<PathValidResponse>;
@@ -0,0 +1,45 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Handler for the query to validate a file system path.
/// </summary>
public class ValidatePathQueryHandler : IRequestHandler<ValidatePathQuery, PathValidResponse>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IPathService _pathService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <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)
{
_pathService = pathService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Validates the specified file system path.
/// </summary>
/// <param name="request">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.
/// </returns>
public ValueTask<PathValidResponse> Handle(ValidatePathQuery request, CancellationToken cancellationToken)
{
return ValueTask.FromResult(new PathValidResponse(_pathService.IsValidPath(request.Path)));
}
#endregion
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Validates the needed validation rules for <see cref="ValidatePathQuery"/>.
/// </summary>
public class ValidatePathQueryValidator : AbstractValidator<ValidatePathQuery>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="ValidatePathQueryValidator"/> class.
/// </summary>
public ValidatePathQueryValidator()
{
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}