using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.User; using GB5Shared.DTO.Framework.User; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.User { public class SaveUser : BaseEndpoint { private readonly IUserBLL _userBLL; public SaveUser(IUserBLL userBLL) { _userBLL = userBLL; } public override void Configure() { Post("/User/SaveUser"); AllowAnonymous(); } public record SaveUserParameters( [property: FromBody] UserDTO UserDTO, [property: FromHeader(HeaderName = "Login")] string Login ); protected override async Task> ExecuteAsync(SaveUserParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { string result = await _userBLL.Save(parameters.UserDTO, 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 ); } } } }