-
Notifications
You must be signed in to change notification settings - Fork 1
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 #537 from cabinetoffice/feature/dp-516-mappings
DP-516 - SupplierInformation mapping added
- Loading branch information
Showing
14 changed files
with
240 additions
and
36 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace CO.CDP.DataSharing.WebApi.Model; | ||
|
||
public record FormAnswerSet | ||
{ | ||
/// <example>"3b3a269a-c1fa-4bfa-8892-7c6a9aef03bb"</example> | ||
public required Guid Id { get; set; } | ||
|
||
public required ICollection<FormAnswer> Answers { get; set; } = []; | ||
} |
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
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
42 changes: 37 additions & 5 deletions
42
Services/CO.CDP.DataSharing.WebApi/UseCase/GetSharedDataUseCase.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 |
---|---|---|
@@ -1,22 +1,54 @@ | ||
using AutoMapper; | ||
using CO.CDP.DataSharing.WebApi.Model; | ||
using CO.CDP.OrganisationInformation; | ||
using CO.CDP.OrganisationInformation.Persistence; | ||
using SharedConsent = CO.CDP.OrganisationInformation.Persistence.Forms.SharedConsent; | ||
|
||
namespace CO.CDP.DataSharing.WebApi.UseCase; | ||
|
||
public class GetSharedDataUseCase( | ||
IShareCodeRepository shareCodeRepository, | ||
IOrganisationRepository organisationRepository, | ||
IMapper mapper) | ||
: IUseCase<string, SupplierInformation?> | ||
{ | ||
public async Task<SupplierInformation?> Execute(string sharecode) | ||
{ | ||
var organisation = await shareCodeRepository.GetByShareCode(sharecode); | ||
if (organisation == null) | ||
var sharedConsent = await shareCodeRepository.GetByShareCode(sharecode) | ||
?? throw new SharedConsentNotFoundException("Shared Consent not found."); | ||
|
||
var associatedPersons = await AssociatedPersons(sharedConsent); | ||
var additionalEntities = await AdditionalEntities(sharedConsent); | ||
return mapper.Map<SupplierInformation>(sharedConsent, opts => | ||
{ | ||
opts.Items["AssociatedPersons"] = associatedPersons; | ||
opts.Items["AdditionalParties"] = new List<OrganisationReference>(); | ||
opts.Items["AdditionalEntities"] = additionalEntities; | ||
}); | ||
} | ||
|
||
private async Task<ICollection<AssociatedPerson>> AssociatedPersons(SharedConsent sharedConsent) | ||
{ | ||
var associatedPersons = await organisationRepository.GetConnectedIndividualTrusts(sharedConsent.OrganisationId); | ||
return associatedPersons.Select(x => new AssociatedPerson | ||
{ | ||
throw new SharedConsentNotFoundException("Shared Consent not found."); | ||
} | ||
Id = x.Guid, | ||
Name = string.Format($"{x.IndividualOrTrust?.FirstName} {x.IndividualOrTrust?.LastName}"), | ||
Relationship = x.IndividualOrTrust?.Category.ToString() ?? string.Empty, | ||
Uri = null, | ||
Roles = [] | ||
}).ToList(); | ||
} | ||
|
||
return mapper.Map<SupplierInformation>(organisation); | ||
private async Task<ICollection<OrganisationReference>> AdditionalEntities(SharedConsent sharedConsent) | ||
{ | ||
var additionalEntities = await organisationRepository.GetConnectedOrganisations(sharedConsent.OrganisationId); | ||
return additionalEntities.Select(x => new OrganisationReference | ||
{ | ||
Id = x.Guid, | ||
Name = x.Organisation?.Name ?? string.Empty, | ||
Roles = [], | ||
Uri = null | ||
}).ToList(); | ||
} | ||
} |
Oops, something went wrong.