diff --git a/PostFundManagement.Api/Endpoints/Communications/GetInvitesEndpoint.cs b/PostFundManagement.Api/Endpoints/Communications/GetInvitesEndpoint.cs index 48dc0ef..851e83d 100644 --- a/PostFundManagement.Api/Endpoints/Communications/GetInvitesEndpoint.cs +++ b/PostFundManagement.Api/Endpoints/Communications/GetInvitesEndpoint.cs @@ -5,7 +5,7 @@ using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Api; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Models; -using static PostFundManagement.Domain.Extensions.General; +using static PostFundManagement.Application.Extensions.General; namespace PostFundManagement.Api.Endpoints.Communications; diff --git a/PostFundManagement.Api/Program.cs b/PostFundManagement.Api/Program.cs index bd90260..92f6836 100644 --- a/PostFundManagement.Api/Program.cs +++ b/PostFundManagement.Api/Program.cs @@ -1,4 +1,3 @@ -using PostFundManagement.Api.Extensions; using PostFundManagement.Application.Api.Filters; using PostFundManagement.Application.Extensions; using PostFundManagement.Domain.Extensions; diff --git a/PostFundManagement.Application/Api/Filters/ActiveUserFilter.cs b/PostFundManagement.Application/Api/Filters/ActiveUserFilter.cs index 6d8e45b..060a208 100644 --- a/PostFundManagement.Application/Api/Filters/ActiveUserFilter.cs +++ b/PostFundManagement.Application/Api/Filters/ActiveUserFilter.cs @@ -1,5 +1,5 @@ using PostFundManagement.Application.Shared; -using static PostFundManagement.Domain.Extensions.General; +using static PostFundManagement.Application.Extensions.General; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Application.Api.Filters; diff --git a/PostFundManagement.Application/Communications/Events/SyncUserEvent.cs b/PostFundManagement.Application/Communications/Events/SyncUserEvent.cs index 45a7f63..b5e83c4 100644 --- a/PostFundManagement.Application/Communications/Events/SyncUserEvent.cs +++ b/PostFundManagement.Application/Communications/Events/SyncUserEvent.cs @@ -7,3 +7,13 @@ public class SyncUserEvent : EventBase, IEvent { public string Name { get; set; } = nameof(SyncUserEvent); } + +public class SyncUserEventHandler(ILogger logger) : INotificationHandler +{ + public ValueTask Handle(SyncUserEvent notification, CancellationToken cancellationToken) + { + logger.LogInformation("Integration Sync executed. Correlation ID: {CorrelationId}", notification.CorrelationId); + + return ValueTask.CompletedTask; + } +} diff --git a/PostFundManagement.Application/Communications/Events/SyncUserEventHandler.cs b/PostFundManagement.Application/Communications/Events/SyncUserEventHandler.cs deleted file mode 100644 index 2290442..0000000 --- a/PostFundManagement.Application/Communications/Events/SyncUserEventHandler.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace PostFundManagement.Application.Communications.Events; - -public class SyncUserEventHandler(ILogger logger) : INotificationHandler -{ - public ValueTask Handle(SyncUserEvent notification, CancellationToken cancellationToken) - { - logger.LogInformation("Integration Sync executed. Correlation ID: {CorrelationId}", notification.CorrelationId); - - return ValueTask.CompletedTask; - } -} diff --git a/PostFundManagement.Application/Extensions/General.cs b/PostFundManagement.Application/Extensions/General.cs index c5bab52..a9969f4 100644 --- a/PostFundManagement.Application/Extensions/General.cs +++ b/PostFundManagement.Application/Extensions/General.cs @@ -16,4 +16,33 @@ public static class General return services; } + + public static Guid GetUserId(this HttpContext context) => (Guid)context.Items[Domain.Extensions.Constants.UserIdItemKey]!; + + public static string GetUserEmail(this HttpContext context) => (string)context.Items[Domain.Extensions.Constants.EmaiItemKey]!; + + public static (bool Decoded, Guid userId) GetUserId(this ClaimsPrincipal principal) + { + var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value; + + var decoded = Guid.TryParse(sidClaim, out var userId); + + return (decoded, userId); + } + + public static (bool Decoded, Guid email) GetUserEmail(this ClaimsPrincipal principal) + { + var emailClaim = principal.FindFirst("email")?.Value ?? principal.FindFirst(ClaimTypes.Email)?.Value; + + var decoded = Guid.TryParse(emailClaim, out var email); + + return (decoded, email); + } + + public static Microsoft.AspNetCore.Mvc.ProblemDetails ToProblems(this IReadOnlyList errors) => new() + { + Detail = string.Join(',', errors.Select(e => e.Message)), + Status = StatusCodes.Status400BadRequest, + Title = errors[0]?.Message, + }; } diff --git a/PostFundManagement.Domain/Extensions/Otel.cs b/PostFundManagement.Application/Extensions/Otel.cs similarity index 90% rename from PostFundManagement.Domain/Extensions/Otel.cs rename to PostFundManagement.Application/Extensions/Otel.cs index 41c0fb3..343d8a5 100644 --- a/PostFundManagement.Domain/Extensions/Otel.cs +++ b/PostFundManagement.Application/Extensions/Otel.cs @@ -1,4 +1,10 @@ -namespace PostFundManagement.Domain.Extensions; +using OpenTelemetry.Exporter; +using OpenTelemetry.Logs; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; +using OpenTelemetry.Metrics; + +namespace PostFundManagement.Application.Extensions; public static class Otel { diff --git a/PostFundManagement.Api/Extensions/Postgres.cs b/PostFundManagement.Application/Extensions/Postgres.cs similarity index 95% rename from PostFundManagement.Api/Extensions/Postgres.cs rename to PostFundManagement.Application/Extensions/Postgres.cs index 351b55f..ef640a8 100644 --- a/PostFundManagement.Api/Extensions/Postgres.cs +++ b/PostFundManagement.Application/Extensions/Postgres.cs @@ -1,7 +1,7 @@ using PostFundManagement.Infrastructure.Database; using static PostFundManagement.Domain.Extensions.Constants; -namespace PostFundManagement.Api.Extensions; +namespace PostFundManagement.Application.Extensions; public static class Postgres { diff --git a/PostFundManagement.Domain/Extensions/Quartz.cs b/PostFundManagement.Application/Extensions/Quartz.cs similarity index 100% rename from PostFundManagement.Domain/Extensions/Quartz.cs rename to PostFundManagement.Application/Extensions/Quartz.cs diff --git a/PostFundManagement.Api/Extensions/Security.cs b/PostFundManagement.Application/Extensions/Security.cs similarity index 98% rename from PostFundManagement.Api/Extensions/Security.cs rename to PostFundManagement.Application/Extensions/Security.cs index 5e13cb5..736aa40 100644 --- a/PostFundManagement.Api/Extensions/Security.cs +++ b/PostFundManagement.Application/Extensions/Security.cs @@ -1,10 +1,9 @@ -using PostFundManagement.Application.Extensions; using PostFundManagement.Application.Shared; using PostFundManagement.Domain.Api.Configuration; using PostFundManagement.Domain.Sdk; using PostFundManagement.Infrastructure.Database; -namespace PostFundManagement.Api.Extensions; +namespace PostFundManagement.Application.Extensions; public static class Security { diff --git a/PostFundManagement.Infrastructure/Configuration/MachineIdentity.cs b/PostFundManagement.Domain/Api/Configuration/MachineIdentity.cs similarity index 78% rename from PostFundManagement.Infrastructure/Configuration/MachineIdentity.cs rename to PostFundManagement.Domain/Api/Configuration/MachineIdentity.cs index 2434107..6811135 100644 --- a/PostFundManagement.Infrastructure/Configuration/MachineIdentity.cs +++ b/PostFundManagement.Domain/Api/Configuration/MachineIdentity.cs @@ -1,4 +1,4 @@ -namespace PostFundManagement.Infrastructure.Configuration; +namespace PostFundManagement.Domain.Api.Configuration; public sealed class MachineIdentity { diff --git a/PostFundManagement.Domain/Extensions/General.cs b/PostFundManagement.Domain/Extensions/General.cs deleted file mode 100644 index 542f6fe..0000000 --- a/PostFundManagement.Domain/Extensions/General.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace PostFundManagement.Domain.Extensions; - -public static class General -{ - public static Guid GetUserId(this HttpContext context) => (Guid)context.Items[Constants.UserIdItemKey]!; - - public static string GetUserEmail(this HttpContext context) => (string)context.Items[Constants.EmaiItemKey]!; - - public static (bool Decoded, Guid userId) GetUserId(this ClaimsPrincipal principal) - { - var sidClaim = principal.FindFirst("sid")?.Value ?? principal.FindFirst(ClaimTypes.Sid)?.Value; - - var decoded = Guid.TryParse(sidClaim, out var userId); - - return (decoded, userId); - } - - public static (bool Decoded, Guid email) GetUserEmail(this ClaimsPrincipal principal) - { - var emailClaim = principal.FindFirst("email")?.Value ?? principal.FindFirst(ClaimTypes.Email)?.Value; - - var decoded = Guid.TryParse(emailClaim, out var email); - - return (decoded, email); - } - - public static Microsoft.AspNetCore.Mvc.ProblemDetails ToProblems(this IReadOnlyList errors) => new() - { - Detail = string.Join(',', errors.Select(e => e.Message)), - Status = StatusCodes.Status400BadRequest, - Title = errors[0]?.Message, - }; -}