using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Village; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Village { public class GetVillage : BaseEndpoint> { private readonly IVillageBLL _VillageBLL; public GetVillage(IVillageBLL villageBLL) { _VillageBLL = villageBLL; } public override void Configure() { Get("/Village/GetVillage"); AllowAnonymous(); } public record GetVillageParameters( [property: FromHeader] string Login, [property: QueryParam] int VillageId ); protected override string? GetCacheKey(GetVillageParameters req, LoginDTO loginDTO) { try { return KeyGenerator.KeyGeneration(req.VillageId, EntityConstant.OBJECTVILLAGE, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync( GetVillageParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _VillageBLL.GetVillage(req.VillageId, 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); } } } }