diff --git a/RMuseum/Controllers/NoificationController.cs b/RMuseum/Controllers/NoificationController.cs index f64ab32b..83506939 100644 --- a/RMuseum/Controllers/NoificationController.cs +++ b/RMuseum/Controllers/NoificationController.cs @@ -119,6 +119,23 @@ namespace RMuseum.Controllers return Ok(); } + /// + /// Delete All Read Notifications + /// + /// + [HttpDelete] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task DeleteAllReadNotification() + { + Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + RServiceResult res = await _notificationService.DeleteNotification(Guid.Empty, loggedOnUserId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } + /// /// Notification Service /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index e18307e1..95e2bf5e 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -700,6 +700,12 @@ + + + Delete All Read Notifications + + + Notification Service @@ -5130,7 +5136,7 @@ Delete Notification - if empty deletes all + if empty deletes all read notifications @@ -5700,7 +5706,7 @@ Delete Notification - if empty deletes all + if empty deletes all read notifications diff --git a/RMuseum/Services/IRNotificationService.cs b/RMuseum/Services/IRNotificationService.cs index 7073a333..13a4b3bf 100644 --- a/RMuseum/Services/IRNotificationService.cs +++ b/RMuseum/Services/IRNotificationService.cs @@ -52,7 +52,7 @@ namespace RMuseum.Services /// /// Delete Notification /// - /// if empty deletes all + /// if empty deletes all read notifications /// /// Task> DeleteNotification(Guid notificationId, Guid userId); diff --git a/RMuseum/Services/Implementation/RNotificationService.cs b/RMuseum/Services/Implementation/RNotificationService.cs index 6957acb8..169550b8 100644 --- a/RMuseum/Services/Implementation/RNotificationService.cs +++ b/RMuseum/Services/Implementation/RNotificationService.cs @@ -96,7 +96,7 @@ namespace RMuseum.Services.Implementation /// /// Delete Notification /// - /// if empty deletes all + /// if empty deletes all read notifications /// /// public async Task> DeleteNotification(Guid notificationId, Guid userId) @@ -105,7 +105,7 @@ namespace RMuseum.Services.Implementation { if (notificationId == Guid.Empty) { - var notifications = await _context.Notifications.Where(n => n.UserId == userId).ToListAsync(); + var notifications = await _context.Notifications.Where(n => n.UserId == userId && n.Status == NotificationStatus.Read).ToListAsync(); _context.Notifications.RemoveRange(notifications); await _context.SaveChangesAsync(); }