-
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.
Added previous names to v3 endpoint including tests (#917)
* Added previous names to v3 endpoint including tests * Added plugin to mimic how QTS and EYTS dates are updated on Contact in real CRM + updated tests * more tweaks from PR comments
- Loading branch information
Showing
22 changed files
with
800 additions
and
234 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/ApiModels/NameInfo.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,8 @@ | ||
namespace TeachingRecordSystem.Api.V3.ApiModels; | ||
|
||
public record NameInfo | ||
{ | ||
public required string FirstName { get; init; } | ||
public required string MiddleName { get; init; } | ||
public required string LastName { get; init; } | ||
} |
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 |
---|---|---|
|
@@ -12,5 +12,6 @@ | |
"Microsoft.AspNetCore": "Fatal" | ||
} | ||
} | ||
} | ||
}, | ||
"ConcurrentNameChangeWindowSeconds": 1 | ||
} |
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
3 changes: 3 additions & 0 deletions
3
...ngRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetAllEarlyYearsStatusesQuery.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,3 @@ | ||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public record GetAllEarlyYearsStatusesQuery : ICrmQuery<dfeta_earlyyearsstatus[]>; |
5 changes: 5 additions & 0 deletions
5
TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetContactDetailByTrnQuery.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 @@ | ||
using Microsoft.Xrm.Sdk.Query; | ||
|
||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public record GetContactDetailByTrnQuery(string Trn, ColumnSet ColumnSet) : ICrmQuery<ContactDetail?>; |
30 changes: 30 additions & 0 deletions
30
...System/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetAllEarlyYearsStatusesHandler.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,30 @@ | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Query; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; | ||
|
||
public class GetAllEarlyYearsStatusesHandler : ICrmQueryHandler<GetAllEarlyYearsStatusesQuery, dfeta_earlyyearsstatus[]> | ||
{ | ||
public async Task<dfeta_earlyyearsstatus[]> Execute(GetAllEarlyYearsStatusesQuery query, IOrganizationServiceAsync organizationService) | ||
{ | ||
var queryExpression = new QueryExpression() | ||
{ | ||
EntityName = dfeta_earlyyearsstatus.EntityLogicalName, | ||
ColumnSet = new ColumnSet( | ||
dfeta_earlyyearsstatus.Fields.dfeta_name, | ||
dfeta_earlyyearsstatus.Fields.dfeta_Value) | ||
}; | ||
queryExpression.Criteria.AddCondition(dfeta_earlyyearsstatus.Fields.StateCode, ConditionOperator.Equal, (int)dfeta_earlyyearsStatusState.Active); | ||
|
||
var request = new RetrieveMultipleRequest() | ||
{ | ||
Query = queryExpression | ||
}; | ||
|
||
var response = await organizationService.RetrieveMultipleAsync(queryExpression); | ||
|
||
return response.Entities.Select(e => e.ToEntity<dfeta_earlyyearsstatus>()).ToArray(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...ordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetContactDetailByTrnHandler.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,74 @@ | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Query; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; | ||
|
||
public class GetContactDetailByTrnHandler : ICrmQueryHandler<GetContactDetailByTrnQuery, ContactDetail?> | ||
{ | ||
public async Task<ContactDetail?> Execute(GetContactDetailByTrnQuery query, IOrganizationServiceAsync organizationService) | ||
{ | ||
var contactFilter = new FilterExpression(); | ||
contactFilter.AddCondition(Contact.Fields.dfeta_TRN, ConditionOperator.Equal, query.Trn); | ||
var contactQueryExpression = new QueryExpression(Contact.EntityLogicalName) | ||
{ | ||
ColumnSet = query.ColumnSet, | ||
Criteria = contactFilter | ||
}; | ||
|
||
var contactRequest = new RetrieveMultipleRequest() | ||
{ | ||
Query = contactQueryExpression | ||
}; | ||
|
||
var previousNameFilter = new FilterExpression(); | ||
previousNameFilter.AddCondition(dfeta_previousname.Fields.StateCode, ConditionOperator.Equal, (int)dfeta_documentState.Active); | ||
previousNameFilter.AddCondition(dfeta_previousname.Fields.dfeta_Type, ConditionOperator.NotEqual, (int)dfeta_NameType.Title); | ||
var previousNameQueryExpression = new QueryExpression(dfeta_previousname.EntityLogicalName) | ||
{ | ||
ColumnSet = new ColumnSet( | ||
dfeta_previousname.PrimaryIdAttribute, | ||
dfeta_previousname.Fields.dfeta_PersonId, | ||
dfeta_previousname.Fields.CreatedOn, | ||
dfeta_previousname.Fields.dfeta_ChangedOn, | ||
dfeta_previousname.Fields.dfeta_name, | ||
dfeta_previousname.Fields.dfeta_Type), | ||
Criteria = previousNameFilter | ||
}; | ||
|
||
var contactLink = previousNameQueryExpression.AddLink( | ||
Contact.EntityLogicalName, | ||
dfeta_previousname.Fields.dfeta_PersonId, | ||
Contact.PrimaryIdAttribute, | ||
JoinOperator.Inner); | ||
|
||
contactLink.Columns = new ColumnSet( | ||
Contact.PrimaryIdAttribute, | ||
Contact.Fields.dfeta_TRN); | ||
|
||
contactLink.EntityAlias = Contact.EntityLogicalName; | ||
contactLink.LinkCriteria = contactFilter; | ||
|
||
var previousNameRequest = new RetrieveMultipleRequest() | ||
{ | ||
Query = previousNameQueryExpression | ||
}; | ||
|
||
var requestBuilder = RequestBuilder.CreateMultiple(organizationService); | ||
var contactResponse = requestBuilder.AddRequest<RetrieveMultipleResponse>(contactRequest); | ||
var previousNameResponse = requestBuilder.AddRequest<RetrieveMultipleResponse>(previousNameRequest); | ||
|
||
await requestBuilder.Execute(); | ||
|
||
var contact = (await contactResponse.GetResponseAsync()).EntityCollection.Entities.FirstOrDefault()?.ToEntity<Contact>(); | ||
var previousNames = (await previousNameResponse.GetResponseAsync()).EntityCollection.Entities.Select(e => e.ToEntity<dfeta_previousname>()).ToArray(); | ||
|
||
if (contact is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return new ContactDetail(contact, previousNames); | ||
} | ||
} |
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.