using System.Text.Json; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using GB5Shared.DateConverter; using PayRollBLL.TLeave; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.TLeave { public class GetTLeave : BaseEndpoint> { private readonly ITLeaveBLL _TLeaveBLL; public GetTLeave(ITLeaveBLL tLeaveBLL) { _TLeaveBLL = tLeaveBLL; } public override void Configure() { Get("/TLeave/GetTLeave"); AllowAnonymous(); } public record GetTLeaveParameters( [property: QueryParam] int TLeaveId, [property: FromHeader] string Login ); //protected override string? GetCacheKey(GetTLeaveParameters req, LoginDTO login) //{ // try // { // return KeyGenerator.KeyGeneration(req.TLeaveId!, EntityConstant.TLEAVE, CacheKeyLevel.USER_LEVEL, login); // } // catch (Exception) // { // throw; // } //} protected override async Task> ExecuteAsync( GetTLeaveParameters req, LoginDTO login, CancellationToken ct) { try { var tLeave = await _TLeaveBLL.GetTLeave(req.TLeaveId, login); var options = new JsonSerializerOptions { PropertyNamingPolicy = null }; options.AddGB5Converters(); string json = JsonSerializer.Serialize(tLeave, options); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( json, CacheKeyLevel.USER_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.USER_LEVEL, login, ex.Message, 500); } } } }