Files
myAi/Apis/email-api-data/EmailApiDbContext.cs
T
claude 19e73aca17 feat: add email-api-data project with EmailTemplates repository and service
New data project owning the emailApi schema:
- EmailTemplateEntity with Key, Language, Value, Description, UpdatedAt, OperatorCopy
- EmailApiDbContext (schema: emailApi, custom migration table _EmailApiMigrations)
- IEmailTemplateRepository / EfEmailTemplateRepository (scoped)
- IEmailTemplateService / EmailTemplateService (singleton, 10-min cache)
  - GetOperatorCopy falls back to first non-empty OperatorCopy across all rows
- Initial migration CreateEmailTemplates: creates table + seeds all email.*
  templates (match + search-results in en/ro) and html-shell fragments
  with OperatorCopy = "contact@myai.ro" for addressable rows

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-28 08:39:15 +03:00

32 lines
1.2 KiB
C#

using EmailApi.Data.Entities;
using Microsoft.EntityFrameworkCore;
namespace EmailApi.Data;
public sealed class EmailApiDbContext : DbContext
{
public const string SchemaName = "emailApi";
public const string MigrationTableName = "_EmailApiMigrations";
public EmailApiDbContext(DbContextOptions<EmailApiDbContext> options) : base(options) { }
public DbSet<EmailTemplateEntity> EmailTemplates => Set<EmailTemplateEntity>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema(SchemaName);
modelBuilder.Entity<EmailTemplateEntity>(entity =>
{
entity.ToTable("EmailTemplates");
entity.HasKey(x => new { x.Key, x.Language });
entity.Property(x => x.Key).HasMaxLength(128);
entity.Property(x => x.Language).HasMaxLength(8);
entity.Property(x => x.Value).IsRequired();
entity.Property(x => x.Description).HasMaxLength(500).HasDefaultValue(string.Empty);
entity.Property(x => x.UpdatedAt).HasDefaultValueSql("SYSUTCDATETIME()");
entity.Property(x => x.OperatorCopy).HasMaxLength(256).HasDefaultValue(string.Empty);
});
}
}