using FastEndpoints; using FrameworkBLL.DocumentMap; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static FrameworkSL.Endpoints.DocumentMap.GetDocumentMap; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.DocumentMap { public class GetDocumentMap : BaseEndpoint { private readonly IDocumentMapBLL _documentMapBLL; public GetDocumentMap(IDocumentMapBLL documentMapBLL) { _documentMapBLL = documentMapBLL; } public override void Configure() { Get("/DocumentMap/GetDocumentMap"); AllowAnonymous(); } public record GetDocumentMapParameters( [property: QueryParam] int EntityId, [property: QueryParam] int BizTransactionClassId, [property: QueryParam] int BizTransactionId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetDocumentMapParameters parameters, LoginDTO loginDTO) { try { var key = $"{parameters.EntityId}_{parameters.BizTransactionClassId}_{parameters.BizTransactionId}"; return KeyGenerator.KeyGeneration(key, EntityConstant.DOCUMENTMAP, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetDocumentMapParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _documentMapBLL.GetDocumentMap( parameters.EntityId, parameters.BizTransactionClassId, parameters.BizTransactionId, loginDTO); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.USER_LEVEL, loginDTO,ex.Message, 500 ); } } } }