mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 03:11:10 +00:00
Implements directory browser dialog, part 1: file system treeview
This commit is contained in:
1 parent
4a53348013
commit
4e4ecbbfca
318 files changed
+6012
-1184
No files matched your search
@@ -1,8 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Presentation.Api.Common.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries;
|
||||
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.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system directories.
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class DirectoriesController : ApiController
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly ISender _mediator;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DirectoriesController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediator">Injected service for mediating commands and queries.</param>
|
||||
public DirectoriesController(ISender mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets the tree of expanded directories leading up to <paramref name="path"/>, with the additional list of drives, and children of the last child directory.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the directory tree.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-directory-tree")]
|
||||
public async IAsyncEnumerable<FileSystemTreeNodeResponse> GetDirectoryTree([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _mediator.Send(new GetDirectoryTreeQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsError && result.Value is not null)
|
||||
{
|
||||
foreach (var treeNode in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return treeNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directories of <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the directories.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-directories")]
|
||||
public async IAsyncEnumerable<FileSystemTreeNodeResponse> GetDirectories([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _mediator.Send(new GetDirectoriesQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsError && result.Value is not null)
|
||||
{
|
||||
foreach (var directory in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return directory;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileManagement.Drives.Queries;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system drives.
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class DrivesController : ApiController
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly ISender _mediator;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DrivesController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediator">Injected service for mediating commands and queries.</param>
|
||||
public DrivesController(ISender mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Controller action for getting the list of all file system drives.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-drives")]
|
||||
public async Task<IActionResult> GetDrives(CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _mediator.Send(new GetDrivesQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(result => Ok(result), errors => Problem(errors));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileManagement.FileSystem.Queries;
|
||||
using Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file systems.
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/file-system")]
|
||||
public class FileSystemController : ApiController
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly ISender _mediator;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediator">Injected service for mediating commands and queries.</param>
|
||||
public FileSystemController(ISender mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets the type of the file system.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-type")]
|
||||
public async Task<IActionResult> GetType(CancellationToken cancellationToken)
|
||||
{
|
||||
var platformType = await _mediator.Send(new GetFileSystemQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return Ok(platformType);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileManagement.Files.Queries;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Presentation.Api.Common.ModelBinders;
|
||||
using Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
using MapsterMapper;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system files.
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class FilesController : ApiController
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly ISender _mediator;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FilesController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediator">Injected service for mediating commands and queries.</param>
|
||||
public FilesController(ISender mediator, IMapper mapper)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets the files of <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the files.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-files")]
|
||||
public async IAsyncEnumerable<FileSystemTreeNodeResponse> GetFiles([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new GetFilesQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
foreach (var file in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return file;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Presentation.Api.Common.ModelBinders;
|
||||
using Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
using MapsterMapper;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing file system paths.
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class PathController : ApiController
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly ISender _mediator;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PathController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediator">Injected service for mediating commands and queries.</param>
|
||||
public PathController(ISender mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets the root of <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the root.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-path-root")]
|
||||
public async Task<IActionResult> GetPathRoot([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<PathSegmentResponse> result = await _mediator.Send(new GetPathRootQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(result => Ok(result), errors => Problem(errors));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combines <paramref name="originalPath"/> with <paramref name="newPath"/>.
|
||||
/// </summary>
|
||||
/// <param name="originalPath">The path to combine to.</param>
|
||||
/// <param name="newPath">The path to combine with.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("combine")]
|
||||
public async Task<IActionResult> CombinePath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string originalPath, [FromQuery, ModelBinder(typeof(UrlStringBinder))] string newPath, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<PathSegmentResponse> result = await _mediator.Send(new CombinePathCommand(originalPath, newPath), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(result => Ok(result), errors => Problem(errors));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path separator character of the file system.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("get-path-separator")]
|
||||
public async Task<IActionResult> GetPathSeparator(CancellationToken cancellationToken)
|
||||
{
|
||||
PathSeparatorResponse result = await _mediator.Send(new GetPathSeparatorQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path components of <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to get the path segments.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("split")]
|
||||
public async Task<IActionResult> SplitPath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _mediator.Send(new SplitPathCommand(path), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(result => Ok(result), errors => Problem(errors));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.Maintenance;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for health checks.
|
||||
/// </summary>
|
||||
[Route("[controller]")]
|
||||
public class HealthController : ApiController
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Checks if the application is healthy.
|
||||
/// </summary>
|
||||
[HttpGet("check-health")]
|
||||
public async Task<IActionResult> CheckHealth()
|
||||
{
|
||||
// TODO: to be implemented
|
||||
return Ok();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands;
|
||||
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries;
|
||||
using Lumina.Presentation.Api.Common.Contracts.Books;
|
||||
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
using MapsterMapper;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.WrittenContentLibrary.BookLibrary.Books;
|
||||
@@ -26,7 +27,7 @@ public class BooksController : ApiController
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BooksController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediator">Injecting service for mediating commands and queries.</param>
|
||||
/// <param name="mediator">Injected service for mediating commands and queries.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public BooksController(ISender mediator, IMapper mapper)
|
||||
{
|
||||
@@ -42,7 +43,7 @@ public class BooksController : ApiController
|
||||
[HttpGet()]
|
||||
public async Task<IActionResult> GetBooks()
|
||||
{
|
||||
var result = await _mediator.Send(new GetBooksQuery());
|
||||
var result = await _mediator.Send(new GetBooksQuery()).ConfigureAwait(false);
|
||||
return result.Match(result => Ok(result), errors => Problem(errors));
|
||||
}
|
||||
|
||||
@@ -53,7 +54,7 @@ public class BooksController : ApiController
|
||||
[HttpPost()]
|
||||
public async Task<IActionResult> AddBook(AddBookRequest request)
|
||||
{
|
||||
var result = await _mediator.Send(_mapper.Map<AddBookCommand>(request));
|
||||
var result = await _mediator.Send(_mapper.Map<AddBookCommand>(request)).ConfigureAwait(false);
|
||||
return result.Match(result => Created($"/api/v1/books/{result.Id}", result), errors => Problem(errors));
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in new issue
Block a user