diff options
author | vnugent <public@vaughnnugent.com> | 2023-08-28 21:54:26 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-08-28 21:54:26 -0400 |
commit | b153adbd86e226ad805c2edbb90e4032d386a1b0 (patch) | |
tree | 9d3e5d7f2966c66e0264001cb38c67f74d6cf707 /lib/Emails.Transactional.Plugin/src/Transactions/TransactionStore.cs | |
parent | 964e81b81cdb430ecee8f67a68e3c616b3f339aa (diff) |
Refactor overhaul, data extensions & Resend.com support
Diffstat (limited to 'lib/Emails.Transactional.Plugin/src/Transactions/TransactionStore.cs')
-rw-r--r-- | lib/Emails.Transactional.Plugin/src/Transactions/TransactionStore.cs | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/lib/Emails.Transactional.Plugin/src/Transactions/TransactionStore.cs b/lib/Emails.Transactional.Plugin/src/Transactions/TransactionStore.cs index 47db7b1..4005f7b 100644 --- a/lib/Emails.Transactional.Plugin/src/Transactions/TransactionStore.cs +++ b/lib/Emails.Transactional.Plugin/src/Transactions/TransactionStore.cs @@ -2,24 +2,24 @@ * Copyright (c) 2023 Vaughn Nugent * * Library: VNLib -* Package: Transactional Emails +* Package: Emails.Transactional * File: TransactionStore.cs * -* TransactionStore.cs is part of Transactional Emails which is part of the larger +* TransactionStore.cs is part of Emails.Transactional which is part of the larger * VNLib collection of libraries and utilities. * -* Transactional Emails is free software: you can redistribute it and/or modify +* Emails.Transactional is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation, either version 2 of the License, * or (at your option) any later version. * -* Transactional Emails is distributed in the hope that it will be useful, +* Emails.Transactional is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License -* along with Transactional Emails. If not, see http://www.gnu.org/licenses/. +* along with Emails.Transactional. If not, see http://www.gnu.org/licenses/. */ using System; @@ -28,6 +28,7 @@ using System.Linq; using Microsoft.EntityFrameworkCore; using VNLib.Plugins.Extensions.Data; +using VNLib.Plugins.Extensions.Data.Abstractions; namespace Emails.Transactional.Transactions { @@ -41,34 +42,43 @@ namespace Emails.Transactional.Transactions Options = options; } - public override TransactionalDbContext NewContext() => new EmailDbCtx(Options); - - public override string RecordIdBuilder => Guid.NewGuid().ToString("N"); + ///<inheritdoc/> + public override IDbContextHandle GetNewContext() => new EmailDbCtx(Options); - protected override void OnRecordUpdate(EmailTransaction newRecord, EmailTransaction oldRecord) + ///<inheritdoc/> + public override string GetNewRecordId() => Guid.NewGuid().ToString("N"); + + ///<inheritdoc/> + public override void OnRecordUpdate(EmailTransaction newRecord, EmailTransaction oldRecord) { oldRecord.LastModified = DateTime.UtcNow; } - - protected override IQueryable<EmailTransaction> GetCollectionQueryBuilder(TransactionalDbContext context, params string[] constraints) - { - string userId = constraints[0]; - //Get the last transactions for the specifed user - EmailDbCtx ctx = context as EmailDbCtx; - return from trans in ctx.EmailTransactions - where trans.UserId == userId - orderby trans.LastModified descending - select trans; - } - protected override IQueryable<EmailTransaction> GetSingleQueryBuilder(TransactionalDbContext context, params string[] constraints) + public override IDbQueryLookup<EmailTransaction> QueryTable { get; } = new DbQueries(); + + + private sealed record class DbQueries : IDbQueryLookup<EmailTransaction> { - string transactionid = constraints[0]; - EmailDbCtx ctx = context as EmailDbCtx; - //Selet the exact transaction from its id - return from trans in ctx.EmailTransactions - where trans.Id == transactionid - select trans; + public IQueryable<EmailTransaction> GetCollectionQueryBuilder(IDbContextHandle context, params string[] constraints) + { + string userId = constraints[0]; + //Get the last transactions for the specifed user + EmailDbCtx ctx = (context as EmailDbCtx)!; + return from trans in ctx.EmailTransactions + where trans.UserId == userId + orderby trans.LastModified descending + select trans; + } + + public IQueryable<EmailTransaction> GetSingleQueryBuilder(IDbContextHandle context, params string[] constraints) + { + string transactionid = constraints[0]; + EmailDbCtx ctx = (context as EmailDbCtx)!; + //Selet the exact transaction from its id + return from trans in ctx.EmailTransactions + where trans.Id == transactionid + select trans; + } } } } |