diff --git a/AsbCloudApp/Repositories/INotificationRepository.cs b/AsbCloudApp/Repositories/INotificationRepository.cs index 0bbdffbd..d469b120 100644 --- a/AsbCloudApp/Repositories/INotificationRepository.cs +++ b/AsbCloudApp/Repositories/INotificationRepository.cs @@ -21,4 +21,13 @@ public interface INotificationRepository : ICrudRepository Task> GetNotificationsAsync(int idUser, NotificationRequest request, CancellationToken cancellationToken); + + /// + /// Удаление уведомлений по параметрам + /// + /// + /// + /// + Task DeleteAsync(NotificationDeleteRequest request, + CancellationToken cancellationToken); } \ No newline at end of file diff --git a/AsbCloudApp/Requests/NotificationDeleteRequest.cs b/AsbCloudApp/Requests/NotificationDeleteRequest.cs new file mode 100644 index 00000000..ec2026f3 --- /dev/null +++ b/AsbCloudApp/Requests/NotificationDeleteRequest.cs @@ -0,0 +1,24 @@ +using System; + +namespace AsbCloudApp.Requests; + +/// +/// Запрос для удаления уведомлений +/// +public class NotificationDeleteRequest +{ + /// + /// Идентификатор категории + /// + public int? IdCategory { get; set; } + + /// + /// Меньше или равно дате отправки + /// + public DateTime? LtSentDate { get; set; } + + /// + /// Меньше или равно дате прочтения + /// + public DateTime? LtReadDate { get; set; } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/NotificationRepository.cs b/AsbCloudInfrastructure/Repository/NotificationRepository.cs index c3302c95..fecbfa26 100644 --- a/AsbCloudInfrastructure/Repository/NotificationRepository.cs +++ b/AsbCloudInfrastructure/Repository/NotificationRepository.cs @@ -54,6 +54,24 @@ public class NotificationRepository : CrudRepositoryBase DeleteAsync(NotificationDeleteRequest request, CancellationToken cancellationToken) + { + var query = dbContext.Notifications.AsQueryable(); + + if (request.IdCategory.HasValue) + query = query.Where(n => n.IdNotificationCategory == request.IdCategory.Value); + + if (request.LtSentDate.HasValue) + query = query.Where(n => n.SentDate <= request.LtSentDate.Value); + + if (request.LtReadDate.HasValue) + query = query.Where(n => n.ReadDate <= request.LtReadDate.Value); + + dbContext.Notifications.RemoveRange(query); + + return dbContext.SaveChangesAsync(cancellationToken); + } + private IQueryable BuildQuery(int idUser, NotificationRequest request) { diff --git a/AsbCloudWebApi/Controllers/NotificationController.cs b/AsbCloudWebApi/Controllers/NotificationController.cs index 3646647d..066ddd99 100644 --- a/AsbCloudWebApi/Controllers/NotificationController.cs +++ b/AsbCloudWebApi/Controllers/NotificationController.cs @@ -36,7 +36,6 @@ public class NotificationController : ControllerBase /// /// [HttpPost] - [Route("send")] public async Task SendAsync(NotifyRequest request, CancellationToken cancellationToken) { await notificationService.NotifyAsync(request, cancellationToken); @@ -52,7 +51,6 @@ public class NotificationController : ControllerBase /// /// [HttpPut] - [Route("update")] public async Task UpdateAsync([Required] int idNotification, [Required] bool isRead, CancellationToken cancellationToken) @@ -71,7 +69,7 @@ public class NotificationController : ControllerBase /// /// [HttpGet] - [Route("get/{idNotification}")] + [Route("{idNotification}")] [ProducesResponseType(typeof(NotificationDto), (int)System.Net.HttpStatusCode.OK)] public async Task GetAsync([Required] int idNotification, CancellationToken cancellationToken) @@ -94,7 +92,6 @@ public class NotificationController : ControllerBase /// /// [HttpGet] - [Route("getList")] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] public async Task GetListAsync([FromQuery] NotificationRequest request, CancellationToken cancellationToken) @@ -118,7 +115,7 @@ public class NotificationController : ControllerBase /// /// [HttpDelete] - [Route("delete")] + [Route("{idNotification}")] public async Task DeleteAsync([Required] int idNotification, CancellationToken cancellationToken) { @@ -127,4 +124,19 @@ public class NotificationController : ControllerBase return Ok(); } + + /// + /// Удаление уведомлений + /// + /// Параметры запроса + /// + /// + [HttpDelete] + public async Task DeleteAsync(NotificationDeleteRequest request, + CancellationToken cancellationToken) + { + await notificationRepository.DeleteAsync(request, cancellationToken); + + return Ok(); + } } \ No newline at end of file