using EntitlementBLL.Auth; using EntitlementBLL.Interfaces; using EntitlementSL.Common; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using ErrorResponse = GB5Shared.Resource.Response.ErrorResponse; using static GB5Shared.GB5Constant.Constant; namespace EntitlementSL.Endpoints.Subscription; // Client-facing equivalent of GetSubscription — takes no ClientId parameter at all (unlike the // admin endpoint), scoped structurally to the caller's OWN ClientId from verified JWT claims so // there is nothing for a client to spoof. Any authenticated client user (admin or user tier) may // view their own subscription — this is a read of their own data, not a commercial action, so no // additional capability is required (mirrors ChangeRequest/GetMyRequests.cs's gating). public class GetMySubscription : BaseEndpoint> { private const string ClientJwtSchemeName = "ClientJwtBearer"; private readonly ISubscriptionService _SubscriptionService; public GetMySubscription(ISubscriptionService subscriptionService) => _SubscriptionService = subscriptionService; public override void Configure() { Get("/lic/Subscription.svc/GetMySubscription"); AuthSchemes(ClientJwtSchemeName); Roles(ClientRoleCodes.ClientAdmin, ClientRoleCodes.ClientUser); } public record Params([property: FromHeader] string Login); protected override string? GetCacheKey(Params req, LoginDTO loginDTO) { var caller = ClientCallerContext.FromClaims(HttpContext.User.Claims); return KeyGenerator.KeyGeneration(caller.ClientId, EntityConstant.OBJECTENTITLEMENTSUBSCRIPTION, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } protected override async Task> ExecuteAsync(Params req, LoginDTO loginDTO, CancellationToken ct) { var caller = ClientCallerContext.FromClaims(HttpContext.User.Claims); if (caller.ClientId <= 0) return await GB5Shared.ResponseStandard.Response.CreateErrorResponse( ErrorResponse.AccessDeniedMessage, CacheKeyLevel.NOT_REQUIRED, loginDTO, statusCode: 403); var result = await _SubscriptionService.GetAsync(caller.ClientId, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } }