diff --git a/CHANGELOG.md b/CHANGELOG.md index d248da67..9175d26a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +## [v6.0.0](https://github.com/Genocs/genocs-library/compare/6.0.0-preview.2.0...v6.0.0) - 2024-07-31 + +### Commits + +- Refactor and update dependencies and logging level [`63533a2`](https://github.com/Genocs/genocs-library/commit/63533a2ccfb64106dd81e296ca1a1de55c556f48) +- Refactor auth and update docs [`a63d816`](https://github.com/Genocs/genocs-library/commit/a63d816a4b617246ec99b3400d019a1b46ff40b0) +- Update packages, fix typos, and improve code formatting [`d634694`](https://github.com/Genocs/genocs-library/commit/d6346942c88195b831bd66f4ff8a1e039695e0b2) + ## [6.0.0-preview.2.0](https://github.com/Genocs/genocs-library/compare/v5.0.0-preview.4.0...6.0.0-preview.2.0) - 2024-07-19 ### Merged diff --git a/src/Genocs.Core.Demo.WebApi/appsettings.json b/src/Genocs.Core.Demo.WebApi/appsettings.json index 9b1118fd..950182b6 100644 --- a/src/Genocs.Core.Demo.WebApi/appsettings.json +++ b/src/Genocs.Core.Demo.WebApi/appsettings.json @@ -8,7 +8,7 @@ "displayVersion": true }, "logger": { - "level": "information", + "level": "debug", "applicationName": "demo-service", "excludePaths": [ "/ping", "/metrics" ], "console": { diff --git a/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj b/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj index c765a4f7..c84a28cb 100644 --- a/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj +++ b/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj @@ -24,7 +24,7 @@ - + diff --git a/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj b/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj index b9975502..8642f97e 100644 --- a/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj +++ b/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj @@ -8,8 +8,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Genocs.Core/Genocs.Core.csproj b/src/Genocs.Core/Genocs.Core.csproj index 6e259383..98c15645 100644 --- a/src/Genocs.Core/Genocs.Core.csproj +++ b/src/Genocs.Core/Genocs.Core.csproj @@ -70,9 +70,9 @@ - + - + diff --git a/src/Genocs.Logging/Genocs.Logging.csproj b/src/Genocs.Logging/Genocs.Logging.csproj index b85b5d30..ab8b4c62 100644 --- a/src/Genocs.Logging/Genocs.Logging.csproj +++ b/src/Genocs.Logging/Genocs.Logging.csproj @@ -60,7 +60,7 @@ - + diff --git a/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj b/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj index 71219a19..1c501e5e 100644 --- a/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj +++ b/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj @@ -12,8 +12,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj b/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj index 8c493814..d68c3f84 100644 --- a/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj +++ b/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj @@ -13,9 +13,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Genocs.Secrets.AzureKeyVault/Configurations/AzureKeyVaultOptions.cs b/src/Genocs.Secrets.AzureKeyVault/Configurations/AzureKeyVaultOptions.cs index 62ca3c4f..3ccab105 100644 --- a/src/Genocs.Secrets.AzureKeyVault/Configurations/AzureKeyVaultOptions.cs +++ b/src/Genocs.Secrets.AzureKeyVault/Configurations/AzureKeyVaultOptions.cs @@ -1,7 +1,7 @@ namespace Genocs.Secrets.AzureKeyVault.Configurations; /// -/// The vault Setting definition. +/// The Azure Kay Vault setting definition. /// public class AzureKeyVaultOptions { diff --git a/src/Genocs.Secrets.AzureKeyVault/Extensions.cs b/src/Genocs.Secrets.AzureKeyVault/Extensions.cs index 7daa3896..5615cd88 100644 --- a/src/Genocs.Secrets.AzureKeyVault/Extensions.cs +++ b/src/Genocs.Secrets.AzureKeyVault/Extensions.cs @@ -38,11 +38,11 @@ public static IHostBuilder UseAzureKeyVault( } cfg.AddAzureKeyVault( - new Uri($"https://{settings.Name}.vault.azure.net/"), - new DefaultAzureCredential(new DefaultAzureCredentialOptions - { - ManagedIdentityClientId = settings.ManagedIdentityId - })); + new Uri($"https://{settings.Name}.vault.azure.net/"), + new DefaultAzureCredential(new DefaultAzureCredentialOptions + { + ManagedIdentityClientId = settings.ManagedIdentityId + })); }); /// @@ -56,6 +56,11 @@ public static IWebHostBuilder UseAzureKeyVault( string sectionName = AzureKeyVaultOptions.Position) => builder.ConfigureAppConfiguration((ctx, cfg) => { + if (string.IsNullOrWhiteSpace(sectionName)) + { + sectionName = AzureKeyVaultOptions.Position; + } + AzureKeyVaultOptions settings = ctx.Configuration.GetOptions(sectionName); if (!settings.Enabled) { diff --git a/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj b/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj index 52ee0ab7..52a49d87 100644 --- a/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj +++ b/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj @@ -8,8 +8,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/apps/identity/Genocs.Identities.Application/DTO/AuthDto.cs b/src/apps/identity/Genocs.Identities.Application/DTO/AuthDto.cs index 403e9fd5..a5652115 100644 --- a/src/apps/identity/Genocs.Identities.Application/DTO/AuthDto.cs +++ b/src/apps/identity/Genocs.Identities.Application/DTO/AuthDto.cs @@ -1,11 +1,14 @@ namespace Genocs.Identities.Application.DTO; +/// +/// The AuthDto class. +/// public class AuthDto { public Guid UserId { get; set; } public string Username { get; set; } - public string Role { get; set; } - public string AccessToken { get; set; } + public string? Role { get; set; } + public string? AccessToken { get; set; } public string RefreshToken { get; set; } public long Expires { get; set; } } \ No newline at end of file diff --git a/src/apps/identity/Genocs.Identities.Application/Domain/Entities/RefreshToken.cs b/src/apps/identity/Genocs.Identities.Application/Domain/Entities/RefreshToken.cs index 7b17070e..5f0835ba 100644 --- a/src/apps/identity/Genocs.Identities.Application/Domain/Entities/RefreshToken.cs +++ b/src/apps/identity/Genocs.Identities.Application/Domain/Entities/RefreshToken.cs @@ -10,8 +10,13 @@ public class RefreshToken : AggregateRoot public DateTime? RevokedAt { get; private set; } public bool Revoked => RevokedAt.HasValue; - public RefreshToken(AggregateId id, AggregateId userId, string token, DateTime createdAt, - DateTime? revokedAt = null) : base(id) + public RefreshToken( + AggregateId id, + AggregateId userId, + string token, + DateTime createdAt, + DateTime? revokedAt = null) + : base(id) { if (string.IsNullOrWhiteSpace(token)) { diff --git a/src/apps/identity/Genocs.Identities.Application/Domain/Exceptions/InvalidNameException.cs b/src/apps/identity/Genocs.Identities.Application/Domain/Exceptions/InvalidNameException.cs index f0f3fb66..4d64eb2e 100644 --- a/src/apps/identity/Genocs.Identities.Application/Domain/Exceptions/InvalidNameException.cs +++ b/src/apps/identity/Genocs.Identities.Application/Domain/Exceptions/InvalidNameException.cs @@ -2,7 +2,8 @@ namespace Genocs.Identities.Application.Domain.Exceptions; public class InvalidNameException : DomainException { - public InvalidNameException(string name) : base($"Invalid name: {name}.") + public InvalidNameException(string name) + : base($"Invalid name: {name}.") { } } \ No newline at end of file diff --git a/src/apps/identity/Genocs.Identities.Application/Exceptions/AppException.cs b/src/apps/identity/Genocs.Identities.Application/Exceptions/AppException.cs index cb4315e1..f9336e85 100644 --- a/src/apps/identity/Genocs.Identities.Application/Exceptions/AppException.cs +++ b/src/apps/identity/Genocs.Identities.Application/Exceptions/AppException.cs @@ -2,7 +2,8 @@ namespace Genocs.Identities.Application.Exceptions; public abstract class AppException : Exception { - protected AppException(string message) : base(message) + protected AppException(string message) + : base(message) { } } \ No newline at end of file diff --git a/src/apps/identity/Genocs.Identities.Application/Exceptions/ExceptionToResponseMapper.cs b/src/apps/identity/Genocs.Identities.Application/Exceptions/ExceptionToResponseMapper.cs index 1175fb72..e11452f4 100644 --- a/src/apps/identity/Genocs.Identities.Application/Exceptions/ExceptionToResponseMapper.cs +++ b/src/apps/identity/Genocs.Identities.Application/Exceptions/ExceptionToResponseMapper.cs @@ -13,24 +13,24 @@ public class ExceptionToResponseMapper : IExceptionToResponseMapper public ExceptionResponse Map(Exception exception) => exception switch { - DomainException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, - HttpStatusCode.BadRequest), - AppException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, - HttpStatusCode.BadRequest), - _ => new ExceptionResponse(new { code = "error", reason = "There was an error." }, - HttpStatusCode.BadRequest) + DomainException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, HttpStatusCode.BadRequest), + AppException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, HttpStatusCode.BadRequest), + _ => new ExceptionResponse(new { code = "error", reason = "There was an error." }, HttpStatusCode.BadRequest) }; - private static string GetCode(Exception exception) + private static string? GetCode(Exception exception) { var type = exception.GetType(); - if (Codes.TryGetValue(type, out var code)) + if (Codes.TryGetValue(type, out string? code)) { return code; } - var exceptionCode = exception.GetType().Name.Underscore().Replace("_exception", string.Empty); - Codes.TryAdd(type, exceptionCode); + string? exceptionCode = exception.GetType().Name.Underscore()?.Replace("_exception", string.Empty); + if (!string.IsNullOrWhiteSpace(exceptionCode)) + { + Codes.TryAdd(type, exceptionCode); + } return exceptionCode; } diff --git a/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs b/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs index 435ed3c6..70ce9a88 100644 --- a/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs +++ b/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs @@ -11,17 +11,26 @@ public static class Extensions public static IApplicationBuilder UseMongo(this IApplicationBuilder builder) { using var scope = builder.ApplicationServices.CreateScope(); - var users = scope.ServiceProvider.GetService>().Collection; + var users = scope.ServiceProvider.GetService>()?.Collection; + + if (users is null) + { + return builder; + } + var userBuilder = Builders.IndexKeys; + Task.Run(async () => await users.Indexes.CreateManyAsync( new[] { - new CreateIndexModel(userBuilder.Ascending(i => i.Email), + new CreateIndexModel( + userBuilder.Ascending(i => i.Email), new CreateIndexOptions { Unique = true }), - new CreateIndexModel(userBuilder.Ascending(i => i.Name), + new CreateIndexModel( + userBuilder.Ascending(i => i.Name), new CreateIndexOptions { Unique = true diff --git a/src/apps/identity/Genocs.Identities.Application/Services/IJwtProvider.cs b/src/apps/identity/Genocs.Identities.Application/Services/IJwtProvider.cs index b06d8093..eca33933 100644 --- a/src/apps/identity/Genocs.Identities.Application/Services/IJwtProvider.cs +++ b/src/apps/identity/Genocs.Identities.Application/Services/IJwtProvider.cs @@ -3,10 +3,15 @@ namespace Genocs.Identities.Application.Services; /// -/// JwtProvider interface definition +/// JwtProvider interface definition. /// public interface IJwtProvider { - AuthDto Create(Guid userId, string username, string role, string? audience = null, - IDictionary>? claims = null); + AuthDto Create( + Guid userId, + string username, + string role, + string? audience = null, + IDictionary>? claims = null); } \ No newline at end of file diff --git a/src/apps/identity/Genocs.Identities.Application/Services/JwtProvider.cs b/src/apps/identity/Genocs.Identities.Application/Services/JwtProvider.cs index ff76ec60..093b1a16 100644 --- a/src/apps/identity/Genocs.Identities.Application/Services/JwtProvider.cs +++ b/src/apps/identity/Genocs.Identities.Application/Services/JwtProvider.cs @@ -12,11 +12,12 @@ public JwtProvider(IJwtHandler jwtHandler) _jwtHandler = jwtHandler; } - public AuthDto Create(Guid userId, - string username, - string role, - string? audience = null, - IDictionary>? claims = null) + public AuthDto Create( + Guid userId, + string username, + string role, + string? audience = null, + IDictionary>? claims = null) { var jwt = _jwtHandler.CreateToken(userId.ToString("N"), role, audience, claims); diff --git a/src/apps/identity/Genocs.Identities.Application/Services/MessageBroker.cs b/src/apps/identity/Genocs.Identities.Application/Services/MessageBroker.cs index 653bf74f..d2ae9507 100644 --- a/src/apps/identity/Genocs.Identities.Application/Services/MessageBroker.cs +++ b/src/apps/identity/Genocs.Identities.Application/Services/MessageBroker.cs @@ -21,10 +21,15 @@ internal class MessageBroker : IMessageBroker private readonly ILogger _logger; private readonly string _spanContextHeader; - public MessageBroker(IBusPublisher busPublisher, IMessageOutbox outbox, - ICorrelationContextAccessor contextAccessor, IHttpContextAccessor httpContextAccessor, - IMessagePropertiesAccessor messagePropertiesAccessor, ICorrelationIdFactory correlationIdFactory, - RabbitMQOptions options, ILogger logger) + public MessageBroker( + IBusPublisher busPublisher, + IMessageOutbox outbox, + ICorrelationContextAccessor contextAccessor, + IHttpContextAccessor httpContextAccessor, + IMessagePropertiesAccessor messagePropertiesAccessor, + ICorrelationIdFactory correlationIdFactory, + RabbitMQOptions options, + ILogger logger) { if (options is null) { @@ -53,11 +58,12 @@ private async Task PublishAsync(IEnumerable? events) } var messageProperties = _messagePropertiesAccessor.MessageProperties; - var originatedMessageId = messageProperties?.MessageId; - var correlationId = _correlationIdFactory.Create(); - var spanContext = messageProperties?.GetSpanContext(_spanContextHeader); - var correlationContext = _contextAccessor.CorrelationContext ?? + string? originatedMessageId = messageProperties?.MessageId; + string? correlationId = _correlationIdFactory.Create(); + string? spanContext = messageProperties?.GetSpanContext(_spanContextHeader); + object correlationContext = _contextAccessor.CorrelationContext ?? _httpContextAccessor.GetCorrelationContext(); + var headers = new Dictionary(); foreach (var @event in events) @@ -67,11 +73,12 @@ private async Task PublishAsync(IEnumerable? events) continue; } - var messageId = Guid.NewGuid().ToString("N"); + string messageId = Guid.NewGuid().ToString("N"); _logger.LogTrace($"Publishing integration event: {@event.GetType().Name.Underscore()} [ID: '{messageId}']."); if (_outbox.Enabled) { - await _outbox.SendAsync(@event, + await _outbox.SendAsync( + @event, originatedMessageId, messageId, correlationId, @@ -81,12 +88,13 @@ await _outbox.SendAsync(@event, continue; } - await _busPublisher.PublishAsync(@event, - messageId, - correlationId, - spanContext, - correlationContext, - headers); + await _busPublisher.PublishAsync( + @event, + messageId, + correlationId, + spanContext, + correlationContext, + headers); } } } \ No newline at end of file diff --git a/src/apps/orders/Genocs.Orders.WebApi/Program.cs b/src/apps/orders/Genocs.Orders.WebApi/Program.cs index 9d14e35f..545d4589 100644 --- a/src/apps/orders/Genocs.Orders.WebApi/Program.cs +++ b/src/apps/orders/Genocs.Orders.WebApi/Program.cs @@ -81,8 +81,7 @@ .Get(string.Empty, ctx => ctx.Response.WriteAsync("Orders Service")) .Get("ping", ctx => ctx.Response.WriteAsync("pong")) .Get("orders/{orderId}") - .Post("orders", - afterDispatch: (cmd, ctx) => ctx.Response.Created($"orders/{cmd.OrderId}"))) + .Post("orders", afterDispatch: (cmd, ctx) => ctx.Response.Created($"orders/{cmd.OrderId}"))) .UseJaeger() .UseSwaggerDocs() .UseRabbitMq() diff --git a/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs b/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs index 4f98dbcb..f6d07ca8 100644 --- a/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs +++ b/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs @@ -15,10 +15,10 @@ public GetOrderHandler(IMongoRepository repository) } /// - /// GetOrder query handler + /// GetOrder query handler. /// - /// The query - /// The cancellation token + /// The query. + /// The cancellation token. /// public async Task HandleAsync(GetOrder query, CancellationToken cancellationToken = default) { diff --git a/src/apps/products/Genocs.Products.WebApi/Commands/CreateProduct.cs b/src/apps/products/Genocs.Products.WebApi/Commands/CreateProduct.cs index b8857be4..4f101e6c 100644 --- a/src/apps/products/Genocs.Products.WebApi/Commands/CreateProduct.cs +++ b/src/apps/products/Genocs.Products.WebApi/Commands/CreateProduct.cs @@ -8,7 +8,6 @@ public class CreateProduct : ICommand public string SKU { get; } public decimal UnitPrice { get; } - public CreateProduct(Guid productId, string sku, decimal unitPrice) { ProductId = productId == Guid.Empty ? Guid.NewGuid() : productId; diff --git a/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs b/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs index ae2474c4..ca6c727a 100644 --- a/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs +++ b/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs @@ -16,9 +16,12 @@ public class CreateProductHandler : ICommandHandler private readonly ILogger _logger; private readonly ITracer _tracer; - public CreateProductHandler(IMongoRepository repository, IBusPublisher publisher, - IMessageOutbox outbox, ITracer tracer, - ILogger logger) + public CreateProductHandler( + IMongoRepository repository, + IBusPublisher publisher, + IMessageOutbox outbox, + ITracer tracer, + ILogger logger) { _repository = repository; _publisher = publisher; @@ -29,7 +32,7 @@ public CreateProductHandler(IMongoRepository repository, IBusPubl public async Task HandleAsync(CreateProduct command, CancellationToken cancellationToken = default) { - var exists = await _repository.ExistsAsync(o => o.Id == command.ProductId); + bool exists = await _repository.ExistsAsync(o => o.Id == command.ProductId); if (exists) { throw new InvalidOperationException($"Product with given id: {command.ProductId} already exists!"); @@ -40,7 +43,7 @@ public async Task HandleAsync(CreateProduct command, CancellationToken cancellat _logger.LogInformation($"Created a product with id: {command.ProductId}, sku: {command.SKU}, unitPrice: {command.UnitPrice}."); - var spanContext = _tracer.ActiveSpan?.Context.ToString(); + string? spanContext = _tracer.ActiveSpan?.Context.ToString(); var @event = new ProductCreated(product.Id); if (_outbox.Enabled) { diff --git a/src/apps/products/Genocs.Products.WebApi/Program.cs b/src/apps/products/Genocs.Products.WebApi/Program.cs index f8f71171..ceea0f0b 100644 --- a/src/apps/products/Genocs.Products.WebApi/Program.cs +++ b/src/apps/products/Genocs.Products.WebApi/Program.cs @@ -76,12 +76,11 @@ .UseCertificateAuthentication() .UseEndpoints(r => r.MapControllers()) .UseDispatcherEndpoints(endpoints => endpoints - .Get("", ctx => ctx.Response.WriteAsync("Products Service")) + .Get(string.Empty, ctx => ctx.Response.WriteAsync("Products Service")) .Get("ping", ctx => ctx.Response.WriteAsync("pong")) .Get>("products") .Get("products/{productId}") - .Post("products", - afterDispatch: (cmd, ctx) => ctx.Response.Created($"products/{cmd.ProductId}"))) + .Post("products", afterDispatch: (cmd, ctx) => ctx.Response.Created($"products/{cmd.ProductId}"))) .UseJaeger() .UseSwaggerDocs() .UseRabbitMq(); diff --git a/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/BrowseProductsHandler.cs b/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/BrowseProductsHandler.cs index 2f410736..5ce5f85a 100644 --- a/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/BrowseProductsHandler.cs +++ b/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/BrowseProductsHandler.cs @@ -4,7 +4,6 @@ using Genocs.Products.WebApi.DTO; using MongoDB.Driver; - namespace Genocs.Products.WebApi.Queries.Handlers; public class BrowseProductsHandler : IQueryHandler> @@ -25,7 +24,6 @@ public BrowseProductsHandler(IMongoDatabase database) var pagedResult = PagedResult.From(result, result.Items.Select(x => Map(x))); return pagedResult; - } private static ProductDto Map(Product product) diff --git a/src/apps/signalr/Genocs.SignalR.WebApi/Exceptions/ExceptionToResponseMapper.cs b/src/apps/signalr/Genocs.SignalR.WebApi/Exceptions/ExceptionToResponseMapper.cs index 8ad5af5b..e8b11061 100644 --- a/src/apps/signalr/Genocs.SignalR.WebApi/Exceptions/ExceptionToResponseMapper.cs +++ b/src/apps/signalr/Genocs.SignalR.WebApi/Exceptions/ExceptionToResponseMapper.cs @@ -14,22 +14,23 @@ public ExceptionResponse Map(Exception exception) { // DomainException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, // HttpStatusCode.BadRequest), - AppException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, - HttpStatusCode.BadRequest), - _ => new ExceptionResponse(new { code = "error", reason = "There was an error." }, - HttpStatusCode.BadRequest) + AppException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, HttpStatusCode.BadRequest), + _ => new ExceptionResponse(new { code = "error", reason = "There was an error." }, HttpStatusCode.BadRequest) }; - private static string GetCode(Exception exception) + private static string? GetCode(Exception exception) { var type = exception.GetType(); - if (Codes.TryGetValue(type, out var code)) + if (Codes.TryGetValue(type, out string? code)) { return code; } - string exceptionCode = exception.GetType().Name.Underscore().Replace("_exception", string.Empty); - Codes.TryAdd(type, exceptionCode); + string? exceptionCode = exception.GetType().Name.Underscore()?.Replace("_exception", string.Empty); + if (!string.IsNullOrWhiteSpace(exceptionCode)) + { + Codes.TryAdd(type, exceptionCode); + } return exceptionCode; } diff --git a/src/apps/signalr/Genocs.SignalR.WebApi/Handlers/OperationUpdatedHandler.cs b/src/apps/signalr/Genocs.SignalR.WebApi/Handlers/OperationUpdatedHandler.cs index 34617883..f1870b46 100644 --- a/src/apps/signalr/Genocs.SignalR.WebApi/Handlers/OperationUpdatedHandler.cs +++ b/src/apps/signalr/Genocs.SignalR.WebApi/Handlers/OperationUpdatedHandler.cs @@ -21,5 +21,4 @@ public async Task HandleAsync(OperationCompleted @event, CancellationToken cance public async Task HandleAsync(OperationRejected @event, CancellationToken cancellationToken = default) => await _hubService.PublishOperationRejectedAsync(@event); - } \ No newline at end of file diff --git a/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs b/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs index 627bca5a..36481219 100644 --- a/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs +++ b/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs @@ -73,8 +73,7 @@ .UseDispatcherEndpoints(endpoints => endpoints .Get("", ctx => ctx.Response.WriteAsync("SignalR Service")) .Get("ping", ctx => ctx.Response.WriteAsync("pong")) - .Post("notifications", - afterDispatch: (cmd, ctx) => ctx.Response.Created($"notifications/{cmd.NotificationId}"))) + .Post("notifications", afterDispatch: (cmd, ctx) => ctx.Response.Created($"notifications/{cmd.NotificationId}"))) .UseJaeger() .UseSwaggerDocs() .UseRabbitMq(); diff --git a/src/apps/signalr/Genocs.SignalR.WebApi/Services/HubService.cs b/src/apps/signalr/Genocs.SignalR.WebApi/Services/HubService.cs index 257bdb90..99ae7aeb 100644 --- a/src/apps/signalr/Genocs.SignalR.WebApi/Services/HubService.cs +++ b/src/apps/signalr/Genocs.SignalR.WebApi/Services/HubService.cs @@ -10,36 +10,37 @@ public HubService(IHubWrapper hubContextWrapper) => _hubContextWrapper = hubContextWrapper ?? throw new ArgumentNullException(nameof(hubContextWrapper)); public async Task PublishOperationPendingAsync(OperationPending @event) - => await _hubContextWrapper.PublishToUserAsync(@event.UserId, - "operation_pending", - new - { - id = @event.Id, - name = @event.Name, - resource = @event.Resource - } - ); + => await _hubContextWrapper.PublishToUserAsync( + @event.UserId, + "operation_pending", + new + { + id = @event.Id, + name = @event.Name, + resource = @event.Resource + }); public async Task PublishOperationCompletedAsync(OperationCompleted @event) - => await _hubContextWrapper.PublishToUserAsync(@event.UserId, - "operation_completed", - new - { - id = @event.Id, - name = @event.Name, - resource = @event.Resource - } - ); + => await _hubContextWrapper.PublishToUserAsync( + @event.UserId, + "operation_completed", + new + { + id = @event.Id, + name = @event.Name, + resource = @event.Resource + }); public async Task PublishOperationRejectedAsync(OperationRejected @event) - => await _hubContextWrapper.PublishToUserAsync(@event.UserId, - "operation_rejected", - new - { - id = @event.Id, - name = @event.Name, - resource = @event.Resource, - code = @event.Code, - reason = @event.Message - }); + => await _hubContextWrapper.PublishToUserAsync( + @event.UserId, + "operation_rejected", + new + { + id = @event.Id, + name = @event.Name, + resource = @event.Resource, + code = @event.Code, + reason = @event.Message + }); } \ No newline at end of file