Skip to content

Commit

Permalink
Merge pull request #493 from DFE-Digital/feature/160874-dao-revoked
Browse files Browse the repository at this point in the history
Feature/160874 dao revoked
  • Loading branch information
dneed-nimble authored Jun 4, 2024
2 parents cf33922 + 73abbd3 commit 012b565
Show file tree
Hide file tree
Showing 31 changed files with 4,563 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using Dfe.Academies.Academisation.Data.Repositories;
using Dfe.Academies.Academisation.Data.UnitTest.Contexts;
using Dfe.Academies.Academisation.Domain.Core.ConversionAdvisoryBoardDecisionAggregate;
using Dfe.Academies.Academisation.IDomain.ConversionAdvisoryBoardDecisionAggregate;
using Microsoft.EntityFrameworkCore;
using Moq;
using Xunit;

namespace Dfe.Academies.Academisation.Data.UnitTest.ConversionAdvisoryBoardDecisionAggregate;
Expand Down Expand Up @@ -44,7 +42,7 @@ public async Task WhenRecordAlreadyExists___UpdatesExistingRecord()

await _context.ConversionAdvisoryBoardDecisions.LoadAsync();

existingDecision.Update(details, existingDecision.DeferredReasons, existingDecision.DeclinedReasons, existingDecision.WithdrawnReasons);
existingDecision.Update(details, existingDecision.DeferredReasons, existingDecision.DeclinedReasons, existingDecision.WithdrawnReasons, existingDecision.DaoRevokedReasons);

//Act
_repo.Update(existingDecision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@ protected override void SeedData()
var seed = new List<ConversionAdvisoryBoardDecision>
{
new ConversionAdvisoryBoardDecision(1, _fixture.Build<AdvisoryBoardDecisionDetails>()
.With(d => d.ConversionProjectId, 1).Create(),
Enumerable.Empty<AdvisoryBoardDeferredReasonDetails>(),
.With(d => d.ConversionProjectId, 1).Create(),
Enumerable.Empty<AdvisoryBoardDeferredReasonDetails>(),
Enumerable.Empty<AdvisoryBoardDeclinedReasonDetails>(),
Enumerable.Empty<AdvisoryBoardWithdrawnReasonDetails>(),
Enumerable.Empty<AdvisoryBoardDAORevokedReasonDetails>(),
timestamp,timestamp),
new ConversionAdvisoryBoardDecision(2,_fixture.Build<AdvisoryBoardDecisionDetails>()
.With(d => d.ConversionProjectId, 2).Create(),
Enumerable.Empty<AdvisoryBoardDeferredReasonDetails>(),
Enumerable.Empty<AdvisoryBoardDeclinedReasonDetails>(),
Enumerable.Empty<AdvisoryBoardWithdrawnReasonDetails>(),
Enumerable.Empty<AdvisoryBoardDAORevokedReasonDetails>(),
timestamp, timestamp),
new ConversionAdvisoryBoardDecision(3,_fixture.Build<AdvisoryBoardDecisionDetails>()
.With(d => d.ConversionProjectId, 3).Create(),
Enumerable.Empty<AdvisoryBoardDeferredReasonDetails>(),
Enumerable.Empty<AdvisoryBoardDeclinedReasonDetails>(),
Enumerable.Empty<AdvisoryBoardWithdrawnReasonDetails>(),
Enumerable.Empty<AdvisoryBoardDAORevokedReasonDetails>(),
timestamp, timestamp)
};

Expand Down
40 changes: 33 additions & 7 deletions Dfe.Academies.Academisation.Data/AcademisationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public AcademisationContext(DbContextOptions<AcademisationContext> options) : ba

public DbSet<Application> Applications { get; set; } = null!;
public DbSet<Contributor> Contributors { get; set; } = null!;
public DbSet<School> Schools { get; set; } = null!;
public DbSet<Loan> SchoolLoans { get; set; } = null!;
public DbSet<School> Schools { get; set; } = null!;
public DbSet<Loan> SchoolLoans { get; set; } = null!;
public DbSet<Lease> SchoolLeases { get; set; } = null!;

public DbSet<JoinTrust> JoinTrusts { get; set; } = null!;
public DbSet<FormTrust> FormTrusts { get; set; } = null!;
public DbSet<JoinTrust> JoinTrusts { get; set; } = null!;
public DbSet<FormTrust> FormTrusts { get; set; } = null!;

public DbSet<Project> Projects { get; set; } = null!;
public DbSet<ProjectNote> ProjectNotes { get; set; } = null!;
Expand Down Expand Up @@ -70,6 +70,7 @@ private void SetModifiedAndCreatedDates()
var advisoryBoardDeferredReasonDetailsEntities = ChangeTracker.Entries<AdvisoryBoardDeferredReasonDetails>().ToList();
var advisoryBoardDeclinedReasonDetailsEntities = ChangeTracker.Entries<AdvisoryBoardDeclinedReasonDetails>().ToList();
var AdvisoryBoardWithdrawnReasonDetailsEntities = ChangeTracker.Entries<AdvisoryBoardWithdrawnReasonDetails>().ToList();
var AdvisoryBoardDAORevokedDetailsEntities = ChangeTracker.Entries<AdvisoryBoardDAORevokedReasonDetails>().ToList();

foreach (var entity in advisoryBoardDeferredReasonDetailsEntities.Where(e => e.State == EntityState.Added))
{
Expand Down Expand Up @@ -103,7 +104,16 @@ private void SetModifiedAndCreatedDates()
{
entity.Entity.LastModifiedOn = timestamp;
}
foreach (var entity in AdvisoryBoardDAORevokedDetailsEntities.Where(e => e.State == EntityState.Added))
{
entity.Entity.CreatedOn = timestamp;
entity.Entity.LastModifiedOn = timestamp;
}

foreach (var entity in AdvisoryBoardDAORevokedDetailsEntities.Where(e => e.State == EntityState.Modified))
{
entity.Entity.LastModifiedOn = timestamp;
}
// for new domain object mapped directly to the database
var domainEntities = ChangeTracker.Entries<Entity>().ToList();

Expand Down Expand Up @@ -138,6 +148,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<AdvisoryBoardDeferredReasonDetails>(ConfigureConversionAdvisoryBoardDecisionDeferredReason);
modelBuilder.Entity<AdvisoryBoardDeclinedReasonDetails>(ConfigureConversionAdvisoryBoardDecisionDeclinedReason);
modelBuilder.Entity<AdvisoryBoardWithdrawnReasonDetails>(ConfigureAdvisoryBoardDecisionWithdrawnReason);
modelBuilder.Entity<AdvisoryBoardDAORevokedReasonDetails>(ConfigureAdvisoryBoardDecisionDAORevokedReason);

modelBuilder.Entity<FormAMatProject>(ConfigureFormAMatProject);

Expand Down Expand Up @@ -379,8 +390,8 @@ private static void ConfigureConversionAdvisoryBoardDecision(EntityTypeBuilder<C
.HasForeignKey(x => x.AdvisoryBoardDecisionId)
.IsRequired();

var diferredNav = ConversionAdvisoryBoardDecisionConfiguration.Metadata.FindNavigation(nameof(ConversionAdvisoryBoardDecision.DeferredReasons));
diferredNav.SetPropertyAccessMode(PropertyAccessMode.Field);
var deferredNav = ConversionAdvisoryBoardDecisionConfiguration.Metadata.FindNavigation(nameof(ConversionAdvisoryBoardDecision.DeferredReasons));
deferredNav.SetPropertyAccessMode(PropertyAccessMode.Field);

ConversionAdvisoryBoardDecisionConfiguration
.HasMany(a => a.DeclinedReasons)
Expand All @@ -390,6 +401,15 @@ private static void ConfigureConversionAdvisoryBoardDecision(EntityTypeBuilder<C

var declineNav = ConversionAdvisoryBoardDecisionConfiguration.Metadata.FindNavigation(nameof(ConversionAdvisoryBoardDecision.DeclinedReasons));
declineNav.SetPropertyAccessMode(PropertyAccessMode.Field);

ConversionAdvisoryBoardDecisionConfiguration
.HasMany(a => a.DaoRevokedReasons)
.WithOne()
.HasForeignKey(x => x.AdvisoryBoardDecisionId)
.IsRequired();

var daoRevokedNav = ConversionAdvisoryBoardDecisionConfiguration.Metadata.FindNavigation(nameof(ConversionAdvisoryBoardDecision.DaoRevokedReasons));
daoRevokedNav.SetPropertyAccessMode(PropertyAccessMode.Field);
}

private static void ConfigureConversionAdvisoryBoardDecisionDeferredReason(EntityTypeBuilder<AdvisoryBoardDeferredReasonDetails> ConversionAdvisoryBoardDecisionDeferredReasonConfiguration)
Expand All @@ -416,7 +436,13 @@ private static void ConfigureAdvisoryBoardDecisionWithdrawnReason(EntityTypeBuil
.Property(e => e.Reason)
.HasConversion<string>();
}

private static void ConfigureAdvisoryBoardDecisionDAORevokedReason(EntityTypeBuilder<AdvisoryBoardDAORevokedReasonDetails> AdvisoryBoardDecisionDAORevokedReasonConfiguration)
{
AdvisoryBoardDecisionDAORevokedReasonConfiguration.ToTable("AdvisoryBoardDecisionDAORevokedReason", DEFAULT_SCHEMA);
AdvisoryBoardDecisionDAORevokedReasonConfiguration
.Property(e => e.Reason)
.HasConversion<string>();
}
/// <summary>
/// New mapping for refactoring
/// </summary>
Expand Down
Loading

0 comments on commit 012b565

Please sign in to comment.