Skip to content

Commit

Permalink
Merge pull request #177 from Brixel/bank-account-totals
Browse files Browse the repository at this point in the history
feat: Added materialized view to hold bank account totals, and show them on bacnk accounts page
  • Loading branch information
BerendWouters authored Jun 22, 2023
2 parents 70e0cb4 + f5f6dac commit ace1499
Show file tree
Hide file tree
Showing 20 changed files with 469 additions and 96 deletions.
4 changes: 1 addition & 3 deletions Commands/Handlers/Member/AddMember/AddMemberHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ namespace Commands.Handlers.Member.AddMember;
public class AddMemberHandler : IRequestHandler<AddMemberCommand, Guid>
{
private readonly IMemberRepository _memberRepository;
private readonly IMapper _mapper;
private readonly IUserAccessor _userAccessor;
private readonly HaSpManContext _dbContext;

public AddMemberHandler(IMemberRepository memberRepository, IMapper mapper, IUserAccessor userAccessor, HaSpManContext dbContext)
public AddMemberHandler(IMemberRepository memberRepository, IUserAccessor userAccessor, HaSpManContext dbContext)
{
_memberRepository = memberRepository;
_mapper = mapper;
_userAccessor = userAccessor;
_dbContext = dbContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ namespace Commands.Handlers.Transaction.EditTransaction;
public class EditTransactionHandler : IRequestHandler<EditTransactionCommand, Guid>
{
private readonly ITransactionRepository _transactionRepository;
private readonly IMapper _mapper;
private readonly IMediator _mediator;

public EditTransactionHandler(ITransactionRepository transactionRepository, IMapper mapper, IMediator mediator)
public EditTransactionHandler(ITransactionRepository transactionRepository, IMediator mediator)
{
_transactionRepository = transactionRepository;
_mapper = mapper;
_mediator = mediator;
}

Expand Down
6 changes: 6 additions & 0 deletions Persistence/Constants/Schema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Persistence.Constants;

public static class Schema
{
public const string HaSpMan = "HaSpMan";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using Persistence.Views;

namespace Persistence.EntityConfigurations;

public class BankAccountsWithTotalsConfiguration : IEntityTypeConfiguration<BankAccountsWithTotals>
{
public void Configure(EntityTypeBuilder<BankAccountsWithTotals> builder)
{
builder
.ToView(BankAccountsWithTotals.ViewName)
.HasKey(v => v.BankAccountId);

builder.HasOne(p => p.Account).WithOne();
}
}
6 changes: 3 additions & 3 deletions Persistence/EntityConfigurations/TransactionConfigurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static Action<OwnedNavigationBuilder<CreditTransaction, TransactionTypeA
};
}

private Action<OwnedNavigationBuilder<CreditTransaction, TransactionAttachment>> AttachmentConfiguration(string tableName)
private static Action<OwnedNavigationBuilder<CreditTransaction, TransactionAttachment>> AttachmentConfiguration(string tableName)
{
return cfg =>
{
Expand Down Expand Up @@ -78,7 +78,7 @@ public void Configure(EntityTypeBuilder<DebitTransaction> builder)

}

private Action<OwnedNavigationBuilder<DebitTransaction, TransactionTypeAmount>> TransactionTypeAmountConfiguration(string tableName)
private static Action<OwnedNavigationBuilder<DebitTransaction, TransactionTypeAmount>> TransactionTypeAmountConfiguration(string tableName)
{
return cfg =>
{
Expand All @@ -88,7 +88,7 @@ private Action<OwnedNavigationBuilder<DebitTransaction, TransactionTypeAmount>>
};
}

private Action<OwnedNavigationBuilder<DebitTransaction, TransactionAttachment>> AttachmentConfiguration(string tableName)
private static Action<OwnedNavigationBuilder<DebitTransaction, TransactionAttachment>> AttachmentConfiguration(string tableName)
{
return cfg =>
{
Expand Down
7 changes: 1 addition & 6 deletions Persistence/Extensions/DbContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ public static void MigrateHaSpManContext(string connectionString)
throw new ArgumentException("The value cannot be empty or whitespace.", nameof(connectionString));
}
var optionsBuilder = new DbContextOptionsBuilder<HaSpManContext>()
.UseSqlServer(connectionString, b =>
{
b.MigrationsAssembly("Persistence")
.MigrationsHistoryTable("__EFMigrationsHistory", "HaSpMan");
b.EnableRetryOnFailure();
});
.UseSqlServer(connectionString);

var context = new HaSpManContext(optionsBuilder.Options);
context.Database.Migrate();
Expand Down
17 changes: 12 additions & 5 deletions Persistence/HaSpManContext.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
using Domain;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

using Types;
using Persistence.Constants;
using Persistence.Views;

namespace Persistence;

public class HaSpManContext : DbContext
{
public HaSpManContext()
{
}

public HaSpManContext(DbContextOptions<HaSpManContext> options)
: base(options)
{
}

public DbSet<Member> Members { get; set; } = null!;
public DbSet<BankAccount> BankAccounts { get; set; } = null!;
public DbSet<BankAccountsWithTotals> BankAccountsWithTotals { get; set; } = null!;
public DbSet<Transaction> Transactions { get; set; } = null!;


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(x => x.MigrationsHistoryTable("__EFMigrationsHistory", Schema.HaSpMan));

protected override void OnModelCreating(ModelBuilder builder)
{
builder.HasDefaultSchema("HaSpMan");
builder.HasDefaultSchema(Schema.HaSpMan);
builder.ApplyConfigurationsFromAssembly(
typeof(Persistence.EntityConfigurations.MemberConfiguration).Assembly
typeof(EntityConfigurations.MemberConfiguration).Assembly

);
base.OnModelCreating(builder);
Expand Down
Loading

0 comments on commit ace1499

Please sign in to comment.