Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/main_smartwallet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
18 changes: 14 additions & 4 deletions src/SmartWallet.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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())
{
Expand Down
2 changes: 1 addition & 1 deletion src/SmartWallet.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/SmartWallet.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "${DB_PATH}"
"DefaultConnection": ""
},
"Jwt": {
"Key": "${JWT_SECRET}",
Expand Down Expand Up @@ -51,6 +51,6 @@
"DurationOfBreakInSeconds": 100
}
}


}
6 changes: 3 additions & 3 deletions src/SmartWallet.Domain/Entities/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class Wallet


// Navegaciones inversas
public ICollection<TransactionLedger> SourceLedgers { get; private set; } = new List<TransactionLedger>();
public ICollection<TransactionLedger> DestinationLedgers { get; private set; } = new List<TransactionLedger>();
public ICollection<Transaction> ReceivedTransfers { get; private set; } = new List<Transaction>();
public ICollection<Transaction> Transactions { get; private set; } = new List<Transaction>(); // origen
public ICollection<Transaction> ReceivedTransfers { get; private set; } = new List<Transaction>(); // destino
public ICollection<TransactionLedger> TransactionLedgers { get; private set; } = new List<TransactionLedger>(); // asientos


// --- constructores ---
Expand Down
34 changes: 26 additions & 8 deletions src/SmartWallet.Infrastructure/SmartWalletDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,59 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

// --- transaction ---
// --- Transaction ---
modelBuilder.Entity<Transaction>(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<TransactionLedger>(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();
}



}
}
Loading