Исправления

1. Удалил зависимость от AsbCloudDb в проекте AsbCloudApp
2. Убрал лишние константы
3. Сделал реализацию для IdState у NotificationDto
4. Удалил атрибут Range у IdTransportType. Проверка на существование сервиса транспорта находится в методе GetTransportService в NotificationService
This commit is contained in:
parent 4511eb239f
commit 55ca21c31e
8 changed files with 25 additions and 19 deletions

View File

@ -18,8 +18,4 @@
<EditorConfigFiles Remove="D:\Source\AsbCloudApp\Services\.editorconfig" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AsbCloudDb\AsbCloudDb.csproj" />
</ItemGroup>
</Project>

View File

@ -67,7 +67,21 @@ public class NotificationDto : IId
}
set
{
switch (value)
{
case 0:
SentDate = null;
ReadDate = null;
break;
case 1:
SentDate = DateTime.UtcNow;
ReadDate = null;
break;
case 2:
SentDate = DateTime.UtcNow;
ReadDate = DateTime.UtcNow;
break;
}
}
}

View File

@ -36,6 +36,5 @@ public class NotifyRequest
/// Id типа доставки уведомления. Допустимое значение: 0, 1
/// </summary>
[Required]
[Range(minimum: 0, maximum: 1, ErrorMessage = "Id способа отправки уведомления недоступно. Допустимые: 0, 1")]
public int IdTransportType { get; set; }
}

View File

@ -7,7 +7,6 @@ using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudDb.Model;
namespace AsbCloudApp.Services.Notifications;
@ -96,11 +95,13 @@ public class NotificationService
/// <returns></returns>
public async Task RenotifyAsync(int idUser, CancellationToken cancellationToken)
{
const int idTransportType = 0;
var notifications = await notificationRepository.GetAllAsync(idUser, false,
Notification.IdTransportTypeSignalR,
idTransportType,
cancellationToken);
var notificationTransportService = GetTransportService(Notification.IdTransportTypeSignalR);
var notificationTransportService = GetTransportService(idTransportType);
await notificationTransportService.SendRangeAsync(notifications,
cancellationToken);

View File

@ -8,9 +8,6 @@ namespace AsbCloudDb.Model;
[Table("t_notification"), Comment("Уведомления")]
public class Notification : IId
{
public const int IdTransportTypeSignalR = 0;
public const int IdTransportTypeTypeEmail = 1;
[Key]
[Column("id")]
public int Id { get; set; }

View File

@ -9,7 +9,6 @@ using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services.Notifications;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Background;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -41,7 +40,7 @@ namespace AsbCloudInfrastructure.Services.Email
this.backgroundWorker = backgroundWorker;
}
public int IdTransportType => Notification.IdTransportTypeTypeEmail;
public int IdTransportType => 1;
public Task SendAsync(NotificationDto notification, CancellationToken cancellationToken)
{

View File

@ -4,7 +4,6 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudDb.Model;
using AsbCloudWebApi.SignalR.Messages;
using Microsoft.AspNetCore.SignalR;
@ -27,6 +26,8 @@ public class NotificationPublisher
public async Task PublishAsync(IGrouping<int, NotificationDto> groupedNotifications, CancellationToken cancellationToken)
{
const int idTransportType = 0;
var connectionId = connectionManagerService.GetConnectionIdByUserId(groupedNotifications.Key);
if (!string.IsNullOrWhiteSpace(connectionId))
@ -44,8 +45,8 @@ public class NotificationPublisher
await PublishMessageAsync(connectionId, new NotificationMessage
{
Notifications = notifications,
CountUnread = await notificationRepository.GetUnreadCountAsync(groupedNotifications.Key,
Notification.IdTransportTypeSignalR,
CountUnread = await notificationRepository.GetUnreadCountAsync(groupedNotifications.Key,
idTransportType,
cancellationToken)
}, cancellationToken);
}

View File

@ -5,7 +5,6 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Services.Notifications;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Background;
using Microsoft.Extensions.DependencyInjection;
@ -20,7 +19,7 @@ public class SignalRNotificationTransportService : INotificationTransportService
this.backgroundWorker = backgroundWorker;
}
public int IdTransportType => Notification.IdTransportTypeSignalR;
public int IdTransportType => 0;
public Task SendAsync(NotificationDto notification,
CancellationToken cancellationToken) => SendRangeAsync(new[] { notification }, cancellationToken);