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

(#266) hot fix notification service update #268

Merged
merged 4 commits into from
Jun 2, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ namespace MiniSpace.Services.Notifications.Infrastructure.Mongo.Documents
public class StudentNotificationsDocument : IIdentifiable<Guid>
{
[BsonId]
[BsonRepresentation(BsonType.String)]
public Guid Id { get; set; }

[BsonRepresentation(BsonType.String)]
public Guid Id { get; set; }
public Guid StudentId { get; set; }
public List<NotificationDocument> Notifications { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public async Task AddOrUpdateAsync(StudentNotifications studentNotifications)
var document = studentNotifications.AsDocument();
var filter = Builders<StudentNotificationsDocument>.Filter.Eq(doc => doc.StudentId, studentNotifications.StudentId);

// Ensure the document is initialized with an empty list if not present
var initializationUpdate = Builders<StudentNotificationsDocument>.Update
.SetOnInsert(doc => doc.Notifications, new List<NotificationDocument>());
.SetOnInsert(doc => doc.Notifications, new List<NotificationDocument>())
.SetOnInsert(doc => doc.Id, document.Id);

var addToSetUpdates = new List<UpdateDefinition<StudentNotificationsDocument>>();
foreach (var notification in studentNotifications.Notifications)
Expand All @@ -86,10 +86,9 @@ public async Task AddOrUpdateAsync(StudentNotifications studentNotifications)
}

var options = new UpdateOptions { IsUpsert = true };
// Initialize document if it doesn't exist

await _repository.Collection.UpdateOneAsync(filter, initializationUpdate, options);

// Apply each AddToSet operation
foreach (var update in addToSetUpdates)
{
await _repository.Collection.UpdateOneAsync(filter, update, options);
Expand All @@ -98,6 +97,7 @@ public async Task AddOrUpdateAsync(StudentNotifications studentNotifications)




public async Task<List<StudentNotifications>> FindAsync(FilterDefinition<StudentNotificationsDocument> filter, FindOptions options)
{
var documents = await _repository.Collection.Find(filter, options).ToListAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static string GetNotificationLink(NotificationDto notification)
case NotificationEventType.ReportRejected:
case NotificationEventType.ReportResolved:
case NotificationEventType.ReportReviewStarted:
return $"/reports/{notification.RelatedEntityId}";
// return $"/reports/{notification.RelatedEntityId}";

default:
return $"/student-details/{notification.RelatedEntityId}";
Expand Down
Loading