diff --git a/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageValidationUseCase.cs b/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageValidationUseCase.cs index b0ff6f2..c00d3ce 100644 --- a/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageValidationUseCase.cs +++ b/geometrix-api/Geometrix.Application/UseCases/GenerateImage/GenerateImageValidationUseCase.cs @@ -3,25 +3,17 @@ namespace Geometrix.Application.UseCases.GenerateImage; -public sealed class GenerateImageValidationUseCase : IGenerateImageUseCase +public sealed class GenerateImageValidationUseCase( + IGenerateImageUseCase useCase, + Notification notification) + : IGenerateImageUseCase { - private readonly IGenerateImageUseCase _useCase; - private readonly Notification _notification; - private IOutputPort _outputPort; - - public GenerateImageValidationUseCase( - IGenerateImageUseCase useCase, - Notification notification) - { - _useCase = useCase; - _notification = notification; - _outputPort = new GenerateImagePresenter(); - } + private IOutputPort _outputPort = new GenerateImagePresenter(); public void SetOutputPort(IOutputPort outputPort) { _outputPort = outputPort; - _useCase.SetOutputPort(outputPort); + useCase.SetOutputPort(outputPort); } public async Task Execute( @@ -36,31 +28,31 @@ public async Task Execute( { if (mirrorPowerHorizontal is < 1 or > 4) { - _notification + notification .Add(nameof(mirrorPowerHorizontal), "MirrorPowerHorizontal is required."); } if (mirrorPowerVertical is < 1 or > 4) { - _notification + notification .Add(nameof(mirrorPowerVertical), "MirrorPowerVertical is required."); } if (cellGroupLength is < 2 or > 8) { - _notification + notification .Add(nameof(cellGroupLength), "CellGroupLength is required."); } if (cellWidthPixel is < 32 or > 256) { - _notification + notification .Add(nameof(cellWidthPixel), "CellWidthPixel is required."); } if (seed is < 0 or > 100000) { - _notification + notification .Add(nameof(seed), "Seed is required."); } @@ -74,7 +66,7 @@ public async Task Execute( backgroundColor != ThemeColor.Purple.Value && backgroundColor != ThemeColor.Pink.Value) { - _notification + notification .Add(nameof(backgroundColor), "BackgroundColor is required."); } @@ -88,17 +80,17 @@ public async Task Execute( foregroundColor != ThemeColor.Purple.Value && foregroundColor != ThemeColor.Pink.Value) { - _notification + notification .Add(nameof(backgroundColor), "ForegroundColor is required."); } - if (_notification.IsInvalid) + if (notification.IsInvalid) { _outputPort.Invalid(); return; } - await _useCase + await useCase .Execute( mirrorPowerHorizontal, mirrorPowerVertical, cellGroupLength, cellWidthPixel, includeEmptyAndFill, seed, diff --git a/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs b/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs index 92873c2..500fabf 100644 --- a/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs +++ b/geometrix-api/Geometrix.Domain/ValueObjects/TriangleDirection.cs @@ -1,13 +1,9 @@ namespace Geometrix.Domain.ValueObjects; -public readonly struct TriangleDirection : IEquatable +public readonly struct TriangleDirection(TriangleDirection.Direction value) + : IEquatable { - public Direction Value { get; } - - public TriangleDirection(Direction value) - { - Value = value; - } + public Direction Value { get; } = value; public override bool Equals(object? obj) { diff --git a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs index 412e1f9..912050c 100644 --- a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs +++ b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageService.cs @@ -5,26 +5,18 @@ namespace Geometrix.Infrastructure.FileStorage; [Obsolete("Use FileStorageServiceV2 instead")] -public class FileStorageService : IFileStorageService +public class FileStorageService( + IHostEnvironment env, + ILogger logger) + : IFileStorageService { - private readonly IHostEnvironment _env; - private readonly ILogger _logger; - - public FileStorageService( - IHostEnvironment env, - ILogger logger) - { - _env = env; - _logger = logger; - } - public async Task SaveFileAsync( byte[] dataArray, string nameWithoutExtension, string extension = "") { var fileName = $"{nameWithoutExtension}.png"; - var path = Path.Combine(_env.ContentRootPath, "wwwroot", "images"); + var path = Path.Combine(env.ContentRootPath, "wwwroot", "images"); if (!Directory.Exists(path)) { @@ -50,11 +42,11 @@ public FileStorageService( if (dataArray[i] == fileStream.ReadByte()) continue; - _logger.LogError("Error writing data"); + logger.LogError("Error writing data"); return null; } - _logger.LogInformation("The data was written to {Name} and verified", fileStream.Name); + logger.LogInformation("The data was written to {Name} and verified", fileStream.Name); return fileName; } diff --git a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs index 638594b..a0a6989 100644 --- a/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs +++ b/geometrix-api/Geometrix.Infrastructure/FileStorage/FileStorageServiceV2.cs @@ -4,28 +4,21 @@ namespace Geometrix.Infrastructure.FileStorage; -public class FileStorageServiceV2 : IFileStorageService +public class FileStorageServiceV2( + IHostEnvironment env, + ILogger logger) + : IFileStorageService { - private readonly IHostEnvironment _env; - private readonly ILogger _logger; private const string DefaultImageExtension = ".png"; private const string DefaultImageFolder = "wwwroot/images"; - public FileStorageServiceV2( - IHostEnvironment env, - ILogger logger) - { - _env = env; - _logger = logger; - } - public async Task SaveFileAsync( byte[] dataArray, string nameWithoutExtension, string extension = DefaultImageExtension) { var fileName = $"{nameWithoutExtension}{extension}"; - var path = Path.Combine(_env.ContentRootPath, DefaultImageFolder); + var path = Path.Combine(env.ContentRootPath, DefaultImageFolder); if (!Directory.Exists(path)) { @@ -37,12 +30,12 @@ public FileStorageServiceV2( try { await File.WriteAllBytesAsync(fullFileLocation, dataArray); - _logger.LogInformation("The data was written to {Name}", fullFileLocation); + logger.LogInformation("The data was written to {Name}", fullFileLocation); return Path.GetFileName(fullFileLocation); } catch (Exception ex) { - _logger.LogError(ex, "Error writing data to {Name}", fullFileLocation); + logger.LogError(ex, "Error writing data to {Name}", fullFileLocation); return null; } } diff --git a/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs b/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs index 1f0b426..02275a5 100644 --- a/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs +++ b/geometrix-api/Geometrix.WebApi/Modules/Common/LoggingExtensions.cs @@ -29,7 +29,7 @@ public static IServiceCollection AddInvalidRequestLogging(this IServiceCollectio .ToList(); var jsonModelState = JsonSerializer.Serialize(errors); - logger.LogWarning("Invalid request {jsonModelState}", jsonModelState); + logger.LogWarning("Invalid request {JsonModelState}", jsonModelState); var problemDetails = new ValidationProblemDetails(actionContext.ModelState); return new BadRequestObjectResult(problemDetails); diff --git a/geometrix-api/Geometrix.WebApi/Program.cs b/geometrix-api/Geometrix.WebApi/Program.cs index 9575a72..eb3bb6d 100644 --- a/geometrix-api/Geometrix.WebApi/Program.cs +++ b/geometrix-api/Geometrix.WebApi/Program.cs @@ -16,6 +16,6 @@ public static void Main(string[] args) private static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostContext, configApp) => { configApp.AddCommandLine(args); }) + .ConfigureAppConfiguration((_, configApp) => { configApp.AddCommandLine(args); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); } \ No newline at end of file