using FastEndpoints; using FMBLL.Device; using FMDAL.DTO.Device; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FMSL.EndPoints.Device { public class SaveDevice : BaseEndpoint> { private readonly IFMDeviceBLL _bll; public SaveDevice(IFMDeviceBLL bll) => _bll = bll; public override void Configure() { Post("/FM/Device/SaveDevice"); AllowAnonymous(); } public class SaveDeviceParameters { [FromHeader] public string Login { get; set; } = string.Empty; [FromBody] public DeviceSaveDTO Device { get; set; } = new(); } protected override string? GetCacheKey(SaveDeviceParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( SaveDeviceParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.SaveDevice(req.Device, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } } }