Skip to content

Commit

Permalink
cleanup warnings (#97)
Browse files Browse the repository at this point in the history
Co-authored-by: Hammerbeck <[email protected]>
  • Loading branch information
Andreass2 and Hammerbeck authored Jun 4, 2024
1 parent 4feee01 commit 7cf2121
Show file tree
Hide file tree
Showing 45 changed files with 141 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task<ActionResult<CorrespondenceOverviewExt>> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public HealthController()
}

[HttpGet]
public async Task<ActionResult> HealthCheckAsync()
public ActionResult HealthCheckAsync()
{
return Ok("Environment properly configured");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<NotificationStatusEventExt>(),
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CorrespondenceStatusEntity>(),
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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class AttachmentDetailsExt : AttachmentOverviewExt
/// The Status history for the Attachment
/// </summary>
[JsonPropertyName("statusHistory")]
public List<AtachmentStatusEvent> StatusHistory { get; set; }
public List<AtachmentStatusEvent> StatusHistory { get; set; } = new List<AtachmentStatusEvent>();
}
}
6 changes: 3 additions & 3 deletions src/Altinn.Correspondence.API/Models/AttachmentOverviewExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ public class AttachmentOverviewExt : InitializeAttachmentExt
/// Current attachment status
/// </summary>
[JsonPropertyName("status")]
public AttachmentStatusExt Status { get; set; }
public required AttachmentStatusExt Status { get; set; }

/// <summary>
/// Current attachment status text description
/// </summary>
[JsonPropertyName("statusText")]
public string StatusText { get; set; } = string.Empty;
public required string StatusText { get; set; }

/// <summary>
/// Timestamp for when the Current Attachment Status was changed
/// </summary>
[JsonPropertyName("statusChanged")]
public DateTimeOffset? StatusChanged { get; set; }
public required DateTimeOffset StatusChanged { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class CorrespondenceContentExt : InitializeCorrespondenceContentExt
/// TODO: Number restriction?
/// </remarks>
[JsonPropertyName("attachments")]
public new List<CorrespondenceAttachmentOverviewExt> Attachments { get; set; }
public required new List<CorrespondenceAttachmentOverviewExt> Attachments { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ public class CorrespondenceDetailsExt : CorrespondenceOverviewExt
/// The Status history for the Corrrespondence
/// </summary>
[JsonPropertyName("statusHistory")]
public List<CorrespondenceStatusEventExt> StatusHistory { get; set; }
public List<CorrespondenceStatusEventExt> StatusHistory { get; set; } = new List<CorrespondenceStatusEventExt>();

/// <summary>
/// Notifications directly related to this Correspondence.
/// </summary>
[JsonPropertyName("notifications")]
public new List<CorrespondenceNotificationDetailsExt>? Notifications { get; set; }
public new List<CorrespondenceNotificationDetailsExt>? Notifications { get; set; } = new List<CorrespondenceNotificationDetailsExt>();

/// <summary>
/// The Status history for the Notifications
/// </summary>
[JsonPropertyName("notificationStatusHistory")]
public List<NotificationStatusEventExt> NotificationStatusHistory { get; set; }
public List<NotificationStatusEventExt> NotificationStatusHistory { get; set; } = new List<NotificationStatusEventExt>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CorrespondenceNotificationDetailsExt : CorrespondenceNotificationOv
/// Current status for the notification
/// </summary>
[JsonPropertyName("status")]
public string Status { get; set; }
public required string Status { get; set; }

/// <summary>
/// Current status text for the notification
Expand All @@ -29,12 +29,12 @@ public class CorrespondenceNotificationDetailsExt : CorrespondenceNotificationOv
/// Completed Status history for the Notification
/// </summary>
[JsonPropertyName("statusHistory")]
public List<NotificationStatusEventExt> StatusHistory { get; set; }
public List<NotificationStatusEventExt> StatusHistory { get; set; } = new List<NotificationStatusEventExt>();

/// <summary>
/// Created timestamp for the notification
/// </summary>
[JsonPropertyName("created")]
public DateTimeOffset Created { get; set; }
public new DateTimeOffset Created { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CorrespondenceOverviewExt : InitializeCorrespondenceExt
/// The correspondence content. Contains information about the Correspondence body, subject etc.
/// </summary>
[JsonPropertyName("content")]
public new CorrespondenceContentExt Content { get; set; }
public new CorrespondenceContentExt? Content { get; set; }

/// <summary>
/// When the correspondence was created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class CorrespondenceReplyOptionExt
/// <summary>
/// Gets or sets the URL to be used as a reply/response to a correspondence.
/// </summary>
public string LinkURL { get; set; }
public required string LinkURL { get; set; }

/// <summary>
/// Gets or sets the url text.
/// </summary>
public string LinkText { get; set; }
public string? LinkText { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class InitializeCorrespondenceContentExt
/// </summary>
[JsonPropertyName("language")]
[ISO6391]
public string Language { get; set; }
public required string Language { get; set; }

/// <summary>
/// Gets or sets the correspondence message title. Subject.
Expand All @@ -23,7 +23,7 @@ public class InitializeCorrespondenceContentExt
/// TODO: Length restriction?
/// </remarks>
[JsonPropertyName("messageTitle")]
public string MessageTitle { get; set; }
public required string MessageTitle { get; set; }

/// <summary>
/// Gets or sets a summary text of the correspondence.
Expand All @@ -32,7 +32,7 @@ public class InitializeCorrespondenceContentExt
/// TODO: Length restriction?
/// </remarks>
[JsonPropertyName("messageSummary")]
public string MessageSummary { get; set; }
public required string MessageSummary { get; set; }

/// <summary>
/// Gets or sets a list of attachments.
Expand All @@ -41,7 +41,7 @@ public class InitializeCorrespondenceContentExt
/// TODO: Number restriction?
/// </remarks>
[JsonPropertyName("attachments")]
public List<InitializeCorrespondenceAttachmentExt> Attachments { get; set; }
public List<InitializeCorrespondenceAttachmentExt> Attachments { get; set; } = new List<InitializeCorrespondenceAttachmentExt>();

/// <summary>
/// Ids of the attachments that are to be included in the correspondence.
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class InitializeCorrespondenceExt
/// The correspondence content. Contains information about the Correspondence body, subject etc.
/// </summary>
[JsonPropertyName("content")]
public InitializeCorrespondenceContentExt Content { get; set; }
public InitializeCorrespondenceContentExt? Content { get; set; }

/// <summary>
/// When the correspondence should become visible to the recipient.
Expand Down Expand Up @@ -90,14 +90,14 @@ public class InitializeCorrespondenceExt
/// Options for how the recipient can reply to the correspondence
/// </summary>
[JsonPropertyName("replyOptions")]
public List<CorrespondenceReplyOptionExt>? ReplyOptions { get; set; }
public List<CorrespondenceReplyOptionExt> ReplyOptions { get; set; } = new List<CorrespondenceReplyOptionExt>();

/// <summary>
/// Notifications directly related to this Correspondence.
/// </summary>
[JsonPropertyName("notifications")]
[MaxLength(6, ErrorMessage = "Notifications can contain at most 6 notifcations")]
public List<InitializeCorrespondenceNotificationExt>? Notifications { get; set; }
public List<InitializeCorrespondenceNotificationExt> Notifications { get; set; } = new List<InitializeCorrespondenceNotificationExt>();

/// <summary>
/// Specifies whether the correspondence can override reservation against digital comminication in KRR
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class InitializeCorrespondenceNotificationExt
/// Reminders sent after 14 days if Correspondence not confirmed
/// </remarks>
[JsonPropertyName("notificationTemplate")]
public string NotificationTemplate { get; set; }
public required string NotificationTemplate { get; set; }

/// <summary>
/// Single custom text token that can be inserted into the notification template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ namespace Altinn.Correspondence.API.Models
public class NotificationStatusEventExt
{
/// <summary>
/// Notificatipn Status code
/// Notification Status code
/// </summary>
[JsonPropertyName("status")]
public string Status { get; set; }
public required string Status { get; set; }

/// <summary>
/// Notification Status Text description
/// </summary>
[JsonPropertyName("statusText")]
public string StatusText { get; set; } = string.Empty;
public required string StatusText { get; set; }

/// <summary>
/// Timestamp for when this Correspondence Status Event occurred
/// </summary>
[JsonPropertyName("statusChanged")]
public DateTimeOffset StatusChanged { get; set; }
public required DateTimeOffset StatusChanged { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ public GetAttachmentDetailsCommandHandler(IAttachmentStatusRepository attachment
public async Task<OneOf<GetAttachmentDetailsCommandResponse, Error>> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public GetAttachmentOverviewCommandHandler(IAttachmentStatusRepository attachmen
public async Task<OneOf<GetAttachmentOverviewCommandResponse, Error>> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 7cf2121

Please sign in to comment.