Skip to content

Commit

Permalink
UserEmailServiceV2 use JobService to avoid constructor warning AB#16818.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMaki committed Aug 15, 2024
1 parent d2bba63 commit fa05b6a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Apps/GatewayApi/src/Services/IJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public interface IJobService
/// <param name="smsVerificationCode">The code used to validate the ownership of the number.</param>
/// <param name="ct"><see cref="CancellationToken"/> to manage the async request.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task PushNotificationSettingsToPhsaAsync(UserProfile userProfile, string email, string smsNumber, string smsVerificationCode, CancellationToken ct = default);
Task PushNotificationSettingsToPhsaAsync(UserProfile userProfile, string? email, string? smsNumber, string? smsVerificationCode = null, CancellationToken ct = default);
}
}
2 changes: 1 addition & 1 deletion Apps/GatewayApi/src/Services/JobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task SendEmailAsync(string emailAddress, string emailTemplateName,
}

/// <inheritdoc/>
public async Task PushNotificationSettingsToPhsaAsync(UserProfile userProfile, string email, string smsNumber, string smsVerificationCode, CancellationToken ct = default)
public async Task PushNotificationSettingsToPhsaAsync(UserProfile userProfile, string? email, string? smsNumber, string? smsVerificationCode = null, CancellationToken ct = default)
{
NotificationSettingsRequest notificationSettingsRequest = new(userProfile, email, smsNumber) { SmsVerificationCode = smsVerificationCode };
await notificationSettingsService.QueueNotificationSettingsAsync(notificationSettingsRequest, ct);
Expand Down
29 changes: 8 additions & 21 deletions Apps/GatewayApi/src/Services/UserEmailServiceV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ namespace HealthGateway.GatewayApi.Services
using HealthGateway.Common.Constants;
using HealthGateway.Common.Data.Constants;
using HealthGateway.Common.ErrorHandling.Exceptions;
using HealthGateway.Common.Messaging;
using HealthGateway.Common.Models;
using HealthGateway.Common.Models.Events;
using HealthGateway.Common.Services;
using HealthGateway.Database.Constants;
using HealthGateway.Database.Delegates;
using HealthGateway.Database.Models;
Expand All @@ -39,13 +35,11 @@ public class UserEmailServiceV2 : IUserEmailServiceV2
{
private const int MaxVerificationAttempts = 5;

private readonly IEmailQueueService emailQueueService;
private readonly ILogger logger;
private readonly IMessagingVerificationDelegate messageVerificationDelegate;
private readonly IMessagingVerificationService messagingVerificationService;
private readonly INotificationSettingsService notificationSettingsService;
private readonly IUserProfileDelegate profileDelegate;
private readonly IMessageSender messageSender;
private readonly IJobService jobService;
private readonly bool notificationsChangeFeedEnabled;

/// <summary>
Expand All @@ -55,27 +49,21 @@ public class UserEmailServiceV2 : IUserEmailServiceV2
/// <param name="messageVerificationDelegate">The message verification delegate to interact with the DB.</param>
/// <param name="messagingVerificationService">The messaging verification service.</param>
/// <param name="profileDelegate">The profile delegate to interact with the DB.</param>
/// <param name="emailQueueService">The email service to queue emails.</param>
/// <param name="notificationSettingsService">Notification settings delegate.</param>
/// <param name="jobService">The injected job service.</param>
/// <param name="configuration">Configuration settings.</param>
/// <param name="messageSender">The message sender.</param>
public UserEmailServiceV2(
ILogger<UserEmailServiceV2> logger,
IMessagingVerificationDelegate messageVerificationDelegate,
IMessagingVerificationService messagingVerificationService,
IUserProfileDelegate profileDelegate,
IEmailQueueService emailQueueService,
INotificationSettingsService notificationSettingsService,
IConfiguration configuration,
IMessageSender messageSender)
IJobService jobService,
IConfiguration configuration)
{
this.logger = logger;
this.messageVerificationDelegate = messageVerificationDelegate;
this.messagingVerificationService = messagingVerificationService;
this.profileDelegate = profileDelegate;
this.emailQueueService = emailQueueService;
this.notificationSettingsService = notificationSettingsService;
this.messageSender = messageSender;
this.jobService = jobService;
this.notificationsChangeFeedEnabled = configuration.GetSection(ChangeFeedOptions.ChangeFeed).Get<ChangeFeedOptions>()?.Notifications.Enabled ?? false;
}

Expand Down Expand Up @@ -159,7 +147,7 @@ public async Task UpdateEmailAddressAsync(string hdid, string emailAddress, Canc
if (messagingVerification != null)
{
this.logger.LogInformation("Sending new email verification for user {Hdid}", hdid);
await this.emailQueueService.QueueNewEmailAsync(messagingVerification.Email, true, ct);
await this.jobService.SendEmailAsync(messagingVerification.Email, true, ct);
}

await this.QueueNotificationSettingsRequest(userProfile, ct);
Expand Down Expand Up @@ -196,14 +184,13 @@ private async Task NotifyVerificationSuccessful(string hdid, string emailAddress
{
if (this.notificationsChangeFeedEnabled)
{
MessageEnvelope[] events = [new(new NotificationChannelVerifiedEvent(hdid, NotificationChannel.Email, emailAddress), hdid)];
await this.messageSender.SendAsync(events, ct);
await this.jobService.NotifyEmailVerificationAsync(hdid, emailAddress, ct);
}
}

private async Task QueueNotificationSettingsRequest(UserProfile userProfile, CancellationToken ct)
{
await this.notificationSettingsService.QueueNotificationSettingsAsync(new NotificationSettingsRequest(userProfile, userProfile.Email, userProfile.SmsNumber), ct);
await this.jobService.PushNotificationSettingsToPhsaAsync(userProfile, userProfile.Email, userProfile.SmsNumber, ct: ct);
}
}
}
Loading

0 comments on commit fa05b6a

Please sign in to comment.