#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
using Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
using Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathSeparator;
using Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Presentation.Api.Common.ModelBinders;
using Lumina.Presentation.Api.Core.Controllers.Common;
using Mediator;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Controllers.FileManagement;
///
/// Controller for managing file system paths.
///
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
public class PathController : ApiController
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly ISender _mediator;
#endregion
#region ====================================================================== CTOR =====================================================================================
///
/// Initializes a new instance of the class.
///
/// Injected service for mediating commands and queries.
public PathController(ISender mediator)
{
_mediator = mediator;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
///
/// Gets the root of .
///
/// The path for which to get the root.
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-path-root")]
public async Task GetPathRoot([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
{
ErrorOr result = await _mediator.Send(new GetPathRootQuery(path), cancellationToken).ConfigureAwait(false);
return result.Match(Ok, Problem);
}
///
/// Gets the path separator character of the file system.
///
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-path-separator")]
public async Task GetPathSeparator(CancellationToken cancellationToken)
{
PathSeparatorResponse result = await _mediator.Send(new GetPathSeparatorQuery(), cancellationToken).ConfigureAwait(false);
return Ok(result);
}
///
/// Gets the path separator character of the file system.
///
/// The path for which to get the parent path.
/// Cancellation token that can be used to stop the execution.
[HttpGet("get-path-parent")]
public async Task GetPathParent([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
{
ErrorOr> result = await _mediator.Send(new GetPathParentQuery(path), cancellationToken).ConfigureAwait(false);
return result.Match(Ok, Problem);
}
///
/// Combines with .
///
/// The path to combine to.
/// The path to combine with.
/// Cancellation token that can be used to stop the execution.
[HttpGet("combine")]
public async Task CombinePath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string originalPath, [FromQuery, ModelBinder(typeof(UrlStringBinder))] string newPath, CancellationToken cancellationToken)
{
ErrorOr result = await _mediator.Send(new CombinePathCommand(originalPath, newPath), cancellationToken).ConfigureAwait(false);
return result.Match(Ok, Problem);
}
///
/// Gets the path components of .
///
/// The path for which to get the path segments.
/// Cancellation token that can be used to stop the execution.
[HttpGet("split")]
public async Task SplitPath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
{
ErrorOr> result = await _mediator.Send(new SplitPathCommand(path), cancellationToken).ConfigureAwait(false);
return result.Match(Ok, Problem);
}
///
/// Validates the validity of .
///
/// The path to be validated.
/// Cancellation token that can be used to stop the execution.
[HttpGet("validate")]
public async Task ValidatePath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
{
PathValidResponse result = await _mediator.Send(new ValidatePathQuery(path), cancellationToken).ConfigureAwait(false);
return Ok(result);
}
///
/// Checks whether exists or not.
///
/// The path to be checked.
/// Cancellation token that can be used to stop the execution.
[HttpGet("check-path-exists")]
public async Task CheckPathExists([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
{
PathExistsResponse result = await _mediator.Send(new CheckPathExistsQuery(path), cancellationToken).ConfigureAwait(false);
return Ok(result);
}
#endregion
}