Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Jan 13, 2025
1 parent 8fcac7e commit f7ec422
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 19 deletions.
31 changes: 29 additions & 2 deletions docs/schema/V1/schema.verified.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,24 @@ type SearchDialogForbidden implements SearchDialogError {
message: String!
}

"If more than one property is set, is bad."
type SearchDialogSortType {
createdAt: SortDirection
updatedAt: SortDirection
dueAt: SortDirection
}

type SearchDialogValidationError implements SearchDialogError {
message: String!
}

type SearchDialogsPayload {
items: [SearchDialog!]
hasNextPage: Boolean!
"Use this token to fetch the next page of dialogs, must be used in combination with OrderBy"
continuationToken: String
orderBy: String
"Use this OrderBy to fetch the next page of dialogs, must be used in combination with ContinuationToken"
orderBy: [SearchDialogSortType!]!
errors: [SearchDialogError!]!
}

Expand Down Expand Up @@ -294,8 +303,21 @@ input SearchDialogInput {
dueBefore: DateTime
"Search string for free text search. Will attempt to fuzzily match in all free text fields in the aggregate"
search: String
"Limit free text search to texts with this language code, e.g. 'no', 'en'. Culture codes will be normalized to neutral language codes (ISO 639). Default: search all culture codes"
"Limit free text search to texts with this language code, e.g. 'nb', 'en'. Culture codes will be normalized to neutral language codes (ISO 639). Default: search all culture codes"
searchLanguageCode: String
"Limit the number of results returned, defaults to 100, max 1000"
limit: Int
"Continuation token for pagination"
continuationToken: String
"Sort the results by one or more fields"
orderBy: [SearchDialogSortTypeInput!]
}

"If more than one property is set, is bad."
input SearchDialogSortTypeInput {
createdAt: SortDirection
updatedAt: SortDirection
dueAt: SortDirection
}

input SetSystemLabelInput {
Expand Down Expand Up @@ -374,6 +396,11 @@ enum HttpVerb {
CONNECT
}

enum SortDirection {
ASC
DESC
}

enum SystemLabel {
DEFAULT
BIN
Expand Down
16 changes: 1 addition & 15 deletions src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<SearchDialogsPayload> SearchDialogs(
OrderSet<SearchDialogQueryOrderDefinition, IntermediateDialogDto>? orderSet = null;
if (input.OrderBy != null && !input.OrderBy.TryToOrderSet(out orderSet))
{
// error
// error, how can this happen?
}

searchDialogQuery.OrderBy = orderSet;
Expand All @@ -58,17 +58,3 @@ public async Task<SearchDialogsPayload> SearchDialogs(
forbidden => new SearchDialogsPayload { Errors = [new SearchDialogForbidden()] });
}
}

[GraphQLDescription("If more than one property is set, is bad.")]
public sealed class SearchDialogSortType
{
public SortDirection? CreatedAt { get; set; }
public SortDirection? UpdatedAt { get; set; }
public SortDirection? DueAt { get; set; }
}

public enum SortDirection
{
ASC,
DESC
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ public sealed class SearchDialogsPayload
public List<ISearchDialogError> Errors { get; set; } = [];
}

[GraphQLDescription("If more than one property is set, is bad.")]
public sealed class SearchDialogSortType
{
public SortDirection? CreatedAt { get; set; }
public SortDirection? UpdatedAt { get; set; }
public SortDirection? DueAt { get; set; }
}

public enum SortDirection
{
Asc,
Desc
}

public sealed class SearchDialog
{
public Guid Id { get; set; }
Expand Down Expand Up @@ -128,10 +142,43 @@ public sealed class SearchDialogInput

internal static class SearchDialogSortTypeExtensions
{
public static List<SearchDialogSortType> ToSearchDialogSortTypeList(
this string orderBy)
{
List<SearchDialogSortType> searchDialogSortTypes = [];
var orderByParts = orderBy.Split(',');
// updatedAt_desc,dueAt_asc,

foreach (var orderByPart in orderByParts)
{
var parts = orderByPart.Split('_');
if (parts.Length != 2)
{
continue;
}

var sortDirection = parts[1] switch
{
"Asc" => SortDirection.Asc,
"Desc" => SortDirection.Desc,
_ => throw new ArgumentOutOfRangeException()
};

searchDialogSortTypes.Add(parts[0] switch
{
"createdAt" => new SearchDialogSortType { CreatedAt = sortDirection },
"updatedAt" => new SearchDialogSortType { UpdatedAt = sortDirection },
"dueAt" => new SearchDialogSortType { DueAt = sortDirection },
_ => throw new ArgumentOutOfRangeException()
});
}

return searchDialogSortTypes;
}

public static bool TryToOrderSet(this List<SearchDialogSortType> searchDialogSortTypes,
out OrderSet<SearchDialogQueryOrderDefinition, IntermediateDialogDto>? orderSet)
{

var stringBuilder = new StringBuilder();
foreach (var orderBy in searchDialogSortTypes)
{
Expand Down Expand Up @@ -162,5 +209,4 @@ public static bool TryToOrderSet(this List<SearchDialogSortType> searchDialogSor
orderSet = null;
return false;
}

}

0 comments on commit f7ec422

Please sign in to comment.