-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(infrastructure & api): Implement banking account repository and …
…fix controllers
- Loading branch information
1 parent
3a91725
commit 6dd7221
Showing
9 changed files
with
122 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
BankingSystem/Infrastructure/Configuration/BankingAccountsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using BankingSystem.Core.Entities; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace BankingSystem.Infrastructure.Configuration | ||
{ | ||
public class BankingAccountsConfiguration : IEntityTypeConfiguration<BankingAccount> | ||
{ | ||
public void Configure(EntityTypeBuilder<BankingAccount> builder) | ||
{ | ||
builder.ToTable("BankingAccounts"); | ||
|
||
builder.HasKey(ba => ba.Id); | ||
|
||
builder.Property(ba => ba.UserId) | ||
.IsRequired(); | ||
|
||
builder.Property(ba => ba.Name) | ||
.IsRequired(); | ||
|
||
builder.Property(ba => ba.CreatedAt) | ||
.IsRequired(); | ||
|
||
builder.Property(ba => ba.Version) | ||
.IsRequired(); | ||
|
||
builder.Property(ba => ba.Version) | ||
.IsConcurrencyToken(); // Optimistic concurrency to protect the model from concurrent modifications | ||
|
||
builder.HasIndex(ba => ba.Id); | ||
|
||
builder.HasIndex(ba => ba.UserId); | ||
|
||
builder.HasOne<User>() | ||
.WithMany() | ||
.HasForeignKey(ba => ba.UserId); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
BankingSystem/Infrastructure/Configuration/TransferConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using BankingSystem.Core.Entities; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore; | ||
using static BankingSystem.Core.Entities.Transfer; | ||
|
||
namespace BankingSystem.Infrastructure.Configuration | ||
{ | ||
public class TransferConfiguration : IEntityTypeConfiguration<Transfer> | ||
{ | ||
public void Configure(EntityTypeBuilder<Transfer> builder) | ||
{ | ||
builder.ToTable("Transfers"); | ||
|
||
builder.HasKey(x => x.Id); | ||
|
||
builder.Property(x => x.CorrelationTransferId); | ||
|
||
builder.Property(x => x.BankingAccountId) | ||
.IsRequired(); | ||
|
||
builder.Property(x => x.Amount) | ||
.IsRequired(); | ||
|
||
builder.Property(x => x.CreatedAt) | ||
.IsRequired(); | ||
|
||
builder.Property(x => x.Direction) | ||
.IsRequired() | ||
.HasConversion( | ||
v => v.ToString(), | ||
v => (TransferDirection)Enum.Parse(typeof(TransferDirection), v)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
BankingSystem/Infrastructure/Repositories/BankingAccountRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using BankingSystem.Core.Entities; | ||
using BankingSystem.Core.Repositories; | ||
using BankingSystem.Infrastructure.Contexts; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace BankingSystem.Infrastructure.Repositories | ||
{ | ||
public class BankingAccountRepository : IBankingAccountRepository | ||
{ | ||
private readonly BankingSystemDbContext _context; | ||
private readonly DbSet<BankingAccount> _bankingAccounts; | ||
|
||
public BankingAccountRepository(BankingSystemDbContext context) | ||
{ | ||
_context = context; | ||
_bankingAccounts = _context.BankingAccounts; | ||
} | ||
|
||
public Task<BankingAccount?> GetAsync(Guid id) | ||
=> _bankingAccounts | ||
.Include(x => x.Transfers) | ||
.SingleOrDefaultAsync(x => x.Id.Equals(id)); | ||
|
||
public async Task AddAsync(BankingAccount bankingAccount) | ||
{ | ||
await _bankingAccounts.AddAsync(bankingAccount); | ||
await _context.SaveChangesAsync(); | ||
} | ||
|
||
public async Task UpdateAsync(BankingAccount bankingAccount) | ||
{ | ||
_bankingAccounts.Update(bankingAccount); | ||
await _context.SaveChangesAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters