From 55ca21c31eb6a615a476fcdcfc09b5167f2ce17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Thu, 14 Sep 2023 17:17:35 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Удалил зависимость от AsbCloudDb в проекте AsbCloudApp 2. Убрал лишние константы 3. Сделал реализацию для IdState у NotificationDto 4. Удалил атрибут Range у IdTransportType. Проверка на существование сервиса транспорта находится в методе GetTransportService в NotificationService --- AsbCloudApp/AsbCloudApp.csproj | 4 ---- AsbCloudApp/Data/NotificationDto.cs | 16 +++++++++++++++- AsbCloudApp/Requests/NotifyRequest.cs | 1 - .../Notifications/NotificationService.cs | 7 ++++--- AsbCloudDb/Model/Notification.cs | 3 --- .../Email/EmailNotificationTransportService.cs | 3 +-- .../SignalR/Services/NotificationPublisher.cs | 7 ++++--- .../SignalRNotificationTransportService.cs | 3 +-- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/AsbCloudApp/AsbCloudApp.csproj b/AsbCloudApp/AsbCloudApp.csproj index 512a0c0a..79ec9867 100644 --- a/AsbCloudApp/AsbCloudApp.csproj +++ b/AsbCloudApp/AsbCloudApp.csproj @@ -18,8 +18,4 @@ - - - - diff --git a/AsbCloudApp/Data/NotificationDto.cs b/AsbCloudApp/Data/NotificationDto.cs index d067a633..06fbc189 100644 --- a/AsbCloudApp/Data/NotificationDto.cs +++ b/AsbCloudApp/Data/NotificationDto.cs @@ -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; + } } } diff --git a/AsbCloudApp/Requests/NotifyRequest.cs b/AsbCloudApp/Requests/NotifyRequest.cs index fc6df840..fdd4a1e5 100644 --- a/AsbCloudApp/Requests/NotifyRequest.cs +++ b/AsbCloudApp/Requests/NotifyRequest.cs @@ -36,6 +36,5 @@ public class NotifyRequest /// Id типа доставки уведомления. Допустимое значение: 0, 1 /// [Required] - [Range(minimum: 0, maximum: 1, ErrorMessage = "Id способа отправки уведомления недоступно. Допустимые: 0, 1")] public int IdTransportType { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Services/Notifications/NotificationService.cs b/AsbCloudApp/Services/Notifications/NotificationService.cs index b8916b15..901a5348 100644 --- a/AsbCloudApp/Services/Notifications/NotificationService.cs +++ b/AsbCloudApp/Services/Notifications/NotificationService.cs @@ -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 /// 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); diff --git a/AsbCloudDb/Model/Notification.cs b/AsbCloudDb/Model/Notification.cs index e363d3d2..09f718b1 100644 --- a/AsbCloudDb/Model/Notification.cs +++ b/AsbCloudDb/Model/Notification.cs @@ -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; } diff --git a/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs b/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs index 4211c73e..e0f4ba0e 100644 --- a/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs +++ b/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs @@ -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) { diff --git a/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs b/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs index 5c1d1e50..1f6f4f67 100644 --- a/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs +++ b/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs @@ -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 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); } diff --git a/AsbCloudWebApi/SignalR/Services/SignalRNotificationTransportService.cs b/AsbCloudWebApi/SignalR/Services/SignalRNotificationTransportService.cs index 08258bef..b418c0b5 100644 --- a/AsbCloudWebApi/SignalR/Services/SignalRNotificationTransportService.cs +++ b/AsbCloudWebApi/SignalR/Services/SignalRNotificationTransportService.cs @@ -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);