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