From 7cf21212e02320bd97f24438a24e7f481c77589f Mon Sep 17 00:00:00 2001 From: Andreas Hammerbeck Date: Tue, 4 Jun 2024 14:54:46 +0200 Subject: [PATCH] cleanup warnings (#97) Co-authored-by: Hammerbeck --- .../Controllers/CorrespondenceController.cs | 2 +- .../Controllers/HealthController.cs | 2 +- .../Mappers/AttachmentDetailsMapper.cs | 2 +- .../Mappers/AttachmentOverviewMapper.cs | 2 +- .../CorrespondenceNotificationMapper.cs | 11 +++---- .../Mappers/InitializeCorrespondenceMapper.cs | 5 +-- .../Models/AttachmentDetailsExt.cs | 2 +- .../Models/AttachmentOverviewExt.cs | 6 ++-- .../Models/CorrespondenceContentExt.cs | 2 +- .../Models/CorrespondenceDetailsExt.cs | 6 ++-- .../CorrespondenceNotificationDetailsExt.cs | 6 ++-- .../Models/CorrespondenceOverviewExt.cs | 2 +- .../Models/CorrespondenceReplyOptionExt.cs | 4 +-- .../InitializeCorrespondenceContentExt.cs | 10 +++--- .../Models/InitializeCorrespondenceExt.cs | 8 ++--- ...InitializeCorrespondenceNotificationExt.cs | 2 +- .../Models/MD5ChecksumAttribute.cs | 2 +- .../Models/NotificationStatusEventExt.cs | 8 ++--- .../GetAttachmentDetailsCommandHandler.cs | 6 ++-- .../GetAttachmentDetailsCommandResponse.cs | 6 ++-- .../GetAttachmentOverviewCommandHandler.cs | 8 ++--- .../GetAttachmentOverviewCommandResponse.cs | 6 ++-- .../GetCorrespondenceDetailsCommandHandler.cs | 14 ++++---- ...GetCorrespondenceDetailsCommandResponse.cs | 6 ++-- ...GetCorrespondenceOverviewCommandHandler.cs | 18 ++++++---- ...etCorrespondenceOverviewCommandResponse.cs | 6 ++-- .../InitializeAttachmentCommandRequest.cs | 2 +- .../InitializeCorrespondenceCommandHandler.cs | 33 ++++++++++++++++--- .../InitializeCorrespondenceCommandRequest.cs | 2 +- ...InitializeCorrespondenceCommandResponse.cs | 2 +- .../Models/AttachmentEntity.cs | 4 +-- .../Models/AttachmentStatusEntity.cs | 2 +- .../Models/CorrespondenceAttachmentEntity.cs | 4 +-- .../Models/CorrespondenceContentEntity.cs | 10 +++--- .../Models/CorrespondenceEntity.cs | 10 +++--- .../CorrespondenceNotificationEntity.cs | 4 +-- .../CorrespondenceNotificationStatusEntity.cs | 6 ++-- .../CorrespondenceReplyOptionsEntity.cs | 6 ++-- .../Models/CorrespondenceStatusEntity.cs | 2 +- .../Models/ExternalReferenceEntity.cs | 2 +- .../IAttachmentStatusRepository.cs | 2 +- .../ICorrespondenceStatusRepository.cs | 2 +- .../AttachmentStatusRepository.cs | 4 +-- .../Repositories/CorrespondenceRepository.cs | 4 +-- .../CorrespondenceStatusRepository.cs | 4 +-- 45 files changed, 141 insertions(+), 116 deletions(-) diff --git a/src/Altinn.Correspondence.API/Controllers/CorrespondenceController.cs b/src/Altinn.Correspondence.API/Controllers/CorrespondenceController.cs index 20e5b319..74124231 100644 --- a/src/Altinn.Correspondence.API/Controllers/CorrespondenceController.cs +++ b/src/Altinn.Correspondence.API/Controllers/CorrespondenceController.cs @@ -72,7 +72,7 @@ public async Task> InitializeCorresponde { CorrespondenceId = Guid.NewGuid(), Recipient = initializeCorrespondence.Recipient, - Content = (CorrespondenceContentExt)initializeCorrespondence.Content, + Content = initializeCorrespondence.Content != null ? (CorrespondenceContentExt)initializeCorrespondence.Content : null, ResourceId = initializeCorrespondence.ResourceId, Sender = initializeCorrespondence.Sender, SendersReference = initializeCorrespondence.SendersReference, diff --git a/src/Altinn.Correspondence.API/Controllers/HealthController.cs b/src/Altinn.Correspondence.API/Controllers/HealthController.cs index 4fadca33..ee19efa6 100644 --- a/src/Altinn.Correspondence.API/Controllers/HealthController.cs +++ b/src/Altinn.Correspondence.API/Controllers/HealthController.cs @@ -12,7 +12,7 @@ public HealthController() } [HttpGet] - public async Task HealthCheckAsync() + public ActionResult HealthCheckAsync() { return Ok("Environment properly configured"); } diff --git a/src/Altinn.Correspondence.API/Mappers/AttachmentDetailsMapper.cs b/src/Altinn.Correspondence.API/Mappers/AttachmentDetailsMapper.cs index 6104a8d4..0d229908 100644 --- a/src/Altinn.Correspondence.API/Mappers/AttachmentDetailsMapper.cs +++ b/src/Altinn.Correspondence.API/Mappers/AttachmentDetailsMapper.cs @@ -13,7 +13,7 @@ internal static AttachmentDetailsExt MapToExternal(GetAttachmentDetailsCommandRe var attachment = new AttachmentDetailsExt { AttachmentId = AttachmentDetails.AttachmentId, - Name = AttachmentDetails.Name, + Name = AttachmentDetails.Name ?? string.Empty, Status = (AttachmentStatusExt)AttachmentDetails.Status, StatusText = AttachmentDetails.StatusText, StatusChanged = AttachmentDetails.StatusChanged, diff --git a/src/Altinn.Correspondence.API/Mappers/AttachmentOverviewMapper.cs b/src/Altinn.Correspondence.API/Mappers/AttachmentOverviewMapper.cs index af1b4429..405a03d2 100644 --- a/src/Altinn.Correspondence.API/Mappers/AttachmentOverviewMapper.cs +++ b/src/Altinn.Correspondence.API/Mappers/AttachmentOverviewMapper.cs @@ -13,7 +13,7 @@ internal static AttachmentOverviewExt MapToExternal(GetAttachmentOverviewCommand var attachment = new AttachmentOverviewExt { AttachmentId = attachmentOverview.AttachmentId, - Name = attachmentOverview.Name, + Name = attachmentOverview.Name ?? string.Empty, Status = (AttachmentStatusExt)attachmentOverview.Status, StatusText = attachmentOverview.StatusText, StatusChanged = attachmentOverview.StatusChanged, diff --git a/src/Altinn.Correspondence.API/Mappers/CorrespondenceNotificationMapper.cs b/src/Altinn.Correspondence.API/Mappers/CorrespondenceNotificationMapper.cs index 20a76d9d..4de8259b 100644 --- a/src/Altinn.Correspondence.API/Mappers/CorrespondenceNotificationMapper.cs +++ b/src/Altinn.Correspondence.API/Mappers/CorrespondenceNotificationMapper.cs @@ -8,7 +8,7 @@ internal static class CorrespondenceNotificationMapper internal static CorrespondenceNotificationDetailsExt MapToExternal(CorrespondenceNotificationEntity correspondenceNotification) { - var latestStatus = correspondenceNotification?.Statuses.OrderByDescending(s => s.StatusChanged).FirstOrDefault(); + var latestStatus = correspondenceNotification.Statuses.OrderByDescending(s => s.StatusChanged).First(); var notification = new CorrespondenceNotificationDetailsExt { NotificationTemplate = correspondenceNotification.NotificationTemplate, @@ -18,13 +18,10 @@ internal static CorrespondenceNotificationDetailsExt MapToExternal(Correspondenc Created = correspondenceNotification.Created, NotificationId = correspondenceNotification.Id, StatusHistory = correspondenceNotification.Statuses != null ? CorrespondenceNotificationStatusMapper.MapListToExternal(correspondenceNotification.Statuses) : new List(), + Status = latestStatus.Status, + StatusText = latestStatus.StatusText ?? string.Empty, + StatusChanged = latestStatus.StatusChanged }; - if (latestStatus != null) - { - notification.Status = latestStatus.Status; - notification.StatusText = latestStatus.StatusText; - notification.StatusChanged = latestStatus.StatusChanged; - } return notification; } diff --git a/src/Altinn.Correspondence.API/Mappers/InitializeCorrespondenceMapper.cs b/src/Altinn.Correspondence.API/Mappers/InitializeCorrespondenceMapper.cs index 05387397..2196ea8e 100644 --- a/src/Altinn.Correspondence.API/Mappers/InitializeCorrespondenceMapper.cs +++ b/src/Altinn.Correspondence.API/Mappers/InitializeCorrespondenceMapper.cs @@ -22,14 +22,15 @@ internal static InitializeCorrespondenceCommandRequest MapToRequest(InitializeCo ReplyOptions = CorrespondenceReplyOptionsMapper.MapListToEntities(initializeCorrespondenceExt.ReplyOptions), IsReservable = initializeCorrespondenceExt.IsReservable, Notifications = InitializeCorrespondenceNotificationMapper.MapListToEntities(initializeCorrespondenceExt.Notifications), + Statuses = new List(), Created = DateTimeOffset.UtcNow, - Content = new CorrespondenceContentEntity + Content = initializeCorrespondenceExt.Content != null ? new CorrespondenceContentEntity { Language = initializeCorrespondenceExt.Content.Language, MessageTitle = initializeCorrespondenceExt.Content.MessageTitle, MessageSummary = initializeCorrespondenceExt.Content.MessageSummary, Attachments = InitializeCorrespondenceAttachmentMapper.MapListToEntities(initializeCorrespondenceExt.Content.Attachments) - } + } : null, }; return new InitializeCorrespondenceCommandRequest() { diff --git a/src/Altinn.Correspondence.API/Models/AttachmentDetailsExt.cs b/src/Altinn.Correspondence.API/Models/AttachmentDetailsExt.cs index cfddcfd4..327011ab 100644 --- a/src/Altinn.Correspondence.API/Models/AttachmentDetailsExt.cs +++ b/src/Altinn.Correspondence.API/Models/AttachmentDetailsExt.cs @@ -13,6 +13,6 @@ public class AttachmentDetailsExt : AttachmentOverviewExt /// The Status history for the Attachment /// [JsonPropertyName("statusHistory")] - public List StatusHistory { get; set; } + public List StatusHistory { get; set; } = new List(); } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.API/Models/AttachmentOverviewExt.cs b/src/Altinn.Correspondence.API/Models/AttachmentOverviewExt.cs index cf693408..fd6686fc 100644 --- a/src/Altinn.Correspondence.API/Models/AttachmentOverviewExt.cs +++ b/src/Altinn.Correspondence.API/Models/AttachmentOverviewExt.cs @@ -26,18 +26,18 @@ public class AttachmentOverviewExt : InitializeAttachmentExt /// Current attachment status /// [JsonPropertyName("status")] - public AttachmentStatusExt Status { get; set; } + public required AttachmentStatusExt Status { get; set; } /// /// Current attachment status text description /// [JsonPropertyName("statusText")] - public string StatusText { get; set; } = string.Empty; + public required string StatusText { get; set; } /// /// Timestamp for when the Current Attachment Status was changed /// [JsonPropertyName("statusChanged")] - public DateTimeOffset? StatusChanged { get; set; } + public required DateTimeOffset StatusChanged { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.API/Models/CorrespondenceContentExt.cs b/src/Altinn.Correspondence.API/Models/CorrespondenceContentExt.cs index a85fd447..810b6788 100644 --- a/src/Altinn.Correspondence.API/Models/CorrespondenceContentExt.cs +++ b/src/Altinn.Correspondence.API/Models/CorrespondenceContentExt.cs @@ -15,6 +15,6 @@ public class CorrespondenceContentExt : InitializeCorrespondenceContentExt /// TODO: Number restriction? /// [JsonPropertyName("attachments")] - public new List Attachments { get; set; } + public required new List Attachments { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.API/Models/CorrespondenceDetailsExt.cs b/src/Altinn.Correspondence.API/Models/CorrespondenceDetailsExt.cs index 7d006490..0c3554b0 100644 --- a/src/Altinn.Correspondence.API/Models/CorrespondenceDetailsExt.cs +++ b/src/Altinn.Correspondence.API/Models/CorrespondenceDetailsExt.cs @@ -11,18 +11,18 @@ public class CorrespondenceDetailsExt : CorrespondenceOverviewExt /// The Status history for the Corrrespondence /// [JsonPropertyName("statusHistory")] - public List StatusHistory { get; set; } + public List StatusHistory { get; set; } = new List(); /// /// Notifications directly related to this Correspondence. /// [JsonPropertyName("notifications")] - public new List? Notifications { get; set; } + public new List? Notifications { get; set; } = new List(); /// /// The Status history for the Notifications /// [JsonPropertyName("notificationStatusHistory")] - public List NotificationStatusHistory { get; set; } + public List NotificationStatusHistory { get; set; } = new List(); } } diff --git a/src/Altinn.Correspondence.API/Models/CorrespondenceNotificationDetailsExt.cs b/src/Altinn.Correspondence.API/Models/CorrespondenceNotificationDetailsExt.cs index 9d148884..96439be9 100644 --- a/src/Altinn.Correspondence.API/Models/CorrespondenceNotificationDetailsExt.cs +++ b/src/Altinn.Correspondence.API/Models/CorrespondenceNotificationDetailsExt.cs @@ -11,7 +11,7 @@ public class CorrespondenceNotificationDetailsExt : CorrespondenceNotificationOv /// Current status for the notification /// [JsonPropertyName("status")] - public string Status { get; set; } + public required string Status { get; set; } /// /// Current status text for the notification @@ -29,12 +29,12 @@ public class CorrespondenceNotificationDetailsExt : CorrespondenceNotificationOv /// Completed Status history for the Notification /// [JsonPropertyName("statusHistory")] - public List StatusHistory { get; set; } + public List StatusHistory { get; set; } = new List(); /// /// Created timestamp for the notification /// [JsonPropertyName("created")] - public DateTimeOffset Created { get; set; } + public new DateTimeOffset Created { get; set; } } } diff --git a/src/Altinn.Correspondence.API/Models/CorrespondenceOverviewExt.cs b/src/Altinn.Correspondence.API/Models/CorrespondenceOverviewExt.cs index bf5c0820..d66e6301 100644 --- a/src/Altinn.Correspondence.API/Models/CorrespondenceOverviewExt.cs +++ b/src/Altinn.Correspondence.API/Models/CorrespondenceOverviewExt.cs @@ -18,7 +18,7 @@ public class CorrespondenceOverviewExt : InitializeCorrespondenceExt /// The correspondence content. Contains information about the Correspondence body, subject etc. /// [JsonPropertyName("content")] - public new CorrespondenceContentExt Content { get; set; } + public new CorrespondenceContentExt? Content { get; set; } /// /// When the correspondence was created diff --git a/src/Altinn.Correspondence.API/Models/CorrespondenceReplyOptionExt.cs b/src/Altinn.Correspondence.API/Models/CorrespondenceReplyOptionExt.cs index fb49faaa..a5c7522b 100644 --- a/src/Altinn.Correspondence.API/Models/CorrespondenceReplyOptionExt.cs +++ b/src/Altinn.Correspondence.API/Models/CorrespondenceReplyOptionExt.cs @@ -9,11 +9,11 @@ public class CorrespondenceReplyOptionExt /// /// Gets or sets the URL to be used as a reply/response to a correspondence. /// - public string LinkURL { get; set; } + public required string LinkURL { get; set; } /// /// Gets or sets the url text. /// - public string LinkText { get; set; } + public string? LinkText { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceContentExt.cs b/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceContentExt.cs index 0f7599d4..559ec25e 100644 --- a/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceContentExt.cs +++ b/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceContentExt.cs @@ -14,7 +14,7 @@ public class InitializeCorrespondenceContentExt /// [JsonPropertyName("language")] [ISO6391] - public string Language { get; set; } + public required string Language { get; set; } /// /// Gets or sets the correspondence message title. Subject. @@ -23,7 +23,7 @@ public class InitializeCorrespondenceContentExt /// TODO: Length restriction? /// [JsonPropertyName("messageTitle")] - public string MessageTitle { get; set; } + public required string MessageTitle { get; set; } /// /// Gets or sets a summary text of the correspondence. @@ -32,7 +32,7 @@ public class InitializeCorrespondenceContentExt /// TODO: Length restriction? /// [JsonPropertyName("messageSummary")] - public string MessageSummary { get; set; } + public required string MessageSummary { get; set; } /// /// Gets or sets a list of attachments. @@ -41,7 +41,7 @@ public class InitializeCorrespondenceContentExt /// TODO: Number restriction? /// [JsonPropertyName("attachments")] - public List Attachments { get; set; } + public List Attachments { get; set; } = new List(); /// /// Ids of the attachments that are to be included in the correspondence. @@ -57,7 +57,7 @@ public ISO6391Attribute() { } - protected override ValidationResult IsValid(object value, ValidationContext validationContext) + protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) { var stringValue = value as string; if (string.IsNullOrWhiteSpace(stringValue)) diff --git a/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceExt.cs b/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceExt.cs index 41779364..432feed1 100644 --- a/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceExt.cs +++ b/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceExt.cs @@ -49,7 +49,7 @@ public class InitializeCorrespondenceExt /// The correspondence content. Contains information about the Correspondence body, subject etc. /// [JsonPropertyName("content")] - public InitializeCorrespondenceContentExt Content { get; set; } + public InitializeCorrespondenceContentExt? Content { get; set; } /// /// When the correspondence should become visible to the recipient. @@ -90,14 +90,14 @@ public class InitializeCorrespondenceExt /// Options for how the recipient can reply to the correspondence /// [JsonPropertyName("replyOptions")] - public List? ReplyOptions { get; set; } + public List ReplyOptions { get; set; } = new List(); /// /// Notifications directly related to this Correspondence. /// [JsonPropertyName("notifications")] [MaxLength(6, ErrorMessage = "Notifications can contain at most 6 notifcations")] - public List? Notifications { get; set; } + public List Notifications { get; set; } = new List(); /// /// Specifies whether the correspondence can override reservation against digital comminication in KRR @@ -113,7 +113,7 @@ public PropertyListAttribute() { } - protected override ValidationResult IsValid(object value, ValidationContext validationContext) + protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) { if (value == null) { diff --git a/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceNotificationExt.cs b/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceNotificationExt.cs index 24d23483..4ae98ba7 100644 --- a/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceNotificationExt.cs +++ b/src/Altinn.Correspondence.API/Models/InitializeCorrespondenceNotificationExt.cs @@ -18,7 +18,7 @@ public class InitializeCorrespondenceNotificationExt /// Reminders sent after 14 days if Correspondence not confirmed /// [JsonPropertyName("notificationTemplate")] - public string NotificationTemplate { get; set; } + public required string NotificationTemplate { get; set; } /// /// Single custom text token that can be inserted into the notification template diff --git a/src/Altinn.Correspondence.API/Models/MD5ChecksumAttribute.cs b/src/Altinn.Correspondence.API/Models/MD5ChecksumAttribute.cs index 7754e91f..cc9b2e77 100644 --- a/src/Altinn.Correspondence.API/Models/MD5ChecksumAttribute.cs +++ b/src/Altinn.Correspondence.API/Models/MD5ChecksumAttribute.cs @@ -8,7 +8,7 @@ public MD5ChecksumAttribute() { } - protected override ValidationResult IsValid(object value, ValidationContext validationContext) + protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) { var stringValue = value as string; if (string.IsNullOrWhiteSpace(stringValue)) diff --git a/src/Altinn.Correspondence.API/Models/NotificationStatusEventExt.cs b/src/Altinn.Correspondence.API/Models/NotificationStatusEventExt.cs index e48244cc..fe9393ea 100644 --- a/src/Altinn.Correspondence.API/Models/NotificationStatusEventExt.cs +++ b/src/Altinn.Correspondence.API/Models/NotificationStatusEventExt.cs @@ -9,21 +9,21 @@ namespace Altinn.Correspondence.API.Models public class NotificationStatusEventExt { /// - /// Notificatipn Status code + /// Notification Status code /// [JsonPropertyName("status")] - public string Status { get; set; } + public required string Status { get; set; } /// /// Notification Status Text description /// [JsonPropertyName("statusText")] - public string StatusText { get; set; } = string.Empty; + public required string StatusText { get; set; } /// /// Timestamp for when this Correspondence Status Event occurred /// [JsonPropertyName("statusChanged")] - public DateTimeOffset StatusChanged { get; set; } + public required DateTimeOffset StatusChanged { get; set; } } } diff --git a/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandHandler.cs b/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandHandler.cs index c6ff168c..6a3bb49e 100644 --- a/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandHandler.cs +++ b/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandHandler.cs @@ -18,20 +18,20 @@ public GetAttachmentDetailsCommandHandler(IAttachmentStatusRepository attachment public async Task> Process(Guid attachmentId, CancellationToken cancellationToken) { var attachment = await _attachmentRepository.GetAttachmentById(attachmentId, true, cancellationToken); - var attachmentStatus = attachment?.Statuses.OrderByDescending(s => s.StatusChanged).FirstOrDefault(); if (attachment == null) { return Errors.AttachmentNotFound; } + var attachmentStatus = attachment.Statuses.OrderByDescending(s => s.StatusChanged).First(); var response = new GetAttachmentDetailsCommandResponse { AttachmentId = attachment.Id, DataLocationUrl = attachment.DataLocationUrl, Name = attachment.FileName, - Status = attachmentStatus?.Status, + Status = attachmentStatus.Status, Statuses = attachment.Statuses, - StatusChanged = attachmentStatus?.StatusChanged, + StatusChanged = attachmentStatus.StatusChanged, DataLocationType = attachment.DataLocationType, DataType = attachment.DataType, IntendedPresentation = attachment.IntendedPresentation, diff --git a/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandResponse.cs b/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandResponse.cs index c67bfd4c..d4b3fa1b 100644 --- a/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandResponse.cs +++ b/src/Altinn.Correspondence.Application/GetAttachmentDetails/GetAttachmentDetailsCommandResponse.cs @@ -11,11 +11,11 @@ public class GetAttachmentDetailsCommandResponse public string? DataLocationUrl { get; set; } - public AttachmentStatus? Status { get; set; } + public AttachmentStatus Status { get; set; } - public string? StatusText { get; set; } = string.Empty; + public string StatusText { get; set; } = string.Empty; - public DateTimeOffset? StatusChanged { get; set; } + public DateTimeOffset StatusChanged { get; set; } public string? Name { get; set; } = string.Empty; diff --git a/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandHandler.cs b/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandHandler.cs index e28a7c5d..2beda182 100644 --- a/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandHandler.cs +++ b/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandHandler.cs @@ -17,20 +17,20 @@ public GetAttachmentOverviewCommandHandler(IAttachmentStatusRepository attachmen public async Task> Process(Guid attachmentId, CancellationToken cancellationToken) { var attachment = await _attachmentRepository.GetAttachmentById(attachmentId, false, cancellationToken); - var attachmentStatus = await _attachmentStatusRepository.GetLatestStatusByAttachmentId(attachmentId, cancellationToken); if (attachment == null) { return Errors.AttachmentNotFound; } + var attachmentStatus = await _attachmentStatusRepository.GetLatestStatusByAttachmentId(attachmentId, cancellationToken); var response = new GetAttachmentOverviewCommandResponse { AttachmentId = attachment.Id, DataLocationUrl = attachment.DataLocationUrl, Name = attachment.FileName, - Status = attachmentStatus?.Status, - StatusText = attachmentStatus?.StatusText, - StatusChanged = attachmentStatus?.StatusChanged, + Status = attachmentStatus.Status, + StatusText = attachmentStatus.StatusText, + StatusChanged = attachmentStatus.StatusChanged, DataLocationType = attachment.DataLocationType, DataType = attachment.DataType, IntendedPresentation = attachment.IntendedPresentation, diff --git a/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandResponse.cs b/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandResponse.cs index ea88184a..9d317847 100644 --- a/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandResponse.cs +++ b/src/Altinn.Correspondence.Application/GetAttachmentOverview/GetAttachmentOverviewCommandResponse.cs @@ -10,11 +10,11 @@ public class GetAttachmentOverviewCommandResponse public string? DataLocationUrl { get; set; } - public AttachmentStatus? Status { get; set; } + public AttachmentStatus Status { get; set; } - public string? StatusText { get; set; } = string.Empty; + public required string StatusText { get; set; } - public DateTimeOffset? StatusChanged { get; set; } + public DateTimeOffset StatusChanged { get; set; } public string? Name { get; set; } = string.Empty; diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandHandler.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandHandler.cs index 66f5fa4b..04f4a19f 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandHandler.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandHandler.cs @@ -1,4 +1,5 @@ using Altinn.Correspondence.Application.GetCorrespondenceDetailsCommand; +using Altinn.Correspondence.Core.Models; using Altinn.Correspondence.Core.Repositories; using OneOf; @@ -15,23 +16,22 @@ public GetCorrespondenceDetailsCommandHandler(ICorrespondenceRepository Correspo public async Task> Process(Guid CorrespondenceId, CancellationToken cancellationToken) { var correspondence = await _CorrespondenceRepository.GetCorrespondenceById(CorrespondenceId, true, cancellationToken); - var latestStatus = correspondence?.Statuses.OrderByDescending(s => s.StatusChanged).FirstOrDefault(); if (correspondence == null) { return Errors.CorrespondenceNotFound; } - + var latestStatus = correspondence.Statuses.OrderByDescending(s => s.StatusChanged).First(); var response = new GetCorrespondenceDetailsCommandResponse { CorrespondenceId = correspondence.Id, - Status = latestStatus?.Status, - StatusText = latestStatus?.StatusText, - StatusChanged = latestStatus?.StatusChanged, + Status = latestStatus.Status, + StatusText = latestStatus.StatusText, + StatusChanged = latestStatus.StatusChanged, SendersReference = correspondence.SendersReference, Created = correspondence.Created, Recipient = correspondence.Recipient, - ReplyOptions = correspondence.ReplyOptions, - Notifications = correspondence.Notifications, + ReplyOptions = correspondence.ReplyOptions == null ? new List() : correspondence.ReplyOptions, + Notifications = correspondence.Notifications == null ? new List() : correspondence.Notifications, VisibleFrom = correspondence.VisibleFrom, IsReservable = correspondence.IsReservable == null || correspondence.IsReservable.Value, StatusHistory = correspondence.Statuses diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandResponse.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandResponse.cs index fe74ffda..38fe0fef 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandResponse.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceDetails/GetCorrespondenceDetailsCommandResponse.cs @@ -7,11 +7,11 @@ public class GetCorrespondenceDetailsCommandResponse { public required Guid CorrespondenceId { get; set; } - public CorrespondenceStatus? Status { get; set; } + public CorrespondenceStatus Status { get; set; } - public string? StatusText { get; set; } = string.Empty; + public string StatusText { get; set; } = string.Empty; - public DateTimeOffset? StatusChanged { get; set; } + public DateTimeOffset StatusChanged { get; set; } public string? Name { get; set; } = string.Empty; diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandHandler.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandHandler.cs index 5dd82c35..e1839d9c 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandHandler.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandHandler.cs @@ -1,4 +1,5 @@ using Altinn.Correspondence.Application.GetCorrespondenceOverviewCommand; +using Altinn.Correspondence.Core.Models; using Altinn.Correspondence.Core.Repositories; using OneOf; @@ -15,23 +16,26 @@ public GetCorrespondenceOverviewCommandHandler(ICorrespondenceRepository Corresp public async Task> Process(Guid CorrespondenceId, CancellationToken cancellationToken) { var correspondence = await _CorrespondenceRepository.GetCorrespondenceById(CorrespondenceId, true, cancellationToken); - var latestStatus = correspondence?.Statuses.OrderByDescending(s => s.StatusChanged).FirstOrDefault(); if (correspondence == null) { return Errors.CorrespondenceNotFound; } - + var latestStatus = correspondence.Statuses?.OrderByDescending(s => s.StatusChanged).FirstOrDefault(); + if (latestStatus == null) + { + return Errors.CorrespondenceNotFound; + } var response = new GetCorrespondenceOverviewCommandResponse { CorrespondenceId = correspondence.Id, - Status = latestStatus?.Status, - StatusText = latestStatus?.StatusText, - StatusChanged = latestStatus?.StatusChanged, + Status = latestStatus.Status, + StatusText = latestStatus.StatusText, + StatusChanged = latestStatus.StatusChanged, SendersReference = correspondence.SendersReference, Created = correspondence.Created, Recipient = correspondence.Recipient, - ReplyOptions = correspondence.ReplyOptions, - Notifications = correspondence.Notifications, + ReplyOptions = correspondence.ReplyOptions ?? new List(), + Notifications = correspondence.Notifications ?? new List(), VisibleFrom = correspondence.VisibleFrom, IsReservable = correspondence.IsReservable == null || correspondence.IsReservable.Value, }; diff --git a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandResponse.cs b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandResponse.cs index 58e4e6c2..3e7470c4 100644 --- a/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandResponse.cs +++ b/src/Altinn.Correspondence.Application/GetCorrespondenceOverview/GetCorrespondenceOverviewCommandResponse.cs @@ -7,11 +7,11 @@ public class GetCorrespondenceOverviewCommandResponse { public required Guid CorrespondenceId { get; set; } - public CorrespondenceStatus? Status { get; set; } + public required CorrespondenceStatus Status { get; set; } - public string? StatusText { get; set; } = string.Empty; + public required string StatusText { get; set; } - public DateTimeOffset? StatusChanged { get; set; } + public required DateTimeOffset StatusChanged { get; set; } public string? Name { get; set; } = string.Empty; diff --git a/src/Altinn.Correspondence.Application/InitializeAttachmentCommand/InitializeAttachmentCommandRequest.cs b/src/Altinn.Correspondence.Application/InitializeAttachmentCommand/InitializeAttachmentCommandRequest.cs index 68a45092..e8e62c78 100644 --- a/src/Altinn.Correspondence.Application/InitializeAttachmentCommand/InitializeAttachmentCommandRequest.cs +++ b/src/Altinn.Correspondence.Application/InitializeAttachmentCommand/InitializeAttachmentCommandRequest.cs @@ -4,5 +4,5 @@ namespace Altinn.Correspondence.Application.InitializeAttachmentCommand; public class InitializeAttachmentCommandRequest { - public AttachmentEntity Attachment { get; set; } + public required AttachmentEntity Attachment { get; set; } } diff --git a/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandHandler.cs b/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandHandler.cs index a76e6347..76986012 100644 --- a/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandHandler.cs +++ b/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandHandler.cs @@ -21,10 +21,14 @@ public InitializeCorrespondenceCommandHandler(ICorrespondenceRepository correspo public async Task> Process(InitializeCorrespondenceCommandRequest request, CancellationToken cancellationToken) { - var attachments = request.Correspondence.Content.Attachments; - foreach (var attachment in attachments) + var attachments = request.Correspondence.Content?.Attachments; + + if (attachments != null) { - attachment.Attachment = await ProcessAttachment(attachment, cancellationToken); + foreach (var attachment in attachments) + { + attachment.Attachment = await ProcessAttachment(attachment, cancellationToken); + } } var statuses = new List(){ new CorrespondenceStatusEntity @@ -34,19 +38,20 @@ public async Task> Process } }; request.Correspondence.Statuses = statuses; + request.Correspondence.Notifications = ProcessNotifications(request.Correspondence.Notifications, cancellationToken); var correspondence = await _correspondenceRepository.InitializeCorrespondence(request.Correspondence, cancellationToken); await _eventBus.Publish(AltinnEventType.CorrespondenceInitialized, null, correspondence.Id.ToString(), "correspondence", null, cancellationToken); return new InitializeCorrespondenceCommandResponse() { CorrespondenceId = correspondence.Id, - AttachmentIds = correspondence.Content.Attachments.Select(a => a.Attachment.Id).ToList() + AttachmentIds = correspondence.Content?.Attachments.Select(a => a.AttachmentId).ToList() ?? new List() }; } public CorrespondenceStatus GetInitializeCorrespondenceStatus(CorrespondenceEntity correspondence) { var status = CorrespondenceStatus.Initialized; - if (correspondence.Content.Attachments.All(c => c.Attachment.Statuses != null && c.Attachment.Statuses.All(s => s.Status == AttachmentStatus.Published))) + if (correspondence.Content != null && correspondence.Content.Attachments.All(c => c.Attachment?.Statuses != null && c.Attachment.Statuses.All(s => s.Status == AttachmentStatus.Published))) { status = CorrespondenceStatus.Published; } @@ -88,4 +93,22 @@ public async Task ProcessAttachment(CorrespondenceAttachmentEn } return attachment; } + + private List ProcessNotifications(List? notifications, CancellationToken cancellationToken) + { + if (notifications == null) return new List(); + + foreach (var notification in notifications) + { + notification.Statuses = new List(){ + new CorrespondenceNotificationStatusEntity + { + Status = "Initialized", //TODO create enums for notications? + StatusChanged = DateTimeOffset.UtcNow, + StatusText = "Initialized" + } + }; + } + return notifications; + } } diff --git a/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandRequest.cs b/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandRequest.cs index d9aa1174..982bdd2d 100644 --- a/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandRequest.cs +++ b/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandRequest.cs @@ -4,5 +4,5 @@ namespace Altinn.Correspondence.Application.InitializeCorrespondenceCommand; public class InitializeCorrespondenceCommandRequest { - public CorrespondenceEntity Correspondence { get; set; } + public required CorrespondenceEntity Correspondence { get; set; } } diff --git a/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandResponse.cs b/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandResponse.cs index 25349e3b..ee82fd25 100644 --- a/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandResponse.cs +++ b/src/Altinn.Correspondence.Application/InitializeCorrespondenceCommand/InitializeCorrespondenceCommandResponse.cs @@ -6,5 +6,5 @@ public class InitializeCorrespondenceCommandResponse { public Guid CorrespondenceId { get; set; } - public List AttachmentIds { get; set; } + public List AttachmentIds { get; set; } = new List(); } diff --git a/src/Altinn.Correspondence.Core/Models/AttachmentEntity.cs b/src/Altinn.Correspondence.Core/Models/AttachmentEntity.cs index 29cc9977..17b246c1 100644 --- a/src/Altinn.Correspondence.Core/Models/AttachmentEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/AttachmentEntity.cs @@ -32,13 +32,13 @@ public class AttachmentEntity [Required] public DateTimeOffset ExpirationTime { get; set; } - public List Statuses { get; set; } + public List Statuses { get; set; } = new List(); public string? DataLocationUrl { get; set; } public AttachmentDataLocationType DataLocationType { get; set; } - public List CorrespondenceAttachments { get; set; } + public List CorrespondenceAttachments { get; set; } = new List(); [Required] public required DateTimeOffset Created { get; set; } diff --git a/src/Altinn.Correspondence.Core/Models/AttachmentStatusEntity.cs b/src/Altinn.Correspondence.Core/Models/AttachmentStatusEntity.cs index c1fba9cd..1ef9aefd 100644 --- a/src/Altinn.Correspondence.Core/Models/AttachmentStatusEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/AttachmentStatusEntity.cs @@ -19,7 +19,7 @@ public class AttachmentStatusEntity public Guid AttachmentId { get; set; } [ForeignKey("AttachmentId")] - public AttachmentEntity Attachment { get; set; } + public AttachmentEntity? Attachment { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.Core/Models/CorrespondenceAttachmentEntity.cs b/src/Altinn.Correspondence.Core/Models/CorrespondenceAttachmentEntity.cs index 55e82d4e..f9c82ba1 100644 --- a/src/Altinn.Correspondence.Core/Models/CorrespondenceAttachmentEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/CorrespondenceAttachmentEntity.cs @@ -40,11 +40,11 @@ public class CorrespondenceAttachmentEntity public Guid CorrespondenceContentId { get; set; } [ForeignKey("CorrespondenceContentId")] - public CorrespondenceContentEntity CorrespondenceContent { get; set; } + public CorrespondenceContentEntity? CorrespondenceContent { get; set; } public Guid AttachmentId { get; set; } [ForeignKey("AttachmentId")] - public AttachmentEntity Attachment { get; set; } + public AttachmentEntity? Attachment { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.Core/Models/CorrespondenceContentEntity.cs b/src/Altinn.Correspondence.Core/Models/CorrespondenceContentEntity.cs index 4fb85bec..075fbfe7 100644 --- a/src/Altinn.Correspondence.Core/Models/CorrespondenceContentEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/CorrespondenceContentEntity.cs @@ -9,16 +9,16 @@ public class CorrespondenceContentEntity [Key] public Guid Id { get; set; } - public string Language { get; set; } + public required string Language { get; set; } - public string MessageTitle { get; set; } + public required string MessageTitle { get; set; } - public string MessageSummary { get; set; } + public required string MessageSummary { get; set; } - public List Attachments { get; set; } + public required List Attachments { get; set; } public Guid CorrespondenceId { get; set; } [ForeignKey("CorrespondenceId")] - public CorrespondenceEntity Correspondence { get; set; } + public CorrespondenceEntity? Correspondence { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.Core/Models/CorrespondenceEntity.cs b/src/Altinn.Correspondence.Core/Models/CorrespondenceEntity.cs index 6ccf9b1f..8921eb5d 100644 --- a/src/Altinn.Correspondence.Core/Models/CorrespondenceEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/CorrespondenceEntity.cs @@ -22,7 +22,7 @@ public class CorrespondenceEntity [Required] public required string SendersReference { get; set; } - public CorrespondenceContentEntity Content { get; set; } + public CorrespondenceContentEntity? Content { get; set; } public required DateTimeOffset VisibleFrom { get; set; } @@ -30,19 +30,19 @@ public class CorrespondenceEntity public DateTimeOffset DueDateTime { get; set; } - public List? ExternalReferences { get; set; } + public List ExternalReferences { get; set; } = new List(); [MaxLength(10, ErrorMessage = "propertyList can contain at most 10 properties")] public Dictionary PropertyList { get; set; } = new Dictionary(); - public List? ReplyOptions { get; set; } + public List ReplyOptions { get; set; } = new List(); [MaxLength(6, ErrorMessage = "Notifications can contain at most 6 notifcations")] - public List? Notifications { get; set; } + public List Notifications { get; set; } = new List(); public bool? IsReservable { get; set; } - public List? Statuses { get; set; } + public required List Statuses { get; set; } [Required] public required DateTimeOffset Created { get; set; } diff --git a/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationEntity.cs b/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationEntity.cs index 5c45c7c5..849b9a57 100644 --- a/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationEntity.cs @@ -19,11 +19,11 @@ public class CorrespondenceNotificationEntity public Guid CorrespondenceId { get; set; } [ForeignKey("CorrespondenceId")] - public CorrespondenceEntity Correspondence { get; set; } + public CorrespondenceEntity? Correspondence { get; set; } [Required] public required DateTimeOffset Created { get; set; } - public List Statuses { get; set; } + public List Statuses { get; set; } = new List(); } } diff --git a/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationStatusEntity.cs b/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationStatusEntity.cs index 63a3f6ec..5ad85d1b 100644 --- a/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationStatusEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/CorrespondenceNotificationStatusEntity.cs @@ -9,15 +9,15 @@ public class CorrespondenceNotificationStatusEntity public Guid Id { get; set; } [Required] - public string Status { get; set; } + public required string Status { get; set; } - public string? StatusText { get; set; } + public required string StatusText { get; set; } [Required] public DateTimeOffset StatusChanged { get; set; } public Guid NotificationId { get; set; } [ForeignKey("NotificationId")] - public CorrespondenceNotificationEntity Notification { get; set; } + public CorrespondenceNotificationEntity? Notification { get; set; } } } diff --git a/src/Altinn.Correspondence.Core/Models/CorrespondenceReplyOptionsEntity.cs b/src/Altinn.Correspondence.Core/Models/CorrespondenceReplyOptionsEntity.cs index bee4ec53..d69028a2 100644 --- a/src/Altinn.Correspondence.Core/Models/CorrespondenceReplyOptionsEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/CorrespondenceReplyOptionsEntity.cs @@ -8,12 +8,12 @@ public class CorrespondenceReplyOptionEntity [Key] public Guid Id { get; set; } - public string LinkURL { get; set; } + public required string LinkURL { get; set; } - public string LinkText { get; set; } + public string? LinkText { get; set; } public Guid CorrespondenceId { get; set; } [ForeignKey("CorrespondenceId")] - public CorrespondenceEntity Correspondence { get; set; } + public CorrespondenceEntity? Correspondence { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.Core/Models/CorrespondenceStatusEntity.cs b/src/Altinn.Correspondence.Core/Models/CorrespondenceStatusEntity.cs index 3b66a6a2..0957d5dc 100644 --- a/src/Altinn.Correspondence.Core/Models/CorrespondenceStatusEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/CorrespondenceStatusEntity.cs @@ -19,7 +19,7 @@ public class CorrespondenceStatusEntity public Guid CorrespondenceId { get; set; } [ForeignKey("CorrespondenceId")] - public CorrespondenceEntity Correspondence { get; set; } + public CorrespondenceEntity? Correspondence { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.Core/Models/ExternalReferenceEntity.cs b/src/Altinn.Correspondence.Core/Models/ExternalReferenceEntity.cs index 76706fb3..d4dcffb3 100644 --- a/src/Altinn.Correspondence.Core/Models/ExternalReferenceEntity.cs +++ b/src/Altinn.Correspondence.Core/Models/ExternalReferenceEntity.cs @@ -15,6 +15,6 @@ public class ExternalReferenceEntity public Guid CorrespondenceId { get; set; } [ForeignKey("CorrespondenceId")] - public CorrespondenceEntity Correspondence { get; set; } + public CorrespondenceEntity? Correspondence { get; set; } } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.Core/Repositories/IAttachmentStatusRepository.cs b/src/Altinn.Correspondence.Core/Repositories/IAttachmentStatusRepository.cs index cd8fbe58..cb96c0d9 100644 --- a/src/Altinn.Correspondence.Core/Repositories/IAttachmentStatusRepository.cs +++ b/src/Altinn.Correspondence.Core/Repositories/IAttachmentStatusRepository.cs @@ -5,6 +5,6 @@ namespace Altinn.Correspondence.Core.Repositories public interface IAttachmentStatusRepository { Task AddAttachmentStatus(AttachmentStatusEntity attachment, CancellationToken cancellationToken); - Task GetLatestStatusByAttachmentId(Guid attachmentId, CancellationToken cancellationToken); + Task GetLatestStatusByAttachmentId(Guid attachmentId, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/Altinn.Correspondence.Core/Repositories/ICorrespondenceStatusRepository.cs b/src/Altinn.Correspondence.Core/Repositories/ICorrespondenceStatusRepository.cs index 3a021561..37f1050a 100644 --- a/src/Altinn.Correspondence.Core/Repositories/ICorrespondenceStatusRepository.cs +++ b/src/Altinn.Correspondence.Core/Repositories/ICorrespondenceStatusRepository.cs @@ -6,7 +6,7 @@ public interface ICorrespondenceStatusRepository { Task AddCorrespondenceStatus(CorrespondenceStatusEntity Correspondence, CancellationToken cancellationToken); - Task GetLatestStatusByCorrespondenceId(Guid CorrespondenceId, CancellationToken cancellationToken); + Task GetLatestStatusByCorrespondenceId(Guid CorrespondenceId, CancellationToken cancellationToken); Task> AddCorrespondenceStatuses(List statuses, CancellationToken cancellationToken); } diff --git a/src/Altinn.Correspondence.Persistence/Repositories/AttachmentStatusRepository.cs b/src/Altinn.Correspondence.Persistence/Repositories/AttachmentStatusRepository.cs index b82f9b33..8dc7e066 100644 --- a/src/Altinn.Correspondence.Persistence/Repositories/AttachmentStatusRepository.cs +++ b/src/Altinn.Correspondence.Persistence/Repositories/AttachmentStatusRepository.cs @@ -15,12 +15,12 @@ public async Task AddAttachmentStatus(AttachmentStatusEntity status, Cance return status.Id; } - public async Task GetLatestStatusByAttachmentId(Guid attachmentId, CancellationToken cancellationToken) + public async Task GetLatestStatusByAttachmentId(Guid attachmentId, CancellationToken cancellationToken) { var status = await _context.AttachmentStatuses .Where(s => s.AttachmentId == attachmentId) .OrderByDescending(s => s.StatusChanged) - .FirstOrDefaultAsync(cancellationToken); + .FirstAsync(cancellationToken); return status; } diff --git a/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceRepository.cs b/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceRepository.cs index 3cf1595b..29b9ec47 100644 --- a/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceRepository.cs +++ b/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceRepository.cs @@ -26,7 +26,7 @@ public async Task InitializeCorrespondence(CorrespondenceE CancellationToken cancellationToken) { var correspondences = _context.Correspondences - .Where(c => (status == null || (status != null && _context.CorrespondenceStatuses.Where(cs => cs.CorrespondenceId == c.Id).OrderBy(cs => cs.StatusChanged).LastOrDefault().Status == status)) && + .Where(c => (status == null || (status != null && _context.CorrespondenceStatuses.Where(cs => cs.CorrespondenceId == c.Id).OrderBy(cs => cs.StatusChanged).Last().Status == status)) && (from == null || (from != null && c.VisibleFrom > from)) && (to == null || (to != null && c.VisibleFrom < to))) .OrderByDescending(c => c.VisibleFrom) @@ -54,7 +54,7 @@ public async Task> GetNonPublishedCorrespondencesByAt var correspondence = await _context.Correspondences.Where(c => !_context.CorrespondenceStatuses.Any(cs => cs.CorrespondenceId == c.Id && cs.Status == CorrespondenceStatus.Published) && c.Content.Attachments.Any(ca => ca.AttachmentId == attachmentId) && - (attachmentStatus == null || c.Content.Attachments.All(ca => ca.Attachment.Statuses.OrderByDescending(s => s.StatusChanged).FirstOrDefault().Status == attachmentStatus)) + (attachmentStatus == null || c.Content.Attachments.All(ca => ca.Attachment != null && ca.Attachment.Statuses.OrderByDescending(s => s.StatusChanged).First().Status == attachmentStatus)) ).Include(c => c.Content).ThenInclude(content => content.Attachments).ThenInclude(a => a.Attachment).ToListAsync(cancellationToken); return correspondence; diff --git a/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceStatusRepository.cs b/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceStatusRepository.cs index 326d4574..23f43785 100644 --- a/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceStatusRepository.cs +++ b/src/Altinn.Correspondence.Persistence/Repositories/CorrespondenceStatusRepository.cs @@ -22,12 +22,12 @@ public async Task> AddCorrespondenceStatuses(List s.Id).ToList(); } - public async Task GetLatestStatusByCorrespondenceId(Guid CorrespondenceId, CancellationToken cancellationToken) + public async Task GetLatestStatusByCorrespondenceId(Guid CorrespondenceId, CancellationToken cancellationToken) { var status = await _context.CorrespondenceStatuses .Where(s => s.CorrespondenceId == CorrespondenceId) .OrderByDescending(s => s.StatusChanged) - .FirstOrDefaultAsync(cancellationToken); + .FirstAsync(cancellationToken); return status; }