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