Skip to content

Commit

Permalink
[Notification][Hai] read notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
HaiHungNguyenn committed Mar 17, 2024
1 parent 7e4839b commit aa12273
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Domus.Api/Controllers/NotificationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public async Task<IActionResult> SearchPackagesUsingGetRequest([FromQuery] Searc
).ConfigureAwait(false);
}

[HttpPut]
public async Task<IActionResult> SeenAllNotification()
{
return await ExecuteServiceLogic(async () => await _notificationService.UpdateNotificationStatus(GetJwtToken()).ConfigureAwait(false)).ConfigureAwait(false);
}

}
9 changes: 8 additions & 1 deletion Domus.Service/Implementations/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,21 @@ public async Task<ServiceActionResult> GetNotification(string token)
};
}

public async Task UpdateNotificationStatus(IQueryable<Notification> notifications)
public async Task<ServiceActionResult> UpdateNotificationStatus(string token)
{
var isValidToken = _jwtService.IsValidToken(token);
if (!isValidToken)
throw new InvalidTokenException();
var userId = _jwtService.GetTokenClaim(token, TokenClaimConstants.SUBJECT)?.ToString() ?? throw new UserNotFoundException();
var notifications = await _notificationRepository.FindAsync(x => x.RecipientId == userId);

foreach (var notification in notifications)
{
notification.Status = NotificationStatus.Read;
}
await _notificationRepository.UpdateManyAsync(notifications);
await _unitOfWork.CommitAsync();
return new ServiceActionResult(true);
}

public async Task<ServiceActionResult> SearchNotificationsUsingGet(SearchUsingGetRequest request,string token)
Expand Down
2 changes: 1 addition & 1 deletion Domus.Service/Interfaces/INotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface INotificationService : IAutoRegisterable
{
Task CreateNotification(Notification notification);
Task<ServiceActionResult> GetNotification(string token);
Task UpdateNotificationStatus(IQueryable<Notification> notifications);
Task<ServiceActionResult> UpdateNotificationStatus(string token);

Task<ServiceActionResult> SearchNotificationsUsingGet(SearchUsingGetRequest request,string token);
}

0 comments on commit aa12273

Please sign in to comment.