using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Job; using PayRollDAL.DTO.Job; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Job { public class SaveJob : BaseEndpoint> { private readonly IJobBLL _JobBLL; public SaveJob(IJobBLL jobBLL) { _JobBLL = jobBLL; } public override void Configure() { Post("/Job/SaveJob"); AllowAnonymous(); } public record SaveJobParameters( [property: FromHeader] string Login, [property: FromBody] JobDTO JobDTO ); protected override string? GetCacheKey(SaveJobParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( SaveJobParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _JobBLL.SaveJob(req.JobDTO, loginDTO); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }