Исправления

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" /> <EditorConfigFiles Remove="D:\Source\AsbCloudApp\Services\.editorconfig" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AsbCloudDb\AsbCloudDb.csproj" />
</ItemGroup>
</Project> </Project>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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