Skip to content

Commit

Permalink
update apply api method to set contact creation channel
Browse files Browse the repository at this point in the history
  • Loading branch information
martyn-w committed Jan 23, 2025
1 parent 2ae66ef commit 01dd3d0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
24 changes: 12 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,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<UpsertCandidateJob>((x) => x.Run(json, null));
}

Expand Down
37 changes: 37 additions & 0 deletions GetIntoTeachingApi/Jobs/ContactChannelCandidateWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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; }


public Candidate ScopedCandidate { get; }

// Todo: add some documentation

Check warning on line 32 in GetIntoTeachingApi/Jobs/ContactChannelCandidateWrapper.cs

View workflow job for this annotation

GitHub Actions / sonarcloud

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
public ContactChannelCandidateWrapper(Candidate candidate)
{
ScopedCandidate = candidate;
}
}

0 comments on commit 01dd3d0

Please sign in to comment.