Adds editorconfig and refactors to the established rules

This commit is contained in:
BinaryAlley committed 2024-09-23 16:48:48 +03:00
1 parent 712a0f2b27
commit cd44f11d9e
138 files changed
+1799 -1629

No files matched your search

@@ -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.");
}
@@ -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
}
@@ -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
}