Generalised lead entries
This commit is contained in:
@@ -4,7 +4,9 @@ public class CreateLeadCommand : IRequest<Result<Guid>>
|
||||
{
|
||||
public Guid? CustomerId { get; set; }
|
||||
|
||||
public string? GoogleClickId { get; set; }
|
||||
public string? Source { get; set; }
|
||||
|
||||
public string? ClickId { get; set; }
|
||||
|
||||
public string? WebClickId { get; set; }
|
||||
|
||||
@@ -24,10 +26,11 @@ public class CreateLeadCommand : IRequest<Result<Guid>>
|
||||
|
||||
public string? AttribusionHash { get; set; }
|
||||
|
||||
private CreateLeadCommand(Guid? customerId, string googleClickId, string webClickId, string appClickId, long? campaignId, long? adGroupId, long? adName, long? targetId, long? feedItemId, string? clickLocation, string? attribusionHash)
|
||||
private CreateLeadCommand(Guid? customerId, string source, string clickId, string webClickId, string appClickId, long? campaignId, long? adGroupId, long? adName, long? targetId, long? feedItemId, string? clickLocation, string? attribusionHash)
|
||||
{
|
||||
CustomerId = customerId;
|
||||
GoogleClickId = googleClickId;
|
||||
Source = source;
|
||||
ClickId = clickId;
|
||||
WebClickId = webClickId;
|
||||
AppClickId = appClickId;
|
||||
CampaignId = campaignId;
|
||||
@@ -39,11 +42,14 @@ public class CreateLeadCommand : IRequest<Result<Guid>>
|
||||
AttribusionHash = attribusionHash;
|
||||
}
|
||||
|
||||
public static CreateLeadCommand Create(Guid? customerId, string googleClickId, string webClickId, string appClickId, long? campaignId, long? adGroupId, long? adName, long? targetId, long? feedItemId, string? clickLocation, string? attribusionHash)
|
||||
public static CreateLeadCommand Create(Guid? customerId, string source, string clickId, string webClickId, string appClickId, long? campaignId, long? adGroupId, long? adName, long? targetId, long? feedItemId, string? clickLocation, string? attribusionHash)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(googleClickId) || string.IsNullOrWhiteSpace(appClickId) || string.IsNullOrWhiteSpace(webClickId))
|
||||
throw new ArgumentException("Google ClickId, App ClickId and Web ClickId are required to create a lead.");
|
||||
if(string.IsNullOrWhiteSpace(source))
|
||||
throw new ArgumentNullException("Lead source is required to create a lead.", nameof(source));
|
||||
|
||||
return new(customerId, googleClickId, webClickId, appClickId, campaignId, adGroupId, adName, targetId, feedItemId, clickLocation, attribusionHash);
|
||||
if (string.IsNullOrWhiteSpace(clickId) || string.IsNullOrWhiteSpace(appClickId) || string.IsNullOrWhiteSpace(webClickId))
|
||||
throw new ArgumentException("ClickId, App ClickId and Web ClickId are required to create a lead.");
|
||||
|
||||
return new(customerId, source, clickId, webClickId, appClickId, campaignId, adGroupId, adName, targetId, feedItemId, clickLocation, attribusionHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ public class CreateLeadCommandHandler(IDbContextFactory<LeadGeneratorDbContext>
|
||||
{
|
||||
try
|
||||
{
|
||||
var hashCommand = ComputeHashCommand.Create($"{request.GoogleClickId}{request.AppClickId}{request.WebClickId}");
|
||||
var hashCommand = ComputeHashCommand.Create($"{request.ClickId}{request.AppClickId}{request.WebClickId}");
|
||||
var hashResult = await mediator.Send(hashCommand, cancellationToken);
|
||||
|
||||
if(hashResult.IsFailed)
|
||||
return Result.Fail<Guid>(new Error($"Failed to compute hash for lead -> Google ClickId: {request.GoogleClickId}, App ClickId: {request.AppClickId}, Web ClickId: {request.WebClickId}")
|
||||
return Result.Fail<Guid>(new Error($"Failed to compute hash for lead -> Google ClickId: {request.ClickId}, App ClickId: {request.AppClickId}, Web ClickId: {request.WebClickId}")
|
||||
.CausedBy(hashResult.Errors));
|
||||
|
||||
using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
@@ -22,7 +22,8 @@ public class CreateLeadCommandHandler(IDbContextFactory<LeadGeneratorDbContext>
|
||||
{
|
||||
WebClickId = request.WebClickId,
|
||||
AppClickId = request.AppClickId,
|
||||
GoogleClickId = request.GoogleClickId,
|
||||
Source = request.Source,
|
||||
ClickId = request.ClickId,
|
||||
AdGroupId = request.AdGroupId,
|
||||
AdName = request.AdName,
|
||||
CampaignId = request.CampaignId,
|
||||
@@ -36,7 +37,7 @@ public class CreateLeadCommandHandler(IDbContextFactory<LeadGeneratorDbContext>
|
||||
|
||||
return await context.SaveChangesAsync(cancellationToken) > 0
|
||||
? Result.Ok(newLead.Entity.Id)
|
||||
: Result.Fail<Guid>(new Error($"Failed to create lead -> Google ClickId: {request.GoogleClickId}, App ClickId: {request.AppClickId}, Web ClickId: {request.WebClickId}"));
|
||||
: Result.Fail<Guid>(new Error($"Failed to create lead -> Google ClickId: {request.ClickId}, App ClickId: {request.AppClickId}, Web ClickId: {request.WebClickId}"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user