forked from ddrilling/AsbCloudServer
разрешение конфликтов
This commit is contained in:
commit
83beaada3d
@ -11,16 +11,25 @@ namespace AsbCloudApp.Repositories;
|
||||
/// </summary>
|
||||
public interface INotificationRepository : ICrudRepository<NotificationDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение уведомлений по параметрам
|
||||
/// </summary>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<PaginationContainer<NotificationDto>> GetNotificationsAsync(int idUser,
|
||||
NotificationRequest request,
|
||||
CancellationToken cancellationToken);
|
||||
/// <summary>
|
||||
/// Получение уведомлений по параметрам
|
||||
/// </summary>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Получение количества непрочтенных уведомлений
|
||||
|
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,15 +54,32 @@ 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);
|
||||
}
|
||||
|
||||
public async Task<int> GetUnreadCountAsync(int idUser, CancellationToken cancellationToken)
|
||||
{
|
||||
var count = await dbContext.Notifications
|
||||
.Where(n => n.ReadDate == null)
|
||||
.Where(n => n.IdUser == idUser)
|
||||
.CountAsync(cancellationToken);
|
||||
var count = await dbContext.Notifications
|
||||
.Where(n => n.ReadDate == null)
|
||||
.Where(n => n.IdUser == idUser)
|
||||
.CountAsync(cancellationToken);
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
||||
private IQueryable<Notification> BuildQuery(int idUser,
|
||||
|
@ -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)
|
||||
@ -111,6 +108,23 @@ public class NotificationController : ControllerBase
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление уведомления
|
||||
/// </summary>
|
||||
/// <param name="idNotification">Id уведомления</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[Route("{idNotification}")]
|
||||
public async Task<IActionResult> DeleteAsync([Required] int idNotification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await notificationRepository.DeleteAsync(idNotification,
|
||||
cancellationToken);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение количества непрочитанных уведомлений
|
||||
/// </summary>
|
||||
@ -118,7 +132,7 @@ public class NotificationController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("unreadNotificationCount")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetUnreadCountAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
int? idUser = User.GetUserId();
|
||||
@ -132,18 +146,16 @@ public class NotificationController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление уведомления
|
||||
/// Удаление уведомлений
|
||||
/// </summary>
|
||||
/// <param name="idNotification">Id уведомления</param>
|
||||
/// <param name="request">Параметры запроса</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[Route("delete")]
|
||||
public async Task<IActionResult> DeleteAsync([Required] int idNotification,
|
||||
public async Task<IActionResult> DeleteAsync(NotificationDeleteRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await notificationRepository.DeleteAsync(idNotification,
|
||||
cancellationToken);
|
||||
await notificationRepository.DeleteAsync(request, cancellationToken);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user