mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Adds editorconfig and refactors to the established rules
This commit is contained in:
1 parent
712a0f2b27
commit
cd44f11d9e
138 files changed
+1799
-1629
No files matched your search
@@ -36,8 +36,8 @@ public class ConfigureSwaggerOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
||||
public void Configure(SwaggerGenOptions options)
|
||||
{
|
||||
// add swagger document for every API version discovered
|
||||
foreach (var description in _provider.ApiVersionDescriptions)
|
||||
options.SwaggerDoc(description.GroupName,CreateVersionInfo(description));
|
||||
foreach (ApiVersionDescription description in _provider.ApiVersionDescriptions)
|
||||
options.SwaggerDoc(description.GroupName, CreateVersionInfo(description));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +57,7 @@ public class ConfigureSwaggerOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
||||
/// <returns>The created <see cref="OpenApiInfo"/> instance.</returns>
|
||||
private OpenApiInfo CreateVersionInfo(ApiVersionDescription description)
|
||||
{
|
||||
var info = new OpenApiInfo()
|
||||
OpenApiInfo info = new()
|
||||
{
|
||||
Title = "Lumina API",
|
||||
Version = description.ApiVersion.ToString()
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ internal static class PresentationApiLayerConfiguration
|
||||
/// <exception cref="DirectoryNotFoundException">Thrown when the base path where the configuration files should be located, does not exist.</exception>
|
||||
public static IServiceCollection BindPresentationApiLayerConfiguration(this IServiceCollection services, IConfigurationManager configuration)
|
||||
{
|
||||
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
string? basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
if (!Directory.Exists(basePath))
|
||||
throw new DirectoryNotFoundException($"The base path '{basePath}' does not exist.");
|
||||
configuration.SetBasePath(basePath);
|
||||
|
||||
+4
-7
@@ -25,14 +25,11 @@ public static class PresentationApiLayerServices
|
||||
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddPresentationApiLayerServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll",
|
||||
services.AddCors(options => options.AddPolicy("AllowAll",
|
||||
builder => builder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader());
|
||||
});
|
||||
.AllowAnyHeader()));
|
||||
|
||||
// add services to the container
|
||||
services.AddControllers().AddJsonOptions(options =>
|
||||
@@ -45,7 +42,7 @@ public static class PresentationApiLayerServices
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen();
|
||||
services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
|
||||
services.AddApiVersioning(options =>
|
||||
{
|
||||
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
@@ -62,7 +59,7 @@ public static class PresentationApiLayerServices
|
||||
services.AddSingleton<ProblemDetailsFactory, CustomProblemDetailsFactory>();
|
||||
|
||||
// register mapster configs
|
||||
var mapsterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
TypeAdapterConfig mapsterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
mapsterConfig.Scan(typeof(PresentationApiLayerServices).Assembly);
|
||||
services.AddSingleton(mapsterConfig);
|
||||
services.AddScoped<IMapper, ServiceMapper>();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
string? detail = null, string? instance = null)
|
||||
{
|
||||
statusCode ??= 500;
|
||||
var problemDetails = new ProblemDetails
|
||||
ProblemDetails problemDetails = new()
|
||||
{
|
||||
Status = statusCode,
|
||||
Title = title,
|
||||
@@ -81,7 +81,7 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(modelStateDictionary);
|
||||
statusCode ??= 400;
|
||||
var problemDetails = new ValidationProblemDetails(modelStateDictionary)
|
||||
ValidationProblemDetails problemDetails = new(modelStateDictionary)
|
||||
{
|
||||
Status = statusCode,
|
||||
Type = type,
|
||||
@@ -104,23 +104,20 @@ 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 ClientErrorData? clientErrorData))
|
||||
{
|
||||
problemDetails.Title ??= clientErrorData.Title;
|
||||
problemDetails.Type ??= clientErrorData.Link;
|
||||
}
|
||||
var traceId = Activity.Current?.Id ?? httpContext?.TraceIdentifier;
|
||||
string? traceId = Activity.Current?.Id ?? httpContext?.TraceIdentifier;
|
||||
if (traceId != null)
|
||||
problemDetails.Extensions["traceId"] = traceId;
|
||||
// get any errors that might be sent by ApiController base class' Problem() method
|
||||
var errors = httpContext?.Items[HttpContextItemKeys.ERRORS] as List<Error>;
|
||||
List<Error>? errors = httpContext?.Items[HttpContextItemKeys.ERRORS] as List<Error>;
|
||||
// add any extra custom properties
|
||||
if (errors is not null)
|
||||
{
|
||||
problemDetails.Extensions.Add("errors", errors.Select(error =>
|
||||
{
|
||||
return error.Code;
|
||||
}));
|
||||
problemDetails.Extensions.Add("errors", errors.Select(error => error.Code));
|
||||
}
|
||||
//problemDetails.Extensions.Add("errorCodes", errors.Select(e => e.Type.ToString()));
|
||||
_configure?.Invoke(new() { HttpContext = httpContext!, ProblemDetails = problemDetails });
|
||||
|
||||
@@ -23,7 +23,7 @@ public class UrlStringBinder : IModelBinder
|
||||
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);
|
||||
ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
|
||||
if (valueProviderResult == ValueProviderResult.None)
|
||||
return Task.CompletedTask;
|
||||
string? value = valueProviderResult.FirstValue;
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class ApiController : ControllerBase
|
||||
/// <param name="error">The error to convert.</param>
|
||||
protected internal IActionResult Problem(Error error)
|
||||
{
|
||||
var statusCode = error.Type switch
|
||||
int statusCode = error.Type switch
|
||||
{
|
||||
ErrorType.Conflict => StatusCodes.Status409Conflict,
|
||||
ErrorType.NotFound => StatusCodes.Status404NotFound,
|
||||
@@ -62,8 +62,8 @@ public abstract class ApiController : ControllerBase
|
||||
/// <param name="errors">The list of errors to convert.</param>
|
||||
protected internal IActionResult ValidationProblem(List<Error> errors)
|
||||
{
|
||||
var modelStateDictionary = new ModelStateDictionary();
|
||||
foreach (var error in errors)
|
||||
ModelStateDictionary modelStateDictionary = new();
|
||||
foreach (Error error in errors)
|
||||
modelStateDictionary.AddModelError(error.Code, error.Description);
|
||||
return ValidationProblem(modelStateDictionary: modelStateDictionary, title: "One or more validation errors occurred.");
|
||||
}
|
||||
|
||||
+3
-3
@@ -49,7 +49,7 @@ public class DirectoriesController : ApiController
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _mediator.Send(new GetDirectoryTreeQuery(path, includeFiles), cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsError && result.Value is not null)
|
||||
{
|
||||
foreach (var treeNode in result.Value)
|
||||
foreach (FileSystemTreeNodeResponse treeNode in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
@@ -69,7 +69,7 @@ public class DirectoriesController : ApiController
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _mediator.Send(new GetTreeDirectoriesQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsError && result.Value is not null)
|
||||
{
|
||||
foreach (var directory in result.Value)
|
||||
foreach (FileSystemTreeNodeResponse directory in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
@@ -89,7 +89,7 @@ public class DirectoriesController : ApiController
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _mediator.Send(new GetDirectoriesQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsError && result.Value is not null)
|
||||
{
|
||||
foreach (var directory in result.Value)
|
||||
foreach (DirectoryResponse directory in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class DrivesController : ApiController
|
||||
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));
|
||||
return result.Match(Ok, Problem);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSysem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -39,8 +40,8 @@ public class FileSystemController : ApiController
|
||||
[HttpGet("get-type")]
|
||||
public async Task<IActionResult> GetType(CancellationToken cancellationToken)
|
||||
{
|
||||
var platformType = await _mediator.Send(new GetFileSystemQuery(), cancellationToken).ConfigureAwait(false);
|
||||
FileSystemTypeResponse platformType = await _mediator.Send(new GetFileSystemQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return Ok(platformType);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class FilesController : ApiController
|
||||
public async IAsyncEnumerable<FileSystemTreeNodeResponse> GetTreeFiles([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _mediator.Send(new GetTreeFilesQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
foreach (var file in result.Value)
|
||||
foreach (FileSystemTreeNodeResponse file in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
@@ -66,7 +66,7 @@ public class FilesController : ApiController
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _mediator.Send(new GetFilesQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
if (!result.IsError)
|
||||
{
|
||||
foreach (var file in result.Value)
|
||||
foreach (FileResponse file in result.Value)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PathController : ApiController
|
||||
_mediator = mediator;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets the root of <paramref name="path"/>.
|
||||
@@ -51,7 +51,7 @@ public class PathController : ApiController
|
||||
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));
|
||||
return result.Match(Ok, Problem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,7 +74,7 @@ public class PathController : ApiController
|
||||
public async Task<IActionResult> GetPathParent([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _mediator.Send(new GetPathParentQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(result => Ok(result), errors => Problem(errors));
|
||||
return result.Match(Ok, Problem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,7 +87,7 @@ public class PathController : ApiController
|
||||
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));
|
||||
return result.Match(Ok, Problem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,7 +99,7 @@ public class PathController : ApiController
|
||||
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));
|
||||
return result.Match(Ok, Problem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Api.Core.Controllers.Common;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
@@ -20,7 +20,7 @@ public class HealthController : ApiController
|
||||
public async Task<IActionResult> CheckHealth()
|
||||
{
|
||||
// TODO: to be implemented
|
||||
return Ok();
|
||||
return await Task.FromResult(Ok());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+4
-4
@@ -43,8 +43,8 @@ public class BooksController : ApiController
|
||||
[HttpGet()]
|
||||
public async Task<IActionResult> GetBooks()
|
||||
{
|
||||
var result = await _mediator.Send(new GetBooksQuery()).ConfigureAwait(false);
|
||||
return result.Match(result => Ok(result), errors => Problem(errors));
|
||||
ErrorOr.ErrorOr<System.Collections.Generic.IEnumerable<Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Book>> result = await _mediator.Send(new GetBooksQuery()).ConfigureAwait(false);
|
||||
return result.Match(Ok, Problem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,8 +54,8 @@ public class BooksController : ApiController
|
||||
[HttpPost()]
|
||||
public async Task<IActionResult> AddBook(AddBookRequest 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));
|
||||
ErrorOr.ErrorOr<Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Book> result = await _mediator.Send(_mapper.Map<AddBookCommand>(request)).ConfigureAwait(false);
|
||||
return result.Match(result => Created($"/api/v1/books/{result.Id}", result), Problem);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\server\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<UserSecretsId>37d55c87-4374-4971-82e9-012fcaad1853</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<ContainerRepository>lumina-server</ContainerRepository>
|
||||
@@ -17,7 +17,6 @@
|
||||
<Compile Include="..\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.1" />
|
||||
@@ -53,6 +52,10 @@
|
||||
<ProjectReference Include="..\Lumina.Contracts\Lumina.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Lumina.Infrastructure\Lumina.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Lumina.DataAccess\Lumina.DataAccess.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<!--disable warnings generated by Mediator source generator-->
|
||||
<PropertyGroup>
|
||||
<NoWarn>$(NoWarn);CS0436</NoWarn>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DependencyInjection;
|
||||
using Lumina.DataAccess.Common.DependencyInjection;
|
||||
using Lumina.Domain.Common.DependencyInjection;
|
||||
using Lumina.Infrastructure.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;
|
||||
@@ -23,8 +23,8 @@ public class Program
|
||||
/// <param name="args">Optional command line arguments.</param>
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.BindSharedConfiguration(builder.Configuration);
|
||||
builder.Services.BindPresentationApiLayerConfiguration(builder.Configuration);
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Program
|
||||
builder.Services.AddDataAccessLayerServices();
|
||||
builder.Services.AddDomainLayerServices();
|
||||
|
||||
var app = builder.Build();
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
|
||||
|
||||
Reference in new issue
Block a user