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