using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MarketingBLL.EmotionalDriver; using MarketingDAL.DTO.EmotionalDriver; using static GB5Shared.GB5Constant.Constant; namespace MarketingSL.EndPoints.EmotionalDriver; public class SaveEmotionalDriver : BaseEndpoint> { private readonly IEmotionalDriverBLL _EmotionalDriverBLL; public SaveEmotionalDriver(IEmotionalDriverBLL emotionalDriverBLL) => _EmotionalDriverBLL = emotionalDriverBLL; public override void Configure() { Post("/EmotionalDriver/SaveEmotionalDriver"); AllowAnonymous(); } public record SaveEmotionalDriverParameters( [property: FromHeader] string Login, [property: FromBody] EmotionalDriverDTO EmotionalDriverDTO ); protected override string? GetCacheKey(SaveEmotionalDriverParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync(SaveEmotionalDriverParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _EmotionalDriverBLL.SaveEmotionalDriver(req.EmotionalDriverDTO, 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); } } }