mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 05:11:10 +00:00
Implements file system path existence check
This commit is contained in:
1 parent
dc47386726
commit
c29d829c91
16 files changed
+452
-125
No files matched your search
@@ -0,0 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the existence of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to check the existence.</param>
|
||||
public record CheckPathExistsQuery(string Path) : IRequest<PathExistsResponse>;
|
||||
+45
@@ -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 check the existence a file system path.
|
||||
/// </summary>
|
||||
public class CheckPathExistsQueryHandler : IRequestHandler<CheckPathExistsQuery, PathExistsResponse>
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly IPathService _pathService;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckPathExistsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pathService">Injected service for managing file system paths.</param>
|
||||
public CheckPathExistsQueryHandler(IPathService pathService)
|
||||
{
|
||||
_pathService = pathService;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Checks the existence of 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 exists, <see langword="false"/> otherwise.
|
||||
/// </returns>
|
||||
public ValueTask<PathExistsResponse> Handle(CheckPathExistsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return ValueTask.FromResult(new PathExistsResponse(_pathService.Exists(request.Path)));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+22
@@ -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="CheckPathExistsQuery"/>.
|
||||
/// </summary>
|
||||
public class CheckPathExistsQueryValidator : AbstractValidator<CheckPathExistsQuery>
|
||||
{
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckPathExistsQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public CheckPathExistsQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user