Skip to content

Question: GetDefaultSortOrder not firing #736

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

Closed
fdlane opened this issue May 10, 2020 · 4 comments · Fixed by #746
Closed

Question: GetDefaultSortOrder not firing #736

fdlane opened this issue May 10, 2020 · 4 comments · Fixed by #746

Comments

@fdlane
Copy link
Contributor

fdlane commented May 10, 2020

Description

In my ResourceDefinition I have two overrides, one for GetQueryFilters and one for GetDefaultSortOrder. For some reason, only the GetQueryFilter override fires.

My Postman request does not include any sort params.

Any ideas what I have done wrong here?

...

  public class ClientResource : ResourceDefinition<Client>
    {
      public ClientResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
      public override PropertySortOrder GetDefaultSortOrder() => new PropertySortOrder
      {
        (t => t.DisplayName, SortDirection.Ascending)
      };
      public override QueryFilters GetQueryFilters() => new QueryFilters
      {
        {
        "search",
        (items, filter) => items.Where(i => i.DisplayName.Contains(filter.Value))
        }
      };
    }

Environment

  • JsonApiDotNetCore Version: v4.0.0-alpha5
  • Other Relevant Package Versions: core 3.1
@bart-degreed
Copy link
Contributor

Hi @fdlane, thanks for asking. I don't think you did anything wrong, this looks like a bug.

The _queries field in SortService is initialized with an empty list here, so the null check here never succeeds, resulting in the if statement never being entered and thus the callback never getting fired.

@fdlane
Copy link
Contributor Author

fdlane commented May 11, 2020

Thanks for the fast response.

Change to...?

     if (_queries == null ||  _queries.Count == 0)

@bart-degreed
Copy link
Contributor

I would only check for empty, because the field can never be null.

@bart-degreed
Copy link
Contributor

But we should have a test that covers this, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants