diff --git a/AsbCloudApp/Data/NotificationDto.cs b/AsbCloudApp/Data/NotificationDto.cs index ee42f8d7..0fd8b673 100644 --- a/AsbCloudApp/Data/NotificationDto.cs +++ b/AsbCloudApp/Data/NotificationDto.cs @@ -42,17 +42,17 @@ public class NotificationDto : IId /// Дата регистрации уведомления /// [Required] - public DateTime RegistrationDate { get; set; } + public DateTimeOffset RegistrationDate { get; set; } /// /// Дата отправки уведомления /// - public DateTime? SentDate { get; set; } + public DateTimeOffset? SentDate { get; set; } /// /// Дата прочтения уведомления /// - public DateTime? ReadDate { get; set; } + public DateTimeOffset? ReadDate { get; set; } /// /// Состояние уведомления @@ -82,12 +82,12 @@ public class NotificationDto : IId ReadDate = null; break; case 1: - SentDate = DateTime.UtcNow; + SentDate = DateTimeOffset.UtcNow; ReadDate = null; break; case 2: - SentDate = DateTime.UtcNow; - ReadDate = DateTime.UtcNow; + SentDate = DateTimeOffset.UtcNow; + ReadDate = DateTimeOffset.UtcNow; break; } } diff --git a/AsbCloudApp/Requests/NotificationDeleteRequest.cs b/AsbCloudApp/Requests/NotificationDeleteRequest.cs index ec2026f3..56921d70 100644 --- a/AsbCloudApp/Requests/NotificationDeleteRequest.cs +++ b/AsbCloudApp/Requests/NotificationDeleteRequest.cs @@ -15,10 +15,10 @@ public class NotificationDeleteRequest /// /// Меньше или равно дате отправки /// - public DateTime? LtSentDate { get; set; } + public DateTimeOffset? LtSentDate { get; set; } /// /// Меньше или равно дате прочтения /// - public DateTime? LtReadDate { get; set; } + public DateTimeOffset? LtReadDate { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Services/Notifications/NotificationService.cs b/AsbCloudApp/Services/Notifications/NotificationService.cs index d703ffb4..97b8bfb5 100644 --- a/AsbCloudApp/Services/Notifications/NotificationService.cs +++ b/AsbCloudApp/Services/Notifications/NotificationService.cs @@ -49,7 +49,7 @@ public class NotificationService var notification = new NotificationDto { IdUser = request.IdUser, - RegistrationDate = DateTime.UtcNow, + RegistrationDate = DateTimeOffset.UtcNow, IdNotificationCategory = notificationCategory.Id, Title = request.Title, Message = request.Message, @@ -71,7 +71,7 @@ public class NotificationService Console.WriteLine(ex.Message); } - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; await notificationRepository.UpdateAsync(notification, cancellationToken); } @@ -92,7 +92,7 @@ public class NotificationService if(isRead && !notification.SentDate.HasValue) throw new ArgumentInvalidException(nameof(isRead), "Уведомление не может быть прочитано"); - notification.ReadDate = isRead ? DateTime.UtcNow : null; + notification.ReadDate = isRead ? DateTimeOffset.UtcNow : null; await notificationRepository.UpdateAsync(notification, cancellationToken); @@ -119,7 +119,7 @@ public class NotificationService var tasks = notifications.Select(notification => { - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; return notificationRepository.UpdateAsync(notification, cancellationToken); }); diff --git a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs index 8bd03355..9c6590fb 100644 --- a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs +++ b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs @@ -1581,17 +1581,17 @@ namespace AsbCloudDb.Migrations .HasColumnName("message") .HasComment("Сообщение уведомления"); - b.Property("ReadDate") + b.Property("ReadDate") .HasColumnType("timestamp with time zone") .HasColumnName("read_date") .HasComment("Дата прочтения уведомления"); - b.Property("RegistrationDate") + b.Property("RegistrationDate") .HasColumnType("timestamp with time zone") .HasColumnName("registration_date") .HasComment("Дата регистрации уведомления"); - b.Property("SentDate") + b.Property("SentDate") .HasColumnType("timestamp with time zone") .HasColumnName("sent_date") .HasComment("Дата отправки уведомления"); diff --git a/AsbCloudDb/Model/Notification.cs b/AsbCloudDb/Model/Notification.cs index 09f718b1..bed84a2b 100644 --- a/AsbCloudDb/Model/Notification.cs +++ b/AsbCloudDb/Model/Notification.cs @@ -25,13 +25,13 @@ public class Notification : IId public string Message { get; set; } = null!; [Column("registration_date"), Comment("Дата регистрации уведомления")] - public DateTime RegistrationDate { get; set; } + public DateTimeOffset RegistrationDate { get; set; } [Column("sent_date"), Comment("Дата отправки уведомления")] - public DateTime? SentDate { get; set; } + public DateTimeOffset? SentDate { get; set; } [Column("read_date"), Comment("Дата прочтения уведомления")] - public DateTime? ReadDate { get; set; } + public DateTimeOffset? ReadDate { get; set; } [Column("id_transport_type"), Comment("Id типа доставки уведомления")] public int IdTransportType { get; set; } diff --git a/AsbCloudInfrastructure/Background/WorkToSendEmail.cs b/AsbCloudInfrastructure/Background/WorkToSendEmail.cs index 57605438..ef8048e9 100644 --- a/AsbCloudInfrastructure/Background/WorkToSendEmail.cs +++ b/AsbCloudInfrastructure/Background/WorkToSendEmail.cs @@ -27,7 +27,7 @@ namespace AsbCloudInfrastructure.Background await notificationService.SendAsync(notification, token); - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; await notificationRepository.UpdateAsync(notification, token); } diff --git a/AsbCloudInfrastructure/Repository/NotificationRepository.cs b/AsbCloudInfrastructure/Repository/NotificationRepository.cs index 6f1e4a98..7e184f02 100644 --- a/AsbCloudInfrastructure/Repository/NotificationRepository.cs +++ b/AsbCloudInfrastructure/Repository/NotificationRepository.cs @@ -110,10 +110,10 @@ public class NotificationRepository : CrudRepositoryBase n.IdNotificationCategory == request.IdCategory.Value); if (request.LtSentDate.HasValue) - query = query.Where(n => n.SentDate <= request.LtSentDate.Value); + query = query.Where(n => n.SentDate <= request.LtSentDate.Value.ToUniversalTime()); if (request.LtReadDate.HasValue) - query = query.Where(n => n.ReadDate <= request.LtReadDate.Value); + query = query.Where(n => n.ReadDate <= request.LtReadDate.Value.ToUniversalTime()); dbContext.Notifications.RemoveRange(query); diff --git a/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs b/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs index 724f1e7b..5b6bcb1d 100644 --- a/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs +++ b/AsbCloudWebApi.Tests/Services/Notification/EmailNotificationTransportServiceTests.cs @@ -26,7 +26,7 @@ namespace AsbCloudWebApi.Tests.Services.Notification IdUser = 1, IdTransportType = 1, IdState = 0, - RegistrationDate = DateTime.Now, + RegistrationDate = DateTimeOffset.Now, IdNotificationCategory = 10000, }; private readonly UserExtendedDto user = new UserExtendedDto() diff --git a/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs b/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs index 6799e71d..05c93a29 100644 --- a/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs +++ b/AsbCloudWebApi/SignalR/Services/NotificationPublisher.cs @@ -35,7 +35,7 @@ public class NotificationPublisher { foreach (var notification in groupedNotifications) { - notification.SentDate = DateTime.UtcNow; + notification.SentDate = DateTimeOffset.UtcNow; } var notifications = groupedNotifications.Select(n => n);