Добавлен idTransportType для расчета количества непрочтенных уведомлений

This commit is contained in:
Olga Nemt 2023-07-31 17:55:49 +05:00
parent cbca56ca28
commit b75dbd365b
3 changed files with 7 additions and 5 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}