mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07: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,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
using Lumina.Application.Common.Models.Contributors;
|
||||
using Lumina.Domain.Common.Enums;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Common.Contracts.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to add a book.
|
||||
/// </summary>
|
||||
public record AddBookRequest(
|
||||
WrittenContentMetadataDto? Metadata,
|
||||
BookFormat? Format,
|
||||
string? Edition,
|
||||
int? VolumeNumber,
|
||||
BookSeriesDto? Series,
|
||||
string? ASIN,
|
||||
string? GoodreadsId,
|
||||
string? LCCN,
|
||||
string? OCLCNumber,
|
||||
string? OpenLibraryId,
|
||||
string? LibraryThingId,
|
||||
string? GoogleBooksId,
|
||||
string? BarnesAndNobleId,
|
||||
string? AppleBooksId,
|
||||
List<IsbnDto>? ISBNs,
|
||||
List<MediaContributorDto>? Contributors,
|
||||
List<BookRatingDto>? Ratings
|
||||
);
|
||||
Whitespace-only changes.
+3
-1
@@ -1,4 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
#endregion
|
||||
|
||||
@@ -26,7 +29,6 @@ internal static class PresentationApiLayerConfiguration
|
||||
configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
configuration.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true);
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
#endregion
|
||||
|
||||
+2
-1
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Text.Json.Serialization;
|
||||
using Lumina.Application.Common.Converters;
|
||||
using Lumina.Presentation.Api.Common.Configuration;
|
||||
using Lumina.Presentation.Api.Common.Errors;
|
||||
@@ -7,6 +6,8 @@ using Mapster;
|
||||
using MapsterMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Common.DependencyInjection;
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Lumina.Presentation.Api.Common.Http;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Problem details abstract factory which adds custom properties to the default implementation provided by Microsoft
|
||||
/// Problem details factory which adds custom properties to the default implementation provided by Microsoft.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Creation Date: 14th of July, 2023
|
||||
/// </remarks>
|
||||
public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly ApiBehaviorOptions options;
|
||||
private readonly Action<ProblemDetailsContext>? configure;
|
||||
private readonly ApiBehaviorOptions _options;
|
||||
private readonly Action<ProblemDetailsContext>? _configure;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor
|
||||
/// Initializes a new instance of the <see cref="CustomProblemDetailsFactory"/> class.
|
||||
/// </summary>
|
||||
/// <param name="options">Injected service for retrieving ApiBehaviorOptions</param>
|
||||
/// <param name="problemDetailsOptions">Injected service for retrieving ProblemDetailsOptions</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the value of options (if any) is null</exception>
|
||||
/// <param name="options">Injected service for retrieving <see cref="ApiBehaviorOptions"/>.</param>
|
||||
/// <param name="problemDetailsOptions">Injected service for retrieving <see cref="ProblemDetailsOptions"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the value of options (if any) is <see langword="null"/>.</exception>
|
||||
public CustomProblemDetailsFactory(IOptions<ApiBehaviorOptions> options, IOptions<ProblemDetailsOptions>? problemDetailsOptions = null)
|
||||
{
|
||||
this.options = options?.Value ?? throw new ArgumentNullException(nameof(options));
|
||||
configure = problemDetailsOptions?.Value?.CustomizeProblemDetails;
|
||||
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));
|
||||
_configure = problemDetailsOptions?.Value?.CustomizeProblemDetails;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -103,7 +104,7 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
private void ApplyProblemDetailsDefaults(HttpContext httpContext, ProblemDetails problemDetails, int statusCode)
|
||||
{
|
||||
problemDetails.Status ??= statusCode;
|
||||
if (options.ClientErrorMapping.TryGetValue(statusCode, out var clientErrorData))
|
||||
if (_options.ClientErrorMapping.TryGetValue(statusCode, out var clientErrorData))
|
||||
{
|
||||
problemDetails.Title ??= clientErrorData.Title;
|
||||
problemDetails.Type ??= clientErrorData.Link;
|
||||
@@ -116,13 +117,13 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
// add any extra custom properties
|
||||
if (errors is not null)
|
||||
{
|
||||
problemDetails.Extensions.Add("errors", errors.Select(e =>
|
||||
problemDetails.Extensions.Add("errors", errors.Select(error =>
|
||||
{
|
||||
return e.Code;
|
||||
return error.Code;
|
||||
}));
|
||||
}
|
||||
//problemDetails.Extensions.Add("errorCodes", errors.Select(e => e.Type.ToString()));
|
||||
configure?.Invoke(new() { HttpContext = httpContext!, ProblemDetails = problemDetails });
|
||||
_configure?.Invoke(new() { HttpContext = httpContext!, ProblemDetails = problemDetails });
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+2
-3
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands;
|
||||
using Lumina.Presentation.Api.Common.Contracts.Books;
|
||||
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary;
|
||||
using Mapster;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Common.Mapping;
|
||||
namespace Lumina.Presentation.Api.Common.Mapping.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Mapping configuration for books between the API request object and the command object.
|
||||
@@ -24,7 +24,6 @@ public class BookMappingConfig : IRegister
|
||||
.Map(dest => dest.LCCN, src => src.LCCN)
|
||||
.Map(dest => dest.OCLCNumber, src => src.OCLCNumber)
|
||||
.MapToConstructor(true);
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Common.ModelBinders;
|
||||
|
||||
/// <summary>
|
||||
/// Custom model binder for URL parameters. For some reason, the default binder converts "%20" to "+", instead of " ".
|
||||
/// </summary>
|
||||
public class UrlStringBinder : IModelBinder
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Binds a model to a value by using the specified controller context and binding context.
|
||||
/// </summary>
|
||||
/// <param name="bindingContext">The context within which to bind the model.</param>
|
||||
/// <returns>A task representing the bind operation.</returns>
|
||||
public Task BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
if (bindingContext is null)
|
||||
throw new ArgumentNullException(nameof(bindingContext));
|
||||
string modelName = bindingContext.ModelName;
|
||||
// try to fetch the value of the argument by name
|
||||
var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
|
||||
if (valueProviderResult == ValueProviderResult.None)
|
||||
return Task.CompletedTask;
|
||||
string? value = valueProviderResult.FirstValue;
|
||||
if (value is null)
|
||||
{
|
||||
bindingContext.Result = ModelBindingResult.Failed();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
// do the custom decoding here
|
||||
value = Uri.UnescapeDataString(value);
|
||||
bindingContext.Result = ModelBindingResult.Success(value);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,7 @@ WORKDIR /src
|
||||
COPY ["AssemblyInfo_Shared.cs", "."]
|
||||
COPY ["Lumina.Presentation.Api/Lumina.Presentation.Api.csproj", "Lumina.Presentation.Api/"]
|
||||
COPY ["Lumina.Application/Lumina.Application.csproj", "Lumina.Application/"]
|
||||
COPY ["Lumina.Contracts/Lumina.Contracts.csproj", "Lumina.Contracts/"]
|
||||
COPY ["Lumina.Domain/Lumina.Domain.csproj", "Lumina.Domain/"]
|
||||
COPY ["Lumina.Infrastructure/Lumina.Infrastructure.csproj", "Lumina.Infrastructure/"]
|
||||
COPY ["Lumina.DataAccess/Lumina.DataAccess.csproj", "Lumina.DataAccess/"]
|
||||
@@ -24,6 +25,7 @@ RUN dotnet restore "./Lumina.Presentation.Api/Lumina.Presentation.Api.csproj" /p
|
||||
# build the project
|
||||
COPY ["Lumina.Presentation.Api/", "Lumina.Presentation.Api/"]
|
||||
COPY ["Lumina.Application/", "Lumina.Application/"]
|
||||
COPY ["Lumina.Contracts/", "Lumina.Contracts/"]
|
||||
COPY ["Lumina.Domain/", "Lumina.Domain/"]
|
||||
COPY ["Lumina.Infrastructure/", "Lumina.Infrastructure/"]
|
||||
COPY ["Lumina.DataAccess/", "Lumina.DataAccess/"]
|
||||
|
||||
@@ -48,7 +48,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lumina.Contracts\Lumina.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Lumina.Application\Lumina.Application.csproj" />
|
||||
<ProjectReference Include="..\Lumina.Contracts\Lumina.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Lumina.Infrastructure\Lumina.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Lumina.DataAccess\Lumina.DataAccess.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
@Lumina.Presentation.Api_HostAddress = http://localhost:5214
|
||||
|
||||
GET {{Lumina.Presentation.Api_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
@@ -1,8 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Api.Common.DependencyInjection;
|
||||
using Lumina.Application.Common.DependencyInjection;
|
||||
using Lumina.DataAccess.Common.DependencyInjection;
|
||||
using Lumina.Infrastructure.Common.DependencyInjection;
|
||||
using Lumina.DataAccess.Common.DependencyInjection;
|
||||
using Lumina.Presentation.Api.Common.DependencyInjection;
|
||||
using Lumina.Domain.Common.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api;
|
||||
@@ -17,17 +21,18 @@ public class Program
|
||||
/// Application entry point.
|
||||
/// </summary>
|
||||
/// <param name="args">Optional command line arguments.</param>
|
||||
static void Main(string[] args)
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.BindSharedConfiguration(builder.Configuration);
|
||||
builder.Services.BindPresentationApiLayerConfiguration(builder.Configuration);
|
||||
|
||||
builder.Services.AddApplicationLayerServices();
|
||||
builder.Services.AddPresentationApiLayerServices();
|
||||
builder.Services.AddApplicationLayerServices();
|
||||
builder.Services.AddInfrastructureLayerServices();
|
||||
builder.Services.AddDataAccessLayerServices();
|
||||
builder.Services.AddDomainLayerServices();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@@ -42,11 +47,11 @@ public class Program
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
//app.UseHttpsRedirection();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
await app.RunAsync().ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user