Правка типов дат с DateTime на DateTimeOffset в Notification и NotificationDto

This commit is contained in:
Olga Nemt 2024-03-20 16:29:25 +05:00
parent 0df79ee0fc
commit ec2abd224e
9 changed files with 23 additions and 23 deletions

View File

@ -42,17 +42,17 @@ public class NotificationDto : IId
/// Дата регистрации уведомления /// Дата регистрации уведомления
/// </summary> /// </summary>
[Required] [Required]
public DateTime RegistrationDate { get; set; } public DateTimeOffset RegistrationDate { get; set; }
/// <summary> /// <summary>
/// Дата отправки уведомления /// Дата отправки уведомления
/// </summary> /// </summary>
public DateTime? SentDate { get; set; } public DateTimeOffset? SentDate { get; set; }
/// <summary> /// <summary>
/// Дата прочтения уведомления /// Дата прочтения уведомления
/// </summary> /// </summary>
public DateTime? ReadDate { get; set; } public DateTimeOffset? ReadDate { get; set; }
/// <summary> /// <summary>
/// Состояние уведомления /// Состояние уведомления
@ -82,12 +82,12 @@ public class NotificationDto : IId
ReadDate = null; ReadDate = null;
break; break;
case 1: case 1:
SentDate = DateTime.UtcNow; SentDate = DateTimeOffset.UtcNow;
ReadDate = null; ReadDate = null;
break; break;
case 2: case 2:
SentDate = DateTime.UtcNow; SentDate = DateTimeOffset.UtcNow;
ReadDate = DateTime.UtcNow; ReadDate = DateTimeOffset.UtcNow;
break; break;
} }
} }

View File

@ -15,10 +15,10 @@ public class NotificationDeleteRequest
/// <summary> /// <summary>
/// Меньше или равно дате отправки /// Меньше или равно дате отправки
/// </summary> /// </summary>
public DateTime? LtSentDate { get; set; } public DateTimeOffset? LtSentDate { get; set; }
/// <summary> /// <summary>
/// Меньше или равно дате прочтения /// Меньше или равно дате прочтения
/// </summary> /// </summary>
public DateTime? LtReadDate { get; set; } public DateTimeOffset? LtReadDate { get; set; }
} }

View File

@ -49,7 +49,7 @@ public class NotificationService
var notification = new NotificationDto var notification = new NotificationDto
{ {
IdUser = request.IdUser, IdUser = request.IdUser,
RegistrationDate = DateTime.UtcNow, RegistrationDate = DateTimeOffset.UtcNow,
IdNotificationCategory = notificationCategory.Id, IdNotificationCategory = notificationCategory.Id,
Title = request.Title, Title = request.Title,
Message = request.Message, Message = request.Message,
@ -71,7 +71,7 @@ public class NotificationService
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
} }
notification.SentDate = DateTime.UtcNow; notification.SentDate = DateTimeOffset.UtcNow;
await notificationRepository.UpdateAsync(notification, cancellationToken); await notificationRepository.UpdateAsync(notification, cancellationToken);
} }
@ -92,7 +92,7 @@ public class NotificationService
if(isRead && !notification.SentDate.HasValue) if(isRead && !notification.SentDate.HasValue)
throw new ArgumentInvalidException(nameof(isRead), "Уведомление не может быть прочитано"); throw new ArgumentInvalidException(nameof(isRead), "Уведомление не может быть прочитано");
notification.ReadDate = isRead ? DateTime.UtcNow : null; notification.ReadDate = isRead ? DateTimeOffset.UtcNow : null;
await notificationRepository.UpdateAsync(notification, await notificationRepository.UpdateAsync(notification,
cancellationToken); cancellationToken);
@ -119,7 +119,7 @@ public class NotificationService
var tasks = notifications.Select(notification => var tasks = notifications.Select(notification =>
{ {
notification.SentDate = DateTime.UtcNow; notification.SentDate = DateTimeOffset.UtcNow;
return notificationRepository.UpdateAsync(notification, cancellationToken); return notificationRepository.UpdateAsync(notification, cancellationToken);
}); });

View File

@ -1581,17 +1581,17 @@ namespace AsbCloudDb.Migrations
.HasColumnName("message") .HasColumnName("message")
.HasComment("Сообщение уведомления"); .HasComment("Сообщение уведомления");
b.Property<DateTime?>("ReadDate") b.Property<DateTimeOffset?>("ReadDate")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("read_date") .HasColumnName("read_date")
.HasComment("Дата прочтения уведомления"); .HasComment("Дата прочтения уведомления");
b.Property<DateTime>("RegistrationDate") b.Property<DateTimeOffset>("RegistrationDate")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("registration_date") .HasColumnName("registration_date")
.HasComment("Дата регистрации уведомления"); .HasComment("Дата регистрации уведомления");
b.Property<DateTime?>("SentDate") b.Property<DateTimeOffset?>("SentDate")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("sent_date") .HasColumnName("sent_date")
.HasComment("Дата отправки уведомления"); .HasComment("Дата отправки уведомления");

View File

@ -25,13 +25,13 @@ public class Notification : IId
public string Message { get; set; } = null!; public string Message { get; set; } = null!;
[Column("registration_date"), Comment("Дата регистрации уведомления")] [Column("registration_date"), Comment("Дата регистрации уведомления")]
public DateTime RegistrationDate { get; set; } public DateTimeOffset RegistrationDate { get; set; }
[Column("sent_date"), Comment("Дата отправки уведомления")] [Column("sent_date"), Comment("Дата отправки уведомления")]
public DateTime? SentDate { get; set; } public DateTimeOffset? SentDate { get; set; }
[Column("read_date"), Comment("Дата прочтения уведомления")] [Column("read_date"), Comment("Дата прочтения уведомления")]
public DateTime? ReadDate { get; set; } public DateTimeOffset? ReadDate { get; set; }
[Column("id_transport_type"), Comment("Id типа доставки уведомления")] [Column("id_transport_type"), Comment("Id типа доставки уведомления")]
public int IdTransportType { get; set; } public int IdTransportType { get; set; }

View File

@ -27,7 +27,7 @@ namespace AsbCloudInfrastructure.Background
await notificationService.SendAsync(notification, token); await notificationService.SendAsync(notification, token);
notification.SentDate = DateTime.UtcNow; notification.SentDate = DateTimeOffset.UtcNow;
await notificationRepository.UpdateAsync(notification, token); await notificationRepository.UpdateAsync(notification, token);
} }

View File

@ -110,10 +110,10 @@ public class NotificationRepository : CrudRepositoryBase<NotificationDto, Notifi
query = query.Where(n => n.IdNotificationCategory == request.IdCategory.Value); query = query.Where(n => n.IdNotificationCategory == request.IdCategory.Value);
if (request.LtSentDate.HasValue) 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) 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); dbContext.Notifications.RemoveRange(query);

View File

@ -26,7 +26,7 @@ namespace AsbCloudWebApi.Tests.Services.Notification
IdUser = 1, IdUser = 1,
IdTransportType = 1, IdTransportType = 1,
IdState = 0, IdState = 0,
RegistrationDate = DateTime.Now, RegistrationDate = DateTimeOffset.Now,
IdNotificationCategory = 10000, IdNotificationCategory = 10000,
}; };
private readonly UserExtendedDto user = new UserExtendedDto() private readonly UserExtendedDto user = new UserExtendedDto()

View File

@ -35,7 +35,7 @@ public class NotificationPublisher
{ {
foreach (var notification in groupedNotifications) foreach (var notification in groupedNotifications)
{ {
notification.SentDate = DateTime.UtcNow; notification.SentDate = DateTimeOffset.UtcNow;
} }
var notifications = groupedNotifications.Select(n => n); var notifications = groupedNotifications.Select(n => n);