using System; using AccountsBLL.Instrument; using AccountsDAL.DTO.Instrument; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.Instrument { public class SaveInstrument : BaseEndpoint> { private readonly IInstrumentBLL _InstrumentBLL; public SaveInstrument(IInstrumentBLL InstrumentBLL) { _InstrumentBLL = InstrumentBLL; } public override void Configure() { Post("/Instrument/SaveInstrument"); AllowAnonymous(); } public record SaveInstrumentParameters( [property: FromHeader] string Login, [property: FromHeader] Guid AttachmentHeaderGuid, [property: FromBody] InstrumentDTO InstrumentDTO ); protected override async Task> ExecuteAsync(SaveInstrumentParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _InstrumentBLL.SaveInstrument(req.InstrumentDTO, LoginDTO!, req.AttachmentHeaderGuid); 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); } } } }