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