Skip to content

Commit

Permalink
Merge pull request #1497 from DFE-Digital/apply-candidate-channel-cre…
Browse files Browse the repository at this point in the history
…ation

update apply api method to set contact creation channel
  • Loading branch information
martyn-w authored Jan 28, 2025
2 parents f650c04 + 865c0b7 commit fb482ad
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 25 deletions.
27 changes: 15 additions & 12 deletions GetIntoTeachingApi/Jobs/ApplyCandidateSyncJob.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using GetIntoTeachingApi.Models.Apply;
using GetIntoTeachingApi.Models.Crm;
using GetIntoTeachingApi.Services;
using GetIntoTeachingApi.Utils;
using Hangfire;
using Microsoft.Extensions.Logging;
using ApplyCandidate = GetIntoTeachingApi.Models.Apply.Candidate;

namespace GetIntoTeachingApi.Jobs
{
Expand All @@ -29,7 +30,7 @@ public ApplyCandidateSyncJob(
_appSettings = appSettings;
}

public void Run(Candidate applyCandidate)
public void Run(ApplyCandidate applyCandidate)
{
if (_appSettings.IsCrmIntegrationPaused)
{
Expand All @@ -41,23 +42,25 @@ public void Run(Candidate applyCandidate)
_logger.LogInformation("ApplyCandidateSyncJob - Succeeded - {Id}", applyCandidate.Id);
}

public void SyncCandidate(Candidate applyCandidate)
public void SyncCandidate(ApplyCandidate applyCandidate)
{
var candidate = applyCandidate.ToCrmModel();
var match = _crm.MatchCandidate(candidate.Email, applyCandidate.Id);
ContactChannelCandidateWrapper wrappedCandidate = new(applyCandidate.ToCrmModel())
{
CreationChannelSourceId = (int?) ContactChannelCreation.CreationChannelSource.Apply
};

var match = _crm.MatchCandidate(wrappedCandidate.ScopedCandidate.Email, applyCandidate.Id);

_logger.LogInformation("ApplyCandidateSyncJob - {Status} - {Id}", match == null ? "Miss" : "Hit", applyCandidate.Id);

if (match != null)
{
UpdateCandidateWithMatch(candidate, match);
}
else
{
candidate.ChannelId = (int)Models.Crm.Candidate.Channel.ApplyForTeacherTraining;
UpdateCandidateWithMatch(wrappedCandidate.ScopedCandidate, match);
}

string json = candidate.SerializeChangeTracked();

wrappedCandidate.ScopedCandidate.ConfigureChannel(wrappedCandidate, wrappedCandidate.ScopedCandidate.Id);

string json = wrappedCandidate.ScopedCandidate.SerializeChangeTracked();
_jobClient.Enqueue<UpsertCandidateJob>((x) => x.Run(json, null));
}

Expand Down
41 changes: 41 additions & 0 deletions GetIntoTeachingApi/Jobs/ContactChannelCandidateWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using GetIntoTeachingApi.Models.Crm;

namespace GetIntoTeachingApi.Jobs
{
public class ContactChannelCandidateWrapper : ICreateContactChannel
{
/// <summary>
/// Provides the default read-only contact creation channel integer value.
/// </summary>
public int? DefaultContactCreationChannel =>
(int?)Candidate.Channel.ApplyForTeacherTraining;

/// <summary>
/// Provides the ability to assign and retrieve the channel source creation identifier.
/// </summary>
public int? CreationChannelSourceId { get; set; }

/// <summary>
/// Provides the ability to assign and retrieve the channel service creation identifier.
/// </summary>
public int? CreationChannelServiceId { get; set; }

/// <summary>
/// Provides the ability to assign and retrieve the channel activity creation identifier.
/// </summary>
public int? CreationChannelActivityId { get; set; }

/// <summary>
/// Provides the ability to retrieve the underlying CRM candidate record.
/// </summary>
public Candidate ScopedCandidate { get; }

/// <summary>
/// Initialises the instance with an underlying CRM candidate record.
/// </summary>
public ContactChannelCandidateWrapper(Candidate candidate)
{
ScopedCandidate = candidate;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
},
{
"Key": "dfe_channelcreation",
"Value": {
"Value": 222750025
}
"Value": null
},
{
"Key": "dfe_newregistrant",
Expand Down Expand Up @@ -126,5 +124,38 @@
"RelatedEntities": [],
"RowVersion": null,
"KeyAttributes": []
},
{
"LogicalName" : "dfe_contactchannelcreation",
"Id" : "00000000-0000-0000-0000-000000000000",
"Attributes" : [ {
"Key" : "dfe_contactid",
"Value" : {
"Id" : "00000000-0000-0000-0000-000000000000",
"LogicalName" : "contact",
"Name" : null,
"KeyAttributes" : [ ],
"RowVersion" : null
}
}, {
"Key" : "dfe_creationchannel",
"Value" : true
}, {
"Key" : "dfe_creationchannelactivities",
"Value" : null
}, {
"Key" : "dfe_creationchannelservice",
"Value" : null
}, {
"Key" : "dfe_creationchannelsource",
"Value" : {
"Value" : 222750000
}
} ],
"EntityState" : 1,
"FormattedValues" : [ ],
"RelatedEntities" : [ ],
"RowVersion" : null,
"KeyAttributes" : [ ]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
},
{
"Key": "dfe_channelcreation",
"Value": {
"Value": 222750025
}
"Value": null
},
{
"Key": "dfe_newregistrant",
Expand Down Expand Up @@ -277,5 +275,38 @@
"RelatedEntities": [],
"RowVersion": null,
"KeyAttributes": []
},
{
"LogicalName" : "dfe_contactchannelcreation",
"Id" : "00000000-0000-0000-0000-000000000000",
"Attributes" : [ {
"Key" : "dfe_contactid",
"Value" : {
"Id" : "00000000-0000-0000-0000-000000000000",
"LogicalName" : "contact",
"Name" : null,
"KeyAttributes" : [ ],
"RowVersion" : null
}
}, {
"Key" : "dfe_creationchannel",
"Value" : true
}, {
"Key" : "dfe_creationchannelactivities",
"Value" : null
}, {
"Key" : "dfe_creationchannelservice",
"Value" : null
}, {
"Key" : "dfe_creationchannelsource",
"Value" : {
"Value" : 222750000
}
} ],
"EntityState" : 1,
"FormattedValues" : [ ],
"RelatedEntities" : [ ],
"RowVersion" : null,
"KeyAttributes" : [ ]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
},
{
"Key": "dfe_channelcreation",
"Value": {
"Value": 222750025
}
"Value": null
},
{
"Key": "dfe_newregistrant",
Expand All @@ -45,5 +43,38 @@
"RelatedEntities": [],
"RowVersion": null,
"KeyAttributes": []
},
{
"LogicalName" : "dfe_contactchannelcreation",
"Id" : "00000000-0000-0000-0000-000000000000",
"Attributes" : [ {
"Key" : "dfe_contactid",
"Value" : {
"Id" : "00000000-0000-0000-0000-000000000000",
"LogicalName" : "contact",
"Name" : null,
"KeyAttributes" : [ ],
"RowVersion" : null
}
}, {
"Key" : "dfe_creationchannel",
"Value" : true
}, {
"Key" : "dfe_creationchannelactivities",
"Value" : null
}, {
"Key" : "dfe_creationchannelservice",
"Value" : null
}, {
"Key" : "dfe_creationchannelsource",
"Value" : {
"Value" : 222750000
}
} ],
"EntityState" : 1,
"FormattedValues" : [ ],
"RelatedEntities" : [ ],
"RowVersion" : null,
"KeyAttributes" : [ ]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,38 @@
"RelatedEntities": [],
"RowVersion": null,
"KeyAttributes": []
},
{
"LogicalName" : "dfe_contactchannelcreation",
"Id" : "00000000-0000-0000-0000-000000000000",
"Attributes" : [ {
"Key" : "dfe_contactid",
"Value" : {
"Id" : "00000000-0000-0000-0000-000000000000",
"LogicalName" : "contact",
"Name" : null,
"KeyAttributes" : [ ],
"RowVersion" : null
}
}, {
"Key" : "dfe_creationchannel",
"Value" : true
}, {
"Key" : "dfe_creationchannelactivities",
"Value" : null
}, {
"Key" : "dfe_creationchannelservice",
"Value" : null
}, {
"Key" : "dfe_creationchannelsource",
"Value" : {
"Value" : 222750000
}
} ],
"EntityState" : 1,
"FormattedValues" : [ ],
"RelatedEntities" : [ ],
"RowVersion" : null,
"KeyAttributes" : [ ]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,38 @@
"RelatedEntities": [],
"RowVersion": null,
"KeyAttributes": []
},
{
"LogicalName" : "dfe_contactchannelcreation",
"Id" : "00000000-0000-0000-0000-000000000000",
"Attributes" : [ {
"Key" : "dfe_contactid",
"Value" : {
"Id" : "00000000-0000-0000-0000-000000000000",
"LogicalName" : "contact",
"Name" : null,
"KeyAttributes" : [ ],
"RowVersion" : null
}
}, {
"Key" : "dfe_creationchannel",
"Value" : true
}, {
"Key" : "dfe_creationchannelactivities",
"Value" : null
}, {
"Key" : "dfe_creationchannelservice",
"Value" : null
}, {
"Key" : "dfe_creationchannelsource",
"Value" : {
"Value" : 222750000
}
} ],
"EntityState" : 1,
"FormattedValues" : [ ],
"RelatedEntities" : [ ],
"RowVersion" : null,
"KeyAttributes" : [ ]
}
]
Loading

0 comments on commit fb482ad

Please sign in to comment.