mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13: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
|
||||
}
|
||||
Reference in new issue
Block a user