diff options
author | vnugent <public@vaughnnugent.com> | 2024-07-27 22:13:06 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-07-27 22:13:06 -0400 |
commit | 7cb3029c901a78e97d46644c974c3981f8f812f3 (patch) | |
tree | e10945ab0b345af0c9b15b601a337acbd363fcda /lib/Emails.Transactional.Plugin/src | |
parent | 1b59e3fe6fb8c8a4ba13bfe37d0be95256686361 (diff) |
integrate latest extensions features
Diffstat (limited to 'lib/Emails.Transactional.Plugin/src')
-rw-r--r-- | lib/Emails.Transactional.Plugin/src/Endpoints/SendEndpoint.cs | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/lib/Emails.Transactional.Plugin/src/Endpoints/SendEndpoint.cs b/lib/Emails.Transactional.Plugin/src/Endpoints/SendEndpoint.cs index 2f64dcd..358f22f 100644 --- a/lib/Emails.Transactional.Plugin/src/Endpoints/SendEndpoint.cs +++ b/lib/Emails.Transactional.Plugin/src/Endpoints/SendEndpoint.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: Emails.Transactional @@ -35,6 +35,7 @@ using VNLib.Plugins.Essentials.Oauth; using VNLib.Plugins.Extensions.Validation; using VNLib.Plugins.Extensions.Loading; using VNLib.Plugins.Extensions.Loading.Sql; +using VNLib.Plugins.Extensions.Loading.Routing; using VNLib.Plugins.Extensions.Data.Extensions; using Emails.Transactional.Mta; @@ -44,35 +45,18 @@ using Emails.Transactional.Transactions; namespace Emails.Transactional.Endpoints { + [EndpointPath("{{path}}")] [ConfigurationName("send_endpoint")] - internal class SendEndpoint : O2EndpointBase + internal class SendEndpoint(PluginBase plugin, IConfigScope config) : O2EndpointBase { public const string OAUTH2_USER_SCOPE_PERMISSION = "email:send"; private static readonly EmailTransactionValidator Validator = new(); - private readonly string FromAddress; - - private readonly TransactionStore Transactions; - private readonly IMailTransferAgent EmailService; - private readonly ITemplateStorage Templates; - - public SendEndpoint(PluginBase plugin, IConfigScope config) - { - string? path = config["path"].GetString(); - FromAddress = config.GetRequiredProperty("from_address", e => e.GetString()!); - - InitPathAndLog(path, plugin.Log); - - //Load transactions - Transactions = new(plugin.GetContextOptionsAsync()); - - //init ail transfer agent - EmailService = plugin.GetOrCreateSingleton<MailTransferAgent>(); - - //Load templates - Templates = plugin.GetOrCreateSingleton<EmailTemplateStore>(); - } + private readonly string FromAddress = config.GetRequiredProperty<string>("from_address"); + private readonly TransactionStore Transactions = new(plugin.GetContextOptionsAsync()); + private readonly MailTransferAgent EmailService = plugin.GetOrCreateSingleton<MailTransferAgent>(); + private readonly EmailTemplateStore Templates = plugin.GetOrCreateSingleton<EmailTemplateStore>(); protected override async ValueTask<VfReturnType> PostAsync(HttpEntity entity) { @@ -108,8 +92,7 @@ namespace Emails.Transactional.Endpoints if (!Validator.Validate(transaction, webm)) { //return errors - entity.CloseResponseJson(HttpStatusCode.UnprocessableEntity, webm); - return VfReturnType.VirtualSkip; + return VirtualClose(entity, webm, HttpStatusCode.UnprocessableEntity); } //Always add the template name to the model @@ -152,9 +135,7 @@ namespace Emails.Transactional.Endpoints //Store the results object webm.TransactionId = transaction.Id; - //Return the response object - entity.CloseResponse(webm); - return VfReturnType.VirtualSkip; + return VirtualOk(entity, webm); } } } |