forked from ddrilling/AsbCloudServer
Метод, отдающий количество непрочитанных уведомлений
This commit is contained in:
parent
bbc42208c2
commit
af0d6e2d30
@ -1,8 +1,8 @@
|
|||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories;
|
namespace AsbCloudApp.Repositories;
|
||||||
|
|
||||||
@ -21,4 +21,13 @@ public interface INotificationRepository : ICrudRepository<NotificationDto>
|
|||||||
Task<PaginationContainer<NotificationDto>> GetNotificationsAsync(int idUser,
|
Task<PaginationContainer<NotificationDto>> GetNotificationsAsync(int idUser,
|
||||||
NotificationRequest request,
|
NotificationRequest request,
|
||||||
CancellationToken cancellationToken);
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение количества непрочтенных уведомлений
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idUser"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> GetUnreadCountAsync(int idUser,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
}
|
}
|
@ -54,6 +54,17 @@ public class NotificationRepository : CrudRepositoryBase<NotificationDto, Notifi
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
private IQueryable<Notification> BuildQuery(int idUser,
|
private IQueryable<Notification> BuildQuery(int idUser,
|
||||||
NotificationRequest request)
|
NotificationRequest request)
|
||||||
{
|
{
|
||||||
|
@ -111,6 +111,26 @@ public class NotificationController : ControllerBase
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение количества непрочитанных уведомлений
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("unreadNotificationCount")]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetUnreadCountAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
int? idUser = User.GetUserId();
|
||||||
|
|
||||||
|
if (!idUser.HasValue)
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await notificationRepository.GetUnreadCountAsync(idUser.Value, cancellationToken);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление уведомления
|
/// Удаление уведомления
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user