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.BetaClient; // Client-facing "which beta programs is MY client enrolled in" — GetBetaClientList.cs lists every // client's enrolments (admin-only browse) and has no ClientId parameter to scope by, so this calls // the new IBetaClientBLL.GetListByClientAsync instead. GetOpenPrograms.cs needs no equivalent // change — it's already AllowAnonymous() global reference data (which programs exist), not // per-client enrolment data. public class GetMyEnrollments : BaseEndpoint> { private const string ClientJwtSchemeName = "ClientJwtBearer"; private readonly IBetaClientBLL _BetaClientBLL; public GetMyEnrollments(IBetaClientBLL betaClientBLL) => _BetaClientBLL = betaClientBLL; public override void Configure() { Get("/BetaClient/GetMyEnrollments"); 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.OBJECTENTITLEMENTBETACLIENT, 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 _BetaClientBLL.GetListByClientAsync(caller.ClientId, loginDTO, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponseEnumerable(result, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } }