-
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.
Merge pull request #517 from DFE-Digital/connect-fiat-db-to-ui
Connect fiat db to UI
- Loading branch information
Showing
37 changed files
with
549 additions
and
167 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
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
78 changes: 78 additions & 0 deletions
78
DfE.FindInformationAcademiesTrusts.Data.FiatDb/Repositories/ContactRepository.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,78 @@ | ||
using DfE.FindInformationAcademiesTrusts.Data.Enums; | ||
using DfE.FindInformationAcademiesTrusts.Data.FiatDb.Contexts; | ||
using DfE.FindInformationAcademiesTrusts.Data.FiatDb.Models; | ||
using DfE.FindInformationAcademiesTrusts.Data.Repositories.Contacts; | ||
using DfE.FindInformationAcademiesTrusts.Data.Repositories.Trust; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace DfE.FindInformationAcademiesTrusts.Data.FiatDb.Repositories; | ||
|
||
public interface IContactRepository | ||
{ | ||
Task<InternalContacts> GetInternalContactsAsync(string uid); | ||
|
||
Task<TrustContactUpdated> UpdateInternalContactsAsync(int uid, string? name, string? email, | ||
ContactRole role); | ||
} | ||
|
||
public class ContactRepository(IFiatDbContext fiatDbContext) : IContactRepository | ||
{ | ||
public async Task<InternalContacts> GetInternalContactsAsync(string uid) | ||
{ | ||
var trm = await GetTrustRelationshipManagerLinkedTo(uid); | ||
var sfso = await GetSfsoLeadLinkedTo(uid); | ||
|
||
return new InternalContacts( | ||
trm, | ||
sfso); | ||
} | ||
|
||
public async Task<TrustContactUpdated> UpdateInternalContactsAsync(int uid, string? name, string? email, | ||
ContactRole role) | ||
{ | ||
var emailUpdated = false; | ||
var nameUpdated = false; | ||
var contact = | ||
await fiatDbContext.Contacts.SingleOrDefaultAsync(contact => contact.Uid == uid && contact.Role == role); | ||
if (contact is null) | ||
{ | ||
fiatDbContext.Contacts.Add(new Contact | ||
{ Name = name ?? string.Empty, Email = email ?? string.Empty, Role = role, Uid = uid }); | ||
} | ||
else | ||
{ | ||
if (contact.Name != name) | ||
{ | ||
nameUpdated = true; | ||
contact.Name = name ?? string.Empty; | ||
} | ||
|
||
if (contact.Email != email) | ||
{ | ||
emailUpdated = true; | ||
contact.Email = email ?? string.Empty; | ||
} | ||
} | ||
|
||
await fiatDbContext.SaveChangesAsync(); | ||
return new TrustContactUpdated(emailUpdated, nameUpdated); | ||
} | ||
|
||
private async Task<InternalContact?> GetTrustRelationshipManagerLinkedTo(string uid) | ||
{ | ||
return await fiatDbContext.Contacts.Where(contact => | ||
contact.Uid == int.Parse(uid) && contact.Role == ContactRole.TrustRelationshipManager) | ||
.Select(contact => new InternalContact(contact.Name, contact.Email, | ||
contact.LastModifiedAtTime, contact.LastModifiedByEmail | ||
)).SingleOrDefaultAsync(); | ||
} | ||
|
||
private async Task<InternalContact?> GetSfsoLeadLinkedTo(string uid) | ||
{ | ||
return await fiatDbContext.Contacts.Where(contact => | ||
contact.Uid == int.Parse(uid) && contact.Role == ContactRole.SfsoLead) | ||
.Select(contact => new InternalContact(contact.Name, contact.Email, | ||
contact.LastModifiedAtTime, contact.LastModifiedByEmail | ||
)).SingleOrDefaultAsync(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,5 +6,6 @@ public enum Source | |
Mstr, | ||
Cdm, | ||
Mis, | ||
ExploreEducationStatistics | ||
ExploreEducationStatistics, | ||
FiatDb | ||
} |
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,8 @@ | ||
namespace DfE.FindInformationAcademiesTrusts.Data; | ||
|
||
public record InternalContact( | ||
string FullName, | ||
string Email, | ||
DateTime LastModifiedAtTime, | ||
string LastModifiedByEmail | ||
) : Person(FullName, Email); |
6 changes: 6 additions & 0 deletions
6
DfE.FindInformationAcademiesTrusts.Data/Repositories/Contacts/InternalContacts.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,6 @@ | ||
namespace DfE.FindInformationAcademiesTrusts.Data.Repositories.Contacts; | ||
|
||
public record InternalContacts( | ||
InternalContact? TrustRelationshipManager, | ||
InternalContact? SfsoLead | ||
); |
5 changes: 5 additions & 0 deletions
5
DfE.FindInformationAcademiesTrusts.Data/Repositories/Trust/TrustContactUpdated.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,5 @@ | ||
namespace DfE.FindInformationAcademiesTrusts.Data.Repositories.Trust; | ||
|
||
public record TrustContactUpdated( | ||
bool EmailUpdated, | ||
bool NameUpdated); |
2 changes: 0 additions & 2 deletions
2
DfE.FindInformationAcademiesTrusts.Data/Repositories/Trust/TrustContacts.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
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
16 changes: 16 additions & 0 deletions
16
DfE.FindInformationAcademiesTrusts/Extensions/ContactRoleExtensions.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,16 @@ | ||
using DfE.FindInformationAcademiesTrusts.Data.Enums; | ||
|
||
namespace DfE.FindInformationAcademiesTrusts.Extensions; | ||
|
||
public static class ContactRoleExtensions | ||
{ | ||
public static string MapRoleToViewString(this ContactRole role) | ||
{ | ||
return role switch | ||
{ | ||
ContactRole.TrustRelationshipManager => "Trust relationship manager", | ||
ContactRole.SfsoLead => "SFSO (Schools financial support and oversight) lead", | ||
_ => throw new ArgumentOutOfRangeException(nameof(role)) | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.