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

(#126) update the method students notifications are added to repository #251

Merged
merged 8 commits into from
Jun 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task HandleAsync(CommentCreated eventArgs, CancellationToken cancel
);

studentNotifications.AddNotification(userNotification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var userNotificationDetailsHtml = $"<p>Your comment on the event '{eventDetails.Name}' has been posted successfully.</p>";

Expand Down Expand Up @@ -119,7 +119,7 @@ public async Task HandleAsync(CommentCreated eventArgs, CancellationToken cancel
);

organizerNotifications.AddNotification(organizerNotification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var organizerNotificationDetailsHtml = $"<p>{commentDetails.StudentName} commented on your event '{eventDetails.Name}': {commentDetails.CommentContext}</p>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task HandleAsync(CommentUpdated eventArgs, CancellationToken cancel
);

studentNotifications.AddNotification(userNotification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var userNotificationDetailsHtml = $"<p>Your updated comment on the event '{eventDetails.Name}' is now visible.</p>";

Expand Down Expand Up @@ -118,7 +118,7 @@ public async Task HandleAsync(CommentUpdated eventArgs, CancellationToken cancel
);

organizerNotifications.AddNotification(organizerNotification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var organizerNotificationDetailsHtml = $"<p>{commentDetails.StudentName} updated their comment on your event '{eventDetails.Name}': {commentDetails.CommentContext}</p>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public async Task HandleAsync(EventCreated eventCreated, CancellationToken cance
studentNotifications = new StudentNotifications(user.Id);
}


studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
userId: user.Id,
Expand All @@ -96,9 +100,6 @@ public async Task HandleAsync(EventCreated eventCreated, CancellationToken cance
);

await _messageBroker.PublishAsync(notificationCreatedEvent);

studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task HandleAsync(EventDeleted eventDeleted, CancellationToken cance


studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task HandleAsync(EventParticipantAdded eventArgs, CancellationToken


participantNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(participantNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(participantNotifications);



Expand Down Expand Up @@ -99,7 +99,7 @@ public async Task HandleAsync(EventParticipantAdded eventArgs, CancellationToken


organizerNotifications.AddNotification(organizerNotification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var organizerNotificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task HandleAsync(EventParticipantRemoved eventArgs, CancellationTok
);

participantNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(participantNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(participantNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task HandleAsync(FriendInvited @event, CancellationToken cancellati

var studentNotifications = await _studentNotificationsRepository.GetByStudentIdAsync(@event.InviteeId) ?? new StudentNotifications(@event.InviteeId);
studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task HandleAsync(FriendRequestSent @event, CancellationToken cancel

var studentNotifications = await _studentNotificationsRepository.GetByStudentIdAsync(@event.InviteeId) ?? new StudentNotifications(@event.InviteeId);
studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notification.NotificationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public PasswordResetTokenGeneratedHandler(
public async Task HandleAsync(PasswordResetTokenGenerated @event, CancellationToken cancellationToken)
{
var student = await _studentsServiceClient.GetAsync(@event.UserId);
var encodedToken = System.Net.WebUtility.UrlEncode(@event.ResetToken); // Encode the token
var resetLink = $"https://minispace.itsharppro.com/reset-password/{encodedToken}/page"; // Use the encoded token
var encodedToken = System.Net.WebUtility.UrlEncode(@event.ResetToken);
var resetLink = $"https://minispace.itsharppro.com/reset-password/{encodedToken}/page";
var notificationMessage = $"You have requested to reset your password. Please use the following link to proceed: {resetLink}";
var detailsHtml = $"<p>Click the following link to reset your password: <a href=\"{resetLink}\">Reset Password</a></p>";

Expand All @@ -48,7 +48,7 @@ public async Task HandleAsync(PasswordResetTokenGenerated @event, CancellationTo

var studentNotifications = await _studentNotificationsRepository.GetByStudentIdAsync(@event.UserId) ?? new StudentNotifications(@event.UserId);
studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notification.NotificationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private async Task NotifyStudent(StudentDto student, EventDto eventDetails, Post
}

studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down Expand Up @@ -146,7 +146,7 @@ private async Task NotifyOrganizer(OrganizerDto organizer, EventDto eventDetails
}

organizerNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private async Task NotifyStudent(StudentDto student, EventDto eventDetails, Post
}

studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: notification.NotificationId,
Expand Down Expand Up @@ -146,7 +146,7 @@ private async Task NotifyOrganizer(OrganizerDto organizer, EventDto eventDetails
}

organizerNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task HandleAsync(ReactionCreated eventArgs, CancellationToken cance
);

studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationDetailsHtml = $@"
<p>Thank you for your reaction! Your interaction helps us to better understand what content resonates with our community.</p>";
Expand Down Expand Up @@ -111,7 +111,7 @@ public async Task HandleAsync(ReactionCreated eventArgs, CancellationToken cance
);

organizerNotifications.AddNotification(organizerNotification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

await _messageBroker.PublishAsync(new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private async Task<Notification> CreateNotificationForUser(Guid userId, ReportCa
eventType: NotificationEventType.ReportCancelled
);
notifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(notifications);
await _studentNotificationsRepository.AddOrUpdateAsync(notifications);
return notification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async Task<Notification> CreateNotificationForUser(Guid userId, ReportCr
eventType: NotificationEventType.ReportCreated
);
notifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(notifications);
await _studentNotificationsRepository.AddOrUpdateAsync(notifications);
return notification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private async Task<Notification> CreateNotificationForUser(Guid userId, ReportDe
eventType: NotificationEventType.ReportDeleted
);
notifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(notifications);
await _studentNotificationsRepository.AddOrUpdateAsync(notifications);
return notification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private async Task<Notification> CreateNotificationForUser(Guid userId, ReportRe
eventType: NotificationEventType.ReportRejected
);
notifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(notifications);
await _studentNotificationsRepository.AddOrUpdateAsync(notifications);
return notification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private async Task<Notification> CreateNotificationForUser(Guid userId, ReportRe
eventType: NotificationEventType.ReportResolved
);
notifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(notifications);
await _studentNotificationsRepository.AddOrUpdateAsync(notifications);
return notification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private async Task<Notification> CreateNotificationForUser(Guid userId, ReportRe
eventType: NotificationEventType.ReportReviewStarted
);
notifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(notifications);
await _studentNotificationsRepository.AddOrUpdateAsync(notifications);
return notification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task HandleAsync(SignedUp @event, CancellationToken cancellationTok
);

userNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(userNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(userNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task HandleAsync(StudentCancelledInterestInEvent eventArgs, Cancell


studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task HandleAsync(StudentCancelledSignUpToEvent eventArgs, Cancellat
);

studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down Expand Up @@ -96,7 +96,7 @@ public async Task HandleAsync(StudentCancelledSignUpToEvent eventArgs, Cancellat


organizerNotifications.AddNotification(organizerNotification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var organizerNotificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task HandleAsync(StudentShowedInterestInEvent eventArgs, Cancellati
);

studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task HandleAsync(StudentShowedInterestInEvent eventArgs, Cancellati
}

organizerNotifications.AddNotification(organizerNotification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var organizerNotificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task HandleAsync(StudentSignedUpToEvent eventArgs, CancellationToke
);

studentNotifications.AddNotification(notification);
await _studentNotificationsRepository.UpdateAsync(studentNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(studentNotifications);

var notificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down Expand Up @@ -94,7 +94,7 @@ public async Task HandleAsync(StudentSignedUpToEvent eventArgs, CancellationToke
}

organizerNotifications.AddNotification(organizerNotification);
await _studentNotificationsRepository.UpdateAsync(organizerNotifications);
await _studentNotificationsRepository.AddOrUpdateAsync(organizerNotifications);

var organizerNotificationCreatedEvent = new NotificationCreated(
notificationId: Guid.NewGuid(),
Expand Down
Loading