forked from ddrilling/AsbCloudServer
Добавлен idTransportType для расчета количества непрочтенных уведомлений
This commit is contained in:
parent
cbca56ca28
commit
b75dbd365b
@ -35,8 +35,8 @@ public interface INotificationRepository : ICrudRepository<NotificationDto>
|
||||
/// Получение количества непрочтенных уведомлений
|
||||
/// </summary>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="idTransportType"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> GetUnreadCountAsync(int idUser,
|
||||
CancellationToken cancellationToken);
|
||||
Task<int> GetUnreadCountAsync(int idUser, int idTransportType, CancellationToken cancellationToken);
|
||||
}
|
@ -72,11 +72,12 @@ public class NotificationRepository : CrudRepositoryBase<NotificationDto, Notifi
|
||||
return dbContext.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<int> GetUnreadCountAsync(int idUser, CancellationToken cancellationToken)
|
||||
public async Task<int> GetUnreadCountAsync(int idUser, int idTransportType, CancellationToken cancellationToken)
|
||||
{
|
||||
var count = await dbContext.Notifications
|
||||
.Where(n => n.ReadDate == null)
|
||||
.Where(n => n.IdUser == idUser)
|
||||
.Where(n => n.IdTransportType == idTransportType)
|
||||
.CountAsync(cancellationToken);
|
||||
|
||||
return count;
|
||||
|
@ -128,19 +128,20 @@ public class NotificationController : ControllerBase
|
||||
/// <summary>
|
||||
/// Получение количества непрочитанных уведомлений
|
||||
/// </summary>
|
||||
/// <param name="idTransportType"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("unreadNotificationCount")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetUnreadCountAsync(CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> GetUnreadCountAsync([FromQuery] int idTransportType, CancellationToken cancellationToken)
|
||||
{
|
||||
int? idUser = User.GetUserId();
|
||||
|
||||
if (!idUser.HasValue)
|
||||
return Forbid();
|
||||
|
||||
var result = await notificationRepository.GetUnreadCountAsync(idUser.Value, cancellationToken);
|
||||
var result = await notificationRepository.GetUnreadCountAsync(idUser.Value, idTransportType, cancellationToken);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user