Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use highest status instead of newest for legacy #509

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public async Task<OneOf<LegacyGetCorrespondencesResponse, Error>> Process(Legacy
ServiceOwnerName = String.IsNullOrWhiteSpace(correspondence.MessageSender) ? owner!.Name : correspondence.MessageSender,
InstanceOwnerPartyId = recipient?.PartyId ?? 0,
MessageTitle = correspondence.Content.MessageTitle,
Status = correspondence.GetLatestStatusWithoutPurged().Status,
Status = correspondence.GetHighestStatusWithoutPurged().Status,
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
CorrespondenceId = correspondence.Id,
MinimumAuthenticationLevel = (int)minAuthLevel,
Published = correspondence.Published,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task<OneOf<LegacyGetCorrespondenceOverviewResponse, Error>> Process
{
return Errors.LegacyNoAccessToCorrespondence;
}
var latestStatus = correspondence.GetLatestStatus();
var latestStatus = correspondence.GetHighestStatus();
if (latestStatus == null)
{
_logger.LogWarning("Latest status not found for correspondence");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ public static class CorrespondenceStatusExtensions
.OrderByDescending(s => s.StatusChanged).FirstOrDefault();
return statusEntity;
}
public static CorrespondenceStatusEntity? GetHighestStatus(this CorrespondenceEntity correspondence)
{
var statusEntity = correspondence.Statuses
.Where(s => s.Status != CorrespondenceStatus.Fetched)
.OrderByDescending(s => s.Status).FirstOrDefault();
return statusEntity;
}
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
public static CorrespondenceStatusEntity? GetHighestStatusWithoutPurged(this CorrespondenceEntity correspondence)
{
var statusEntity = correspondence.Statuses
.Where(s => !s.Status.IsPurged() && s.Status != CorrespondenceStatus.Fetched)
.OrderByDescending(s => s.Status).FirstOrDefault();
return statusEntity;
}
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
public static bool IsPurged(this CorrespondenceStatus correspondenceStatus)
{
return correspondenceStatus == CorrespondenceStatus.PurgedByRecipient || correspondenceStatus == CorrespondenceStatus.PurgedByAltinn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static IQueryable<CorrespondenceEntity> IncludeByStatuses(this IQueryable
}

return query
.Where(cs => statusesToFilter.Contains(cs.Statuses.OrderBy(cs => cs.StatusChanged).Last().Status));
.Where(cs => statusesToFilter.Contains(cs.Statuses.OrderBy(cs => cs.Status).Last().Status));
Andreass2 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Loading