using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MarketingBLL.Communication; using static GB5Shared.GB5Constant.Constant; namespace MarketingSL.EndPoints.Communication; /// /// Dispatch endpoint for a Communication. Email/SMS are wired for real via /// GB5Shared.ActionProcessor (see CommunicationBLL.SendCommunicationAsync's doc comment). /// WhatsApp/Social still throw NotImplementedException — no handler exists for those channels /// anywhere in this codebase yet, hence the 501 status below for that specific case. /// public class SendCommunication : BaseEndpoint> { private readonly ICommunicationBLL _CommunicationBLL; public SendCommunication(ICommunicationBLL communicationBLL) => _CommunicationBLL = communicationBLL; public override void Configure() { Post("/Communication/SendCommunication"); AllowAnonymous(); } public record SendCommunicationParameters( [property: FromHeader] string Login, [property: QueryParam] int CommunicationId ); protected override string? GetCacheKey(SendCommunicationParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync(SendCommunicationParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _CommunicationBLL.SendCommunicationAsync(req.CommunicationId, 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, 501); } } }