using FastEndpoints; using FrameworkBLL.AddOnField; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.AddOnField { public class GetAddOnFieldByEntityId : BaseEndpoint { private readonly IAddOnFieldBLL _addOnFieldBLL; public GetAddOnFieldByEntityId(IAddOnFieldBLL addOnFieldBLL) { _addOnFieldBLL = addOnFieldBLL; } public override void Configure() { Get("/AddOnField/GetAddOnFieldByEntityId"); AllowAnonymous(); } public record GetAddOnFieldByEntityIdParameters( [property: QueryParam] int EntityId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetAddOnFieldByEntityIdParameters parameters, LoginDTO loginDTO) { try { return KeyGenerator.KeyGeneration(parameters.EntityId, EntityConstant.ADDONFIELD, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetAddOnFieldByEntityIdParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _addOnFieldBLL.GetAddOnFieldByEntityId(parameters.EntityId, 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); } } } }