Skip to content

Commit

Permalink
Changes to handle the old async process
Browse files Browse the repository at this point in the history
  • Loading branch information
muralikaturi committed Nov 8, 2023
1 parent 90f554a commit 6759cff
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
public class CreateAndNotifyUserIntegrationEvent : IIntegrationEvent
{
public HearingDto Hearing { get; set; }
public IList<ParticipantDto> Participants { get; set; }
public HearingConfirmationForParticipantDto HearingConfirmationForParticipant { get; set; }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
public class HearingNotificationIntegrationEvent : IIntegrationEvent
{
public HearingDto Hearing { get; set; }
public IList<ParticipantDto> Participants { get; set; }
public HearingConfirmationForParticipantDto HearingConfirmationForParticipant { get; set; }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
public class MultiDayHearingIntegrationEvent : IIntegrationEvent
{
public HearingDto Hearing { get; set; }
public IList<ParticipantDto> Participants { get; set; }
public HearingConfirmationForParticipantDto HearingConfirmationForParticipant { get; set; }
public int TotalDays { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
using BookingQueueSubscriber.Services.UserApi;
using BookingsApi.Client;
using NotificationApi.Client;
using NotificationApi.Contract.Requests;

namespace BookingQueueSubscriber.Services.MessageHandlers
{
public class CreateAndNotifyUserHandler : IMessageHandler<CreateAndNotifyUserIntegrationEvent>
{
private readonly IUserCreationAndNotification _userCreationAndNotification;
private readonly INotificationApiClient _notificationApiClient;
private readonly IUserService _userService;
private readonly IBookingsApiClient _bookingsApiClient;

public CreateAndNotifyUserHandler(IUserCreationAndNotification userCreationAndNotification)
public CreateAndNotifyUserHandler(IUserService userService,
INotificationApiClient notificationApiClient,
IBookingsApiClient bookingsApiClient)
{
_userCreationAndNotification = userCreationAndNotification;
_userService = userService;
_notificationApiClient = notificationApiClient;
_bookingsApiClient = bookingsApiClient;
}

public async Task HandleAsync(CreateAndNotifyUserIntegrationEvent eventMessage)
{
var newParticipantUsers = await _userCreationAndNotification.CreateUserAndNotifcationAsync(
eventMessage.Hearing, eventMessage.Participants);
var message = eventMessage.HearingConfirmationForParticipant;
var newUser = await _userService.CreateNewUserForParticipantAsync(message.FirstName,
message.LastName, message.ContactEmail, false);

message.Username = newUser.UserName;

await _notificationApiClient.SendParticipantCreatedAccountEmailAsync(new SignInDetailsEmailRequest
{
ContactEmail = message.ContactEmail,
Name = $"{message.FirstName} {message.LastName}",
RoleName = message.UserRole,
Username = message.Username,
Password = newUser.Password,
});

await _userCreationAndNotification.HandleAssignUserToGroup(newParticipantUsers);
await _bookingsApiClient.UpdatePersonUsernameAsync(message.ContactEmail, message.Username);
await _userService.AssignUserToGroup(newUser.UserId, message.UserRole);
}

async Task IMessageHandler.HandleAsync(object integrationEvent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
using NotificationApi.Client;
using NotificationApi.Contract.Requests;

namespace BookingQueueSubscriber.Services.MessageHandlers
{
public class HearingNotificationHandler : IMessageHandler<HearingNotificationIntegrationEvent>
{
private readonly IUserCreationAndNotification _userCreationAndNotification;
private readonly INotificationApiClient _notificationApiClient;

public HearingNotificationHandler(IUserCreationAndNotification userCreationAndNotification)
public HearingNotificationHandler(INotificationApiClient notificationApiClient)
{
_userCreationAndNotification = userCreationAndNotification;
_notificationApiClient = notificationApiClient;
}

public async Task HandleAsync(HearingNotificationIntegrationEvent eventMessage)
{
await _userCreationAndNotification.SendHearingNotificationAsync(eventMessage.Hearing, eventMessage.Participants);
var message = eventMessage.HearingConfirmationForParticipant;

var request = new ExistingUserSingleDayHearingConfirmationRequest
{
HearingId = message.HearingId,
ContactEmail = message.ContactEmail,
ParticipantId = message.ParticipantId,
CaseName = message.CaseName,
CaseNumber = message.CaseNumber,
DisplayName = message.DisplayName,
Name = $"{message.FirstName} {message.LastName}",
Representee = message.Representee,
Username = message.Username,
RoleName = message.UserRole,
ScheduledDateTime = message.ScheduledDateTime
};

await _notificationApiClient.SendParticipantSingleDayHearingConfirmationForExistingUserEmailAsync(request);
}

async Task IMessageHandler.HandleAsync(object integrationEvent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
using BookingQueueSubscriber.Services.NotificationApi;
using NotificationApi.Client;
using NotificationApi.Contract.Requests;

namespace BookingQueueSubscriber.Services.MessageHandlers
{
public class MultiDayHearingHandler : IMessageHandler<MultiDayHearingIntegrationEvent>
{
private readonly INotificationService _notificationService;
private readonly INotificationApiClient _notificationApiClient;

public MultiDayHearingHandler(INotificationService notificationService)
public MultiDayHearingHandler(INotificationApiClient notificationApiClient)
{
_notificationService = notificationService;
_notificationApiClient = notificationApiClient;
}

public async Task HandleAsync(MultiDayHearingIntegrationEvent eventMessage)
{
await _notificationService.SendMultiDayHearingNotificationAsync(eventMessage.Hearing,
eventMessage.Participants, eventMessage.TotalDays);
var message = eventMessage.HearingConfirmationForParticipant;
var cleanedCaseName = message.CaseName.Replace($"Day 1 of {eventMessage.TotalDays}", string.Empty).Trim();
var request = new ExistingUserMultiDayHearingConfirmationRequest
{
Name = $"{message.FirstName} {message.LastName}",
CaseName = cleanedCaseName,
CaseNumber = message.CaseNumber,
ContactEmail = message.ContactEmail,
DisplayName = message.DisplayName,
HearingId = message.HearingId,
ParticipantId = message.ParticipantId,
Representee = message.Representee,
RoleName = message.Username,
ScheduledDateTime = message.ScheduledDateTime,
TotalDays = eventMessage.TotalDays,
Username = message.Username
};

await _notificationApiClient.SendParticipantMultiDayHearingConfirmationForExistingUserEmailAsync(request);
}

async Task IMessageHandler.HandleAsync(object integrationEvent)
public async Task HandleAsync(object integrationEvent)
{
await HandleAsync((MultiDayHearingIntegrationEvent)integrationEvent);
}
Expand Down
Loading

0 comments on commit 6759cff

Please sign in to comment.