From 01dd3d0c80a9ce860161efc441f6ca223062a0b8 Mon Sep 17 00:00:00 2001 From: Martyn Whitwell Date: Thu, 23 Jan 2025 17:49:08 +0000 Subject: [PATCH] update apply api method to set contact creation channel --- .../Jobs/ApplyCandidateSyncJob.cs | 24 ++++++------ .../Jobs/ContactChannelCandidateWrapper.cs | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 GetIntoTeachingApi/Jobs/ContactChannelCandidateWrapper.cs diff --git a/GetIntoTeachingApi/Jobs/ApplyCandidateSyncJob.cs b/GetIntoTeachingApi/Jobs/ApplyCandidateSyncJob.cs index 8fb10aac7..d6e1fda0f 100644 --- a/GetIntoTeachingApi/Jobs/ApplyCandidateSyncJob.cs +++ b/GetIntoTeachingApi/Jobs/ApplyCandidateSyncJob.cs @@ -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 { @@ -29,7 +30,7 @@ public ApplyCandidateSyncJob( _appSettings = appSettings; } - public void Run(Candidate applyCandidate) + public void Run(ApplyCandidate applyCandidate) { if (_appSettings.IsCrmIntegrationPaused) { @@ -41,23 +42,22 @@ 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()); + + 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); + UpdateCandidateWithMatch(wrappedCandidate.ScopedCandidate, match); } - else - { - candidate.ChannelId = (int)Models.Crm.Candidate.Channel.ApplyForTeacherTraining; - } - - string json = candidate.SerializeChangeTracked(); + + wrappedCandidate.ScopedCandidate.ConfigureChannel(wrappedCandidate, wrappedCandidate.ScopedCandidate.Id); + + string json = wrappedCandidate.ScopedCandidate.SerializeChangeTracked(); _jobClient.Enqueue((x) => x.Run(json, null)); } diff --git a/GetIntoTeachingApi/Jobs/ContactChannelCandidateWrapper.cs b/GetIntoTeachingApi/Jobs/ContactChannelCandidateWrapper.cs new file mode 100644 index 000000000..f9aed24a5 --- /dev/null +++ b/GetIntoTeachingApi/Jobs/ContactChannelCandidateWrapper.cs @@ -0,0 +1,37 @@ +using GetIntoTeachingApi.Models.Crm; + +namespace GetIntoTeachingApi.Jobs; + +public class ContactChannelCandidateWrapper : ICreateContactChannel +{ + + /// + /// Provides the default read-only contact creation channel integer value. + /// + public int? DefaultContactCreationChannel => + (int?)Candidate.Channel.ApplyForTeacherTraining; + + /// + /// Provides the ability to assign and retrieve the channel source creation identifier. + /// + public int? CreationChannelSourceId { get; set; } + + /// + /// Provides the ability to assign and retrieve the channel service creation identifier. + /// + public int? CreationChannelServiceId { get; set; } + + /// + /// Provides the ability to assign and retrieve the channel activity creation identifier. + /// + public int? CreationChannelActivityId { get; set; } + + + public Candidate ScopedCandidate { get; } + + // Todo: add some documentation + public ContactChannelCandidateWrapper(Candidate candidate) + { + ScopedCandidate = candidate; + } +} \ No newline at end of file