forked from ddrilling/AsbCloudServer
Сделал рефакторинг уведомлений
1. Убрал глаголы из Route в контроллере. 2. Создал метод удаления уведомлений по параметрам
This commit is contained in:
parent
bbc42208c2
commit
3ac3fded5b
@ -21,4 +21,13 @@ public interface INotificationRepository : ICrudRepository<NotificationDto>
|
||||
Task<PaginationContainer<NotificationDto>> GetNotificationsAsync(int idUser,
|
||||
NotificationRequest request,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление уведомлений по параметрам
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> DeleteAsync(NotificationDeleteRequest request,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
24
AsbCloudApp/Requests/NotificationDeleteRequest.cs
Normal file
24
AsbCloudApp/Requests/NotificationDeleteRequest.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Requests;
|
||||
|
||||
/// <summary>
|
||||
/// Запрос для удаления уведомлений
|
||||
/// </summary>
|
||||
public class NotificationDeleteRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор категории
|
||||
/// </summary>
|
||||
public int? IdCategory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Меньше или равно дате отправки
|
||||
/// </summary>
|
||||
public DateTime? LtSentDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Меньше или равно дате прочтения
|
||||
/// </summary>
|
||||
public DateTime? LtReadDate { get; set; }
|
||||
}
|
@ -54,6 +54,24 @@ public class NotificationRepository : CrudRepositoryBase<NotificationDto, Notifi
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<int> 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<Notification> BuildQuery(int idUser,
|
||||
NotificationRequest request)
|
||||
{
|
||||
|
@ -36,7 +36,6 @@ public class NotificationController : ControllerBase
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("send")]
|
||||
public async Task<IActionResult> SendAsync(NotifyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
await notificationService.NotifyAsync(request, cancellationToken);
|
||||
@ -52,7 +51,6 @@ public class NotificationController : ControllerBase
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Route("update")]
|
||||
public async Task<IActionResult> UpdateAsync([Required] int idNotification,
|
||||
[Required] bool isRead,
|
||||
CancellationToken cancellationToken)
|
||||
@ -71,7 +69,7 @@ public class NotificationController : ControllerBase
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("get/{idNotification}")]
|
||||
[Route("{idNotification}")]
|
||||
[ProducesResponseType(typeof(NotificationDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetAsync([Required] int idNotification,
|
||||
CancellationToken cancellationToken)
|
||||
@ -94,7 +92,6 @@ public class NotificationController : ControllerBase
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("getList")]
|
||||
[ProducesResponseType(typeof(PaginationContainer<NotificationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetListAsync([FromQuery] NotificationRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
@ -118,7 +115,7 @@ public class NotificationController : ControllerBase
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[Route("delete")]
|
||||
[Route("{idNotification}")]
|
||||
public async Task<IActionResult> DeleteAsync([Required] int idNotification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
@ -127,4 +124,19 @@ public class NotificationController : ControllerBase
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление уведомлений
|
||||
/// </summary>
|
||||
/// <param name="request">Параметры запроса</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
public async Task<IActionResult> DeleteAsync(NotificationDeleteRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await notificationRepository.DeleteAsync(request, cancellationToken);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user