- Updated `ISQLExecutor<TEntity>` to inherit from new `ISQLExecutor` interface for improved SQL execution flexibility. - Added package references for `Dapper` and `DigitalData.Core` in project files. - Modified `CreateEnvelopeCommand` to include `[BindNever]` on `UserId` for better model binding control. - Refactored `CreateEnvelopeCommandHandler` to use `DynamicParameters` for SQL parameter handling. - Updated `CreateEnvelopeSQL` to select only the top record for performance. - Introduced `GetIdOrDefault` method in `ControllerExtensions` for user ID retrieval with fallback. - Added `CreateAsync` method in `EnvelopeController` for envelope creation using `IMediator`. - Ensured infrastructure project has necessary package references. - Refactored `SQLExecutor` to implement new interface and simplified constructor. - Introduced `SQLExecutorBaseEntity` for entity-specific SQL command execution.
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
|
|
namespace EnvelopeGenerator.GeneratorAPI.Controllers
|
|
{
|
|
public static class ControllerExtensions
|
|
{
|
|
public static int? GetIdOrDefault(this ClaimsPrincipal user)
|
|
=> int.TryParse(user.FindFirstValue(ClaimTypes.NameIdentifier) ?? user.FindFirstValue("sub"), out int result)
|
|
? result : null;
|
|
|
|
public static int GetId(this ClaimsPrincipal user)
|
|
=> user.GetIdOrDefault()
|
|
?? throw new InvalidOperationException("User ID claim is missing or invalid. This may indicate a misconfigured or forged JWT token.");
|
|
|
|
public static string? GetUsername(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.Name)?.Value;
|
|
|
|
public static string? GetName(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.Surname)?.Value;
|
|
|
|
public static string? GetPrename(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.GivenName)?.Value;
|
|
|
|
public static string? GetEmail(this ClaimsPrincipal user)
|
|
=> user.FindFirst(ClaimTypes.Email)?.Value;
|
|
}
|
|
} |