diff --git a/.github/workflows/main_smartwallet.yml b/.github/workflows/main_smartwallet.yml index b189f19..07b5461 100644 --- a/.github/workflows/main_smartwallet.yml +++ b/.github/workflows/main_smartwallet.yml @@ -74,8 +74,8 @@ jobs: run: dotnet ef database update --startup-project ../SmartWallet.API env: ASPNETCORE_ENVIRONMENT: Production - JWT_SECRET: ${{ secrets.JWT_SECRET }} - DB_PATH: ${{ secrets.DB_PATH }} + Jwt__Key: ${{ secrets.JWT_SECRET }} + ConnectionStrings__DefaultConnection: ${{ secrets.AZURE_SQL_CONNECTION }} - name: Deploy to Azure Web App id: deploy-to-webapp @@ -85,4 +85,5 @@ jobs: slot-name: 'Production' package: ./publish env: - DB_PATH: ${{ secrets.DB_PATH }} + ConnectionStrings__DefaultConnection: ${{ secrets.AZURE_SQL_CONNECTION }} + Jwt__Key: ${{ secrets.JWT_SECRET }} diff --git a/src/SmartWallet.API/Program.cs b/src/SmartWallet.API/Program.cs index 4949109..fbc8b82 100644 --- a/src/SmartWallet.API/Program.cs +++ b/src/SmartWallet.API/Program.cs @@ -3,11 +3,14 @@ var builder = WebApplication.CreateBuilder(args); // --- validar configuración --- -var jwtSecret = builder.Configuration["Jwt:Key"]; -var dbPath = builder.Configuration.GetConnectionString("DefaultConnection"); +var jwtSecret = Environment.GetEnvironmentVariable("JWT_SECRET") + ?? builder.Configuration["Jwt:Key"]; -if (string.IsNullOrEmpty(jwtSecret) || string.IsNullOrEmpty(dbPath)) - throw new InvalidOperationException("Faltan variables en configuración: Jwt:Key o ConnectionStrings:DefaultConnection."); +var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); + +// --- setear variables en configuracion --- +builder.Configuration["Jwt:Key"] = jwtSecret; +builder.Configuration["ConnectionStrings:DefaultConnection"] = connectionString; // --- servicios --- builder.Services.AddControllers(); @@ -16,6 +19,13 @@ var app = builder.Build(); +// --- validar configuración --- +if (!app.Environment.IsDevelopment()) +{ + if (string.IsNullOrEmpty(jwtSecret) || string.IsNullOrEmpty(connectionString)) + throw new InvalidOperationException("Faltan variables en configuración: Jwt:Key o ConnectionStrings:DefaultConnection."); +} + // --- pipeline --- if (app.Environment.IsDevelopment()) { diff --git a/src/SmartWallet.API/appsettings.Development.json b/src/SmartWallet.API/appsettings.Development.json index 6fd1860..ba09f23 100644 --- a/src/SmartWallet.API/appsettings.Development.json +++ b/src/SmartWallet.API/appsettings.Development.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=SmartWallet;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;" + "DefaultConnection": "Server=localhost;Database=SmartWallet;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;" }, "Jwt": { "Key": "Qk1jY3h0b0p6c0ZkZ1ZyZ1p6d1d6d1p3c1Z6d1p3c1d6d1p3c1Z6d1p3c1d6d1p3c1Z6d1p3c1d6d1p3c1Z6d1p3c1d6d1p3c1Z6d1p3c1d6d1p3c1Z6d1p3c1d6d1p3c1Z6d1p3c1d6d1p3c1Z6d1p3", diff --git a/src/SmartWallet.API/appsettings.json b/src/SmartWallet.API/appsettings.json index a3c9a39..77ab19f 100644 --- a/src/SmartWallet.API/appsettings.json +++ b/src/SmartWallet.API/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "${DB_PATH}" + "DefaultConnection": "" }, "Jwt": { "Key": "${JWT_SECRET}", @@ -51,6 +51,6 @@ "DurationOfBreakInSeconds": 100 } } - + } diff --git a/src/SmartWallet.Domain/Entities/Wallet.cs b/src/SmartWallet.Domain/Entities/Wallet.cs index 42a5dd2..02e5875 100644 --- a/src/SmartWallet.Domain/Entities/Wallet.cs +++ b/src/SmartWallet.Domain/Entities/Wallet.cs @@ -32,9 +32,9 @@ public class Wallet // Navegaciones inversas - public ICollection SourceLedgers { get; private set; } = new List(); - public ICollection DestinationLedgers { get; private set; } = new List(); - public ICollection ReceivedTransfers { get; private set; } = new List(); + public ICollection Transactions { get; private set; } = new List(); // origen + public ICollection ReceivedTransfers { get; private set; } = new List(); // destino + public ICollection TransactionLedgers { get; private set; } = new List(); // asientos // --- constructores --- diff --git a/src/SmartWallet.Infrastructure/SmartWalletDbContext.cs b/src/SmartWallet.Infrastructure/SmartWalletDbContext.cs index 921cb9f..abcbbc9 100644 --- a/src/SmartWallet.Infrastructure/SmartWalletDbContext.cs +++ b/src/SmartWallet.Infrastructure/SmartWalletDbContext.cs @@ -21,41 +21,59 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - // --- transaction --- + // --- Transaction --- modelBuilder.Entity(entity => { entity.HasKey(t => t.Id); entity.Property(t => t.Amount) - .HasColumnType("decimal(18,2)"); + .HasColumnType("decimal(18,2)") + .IsRequired(); + entity.Property(t => t.CurrencyCode).IsRequired(); + entity.Property(t => t.Type).IsRequired(); + entity.Property(t => t.Status).IsRequired(); + entity.Property(t => t.CreatedAt).IsRequired(); + + // relación con Wallet origen entity.HasOne(t => t.Wallet) - .WithMany() + .WithMany(w => w.Transactions) .HasForeignKey(t => t.WalletId) .OnDelete(DeleteBehavior.Restrict); + // relación con Wallet destino entity.HasOne(t => t.DestinationWallet) .WithMany(w => w.ReceivedTransfers) .HasForeignKey(t => t.DestinationWalletId) .OnDelete(DeleteBehavior.Restrict); }); - // --- transactionLedger --- + // --- TransactionLedger --- modelBuilder.Entity(entity => { entity.HasKey(l => l.Id); entity.Property(l => l.Amount) - .HasColumnType("decimal(18,2)"); + .HasColumnType("decimal(18,2)") + .IsRequired(); + + entity.Property(l => l.CurrencyCode).IsRequired(); + entity.Property(l => l.Type).IsRequired(); + entity.Property(l => l.Status).IsRequired(); + entity.Property(l => l.Timestamp).IsRequired(); + // relación con Wallet entity.HasOne(l => l.Wallet) - .WithMany() - .HasForeignKey(l => l.WalletId) + .WithMany(w => w.TransactionLedgers) .HasForeignKey(l => l.WalletId) .OnDelete(DeleteBehavior.Restrict); }); - modelBuilder.Seed(); // Llamada al método de extensión para sembrar datos + // --- seed inicial --- + modelBuilder.Seed(); } + + + } }