Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update apply api method to set contact creation channel #1497

Open
wants to merge 1 commit into
base: add-creation-channel-model
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading