Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Jan 14, 2025
1 parent 8f442cf commit a6518b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public SearchDialogInputValidator()
.When(x => x.OrderBy != null);

RuleForEach(x => x.OrderBy)
.Must(order => order.CreatedAt.HasValue ^ order.UpdatedAt.HasValue ^ order.DueAt.HasValue)
.Must(order =>
new[] { order.CreatedAt.HasValue, order.UpdatedAt.HasValue, order.DueAt.HasValue }
.Count(x => x) == 1)
.WithMessage("Exactly one property must be set on each OrderBy object.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public static List<SearchDialogSortType> ToSearchDialogSortTypeList(
{
List<SearchDialogSortType> searchDialogSortTypes = [];

orderBy = orderBy
var orderByParts = orderBy
.ToLower(CultureInfo.InvariantCulture)
.Replace("id_desc", "", StringComparison.OrdinalIgnoreCase)
.Replace("id_asc", "", StringComparison.OrdinalIgnoreCase);
.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Where(part => !part.Equals("id_desc", StringComparison.OrdinalIgnoreCase) &&
!part.Equals("id_asc", StringComparison.OrdinalIgnoreCase))
.ToList();

foreach (var orderByPart in orderBy.Split(','))
foreach (var orderByPart in orderByParts)
{
var parts = orderByPart.Split('_');
if (parts.Length != 2)
Expand Down Expand Up @@ -55,11 +57,13 @@ public static bool TryToOrderSet(this List<SearchDialogSortType> searchDialogSor
stringBuilder.Append(CultureInfo.InvariantCulture, $"createdAt_{orderBy.CreatedAt},");
continue;
}

if (orderBy.UpdatedAt != null)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $"updatedAt_{orderBy.UpdatedAt},");
continue;
}

if (orderBy.DueAt != null)
{
stringBuilder.Append(CultureInfo.InvariantCulture, $"dueAt_{orderBy.DueAt},");
Expand Down

0 comments on commit a6518b8

Please sign in to comment.