Skip to content

RFC: Enhancements to ResourceDefintion #402

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
jaredcnance opened this issue Sep 11, 2018 · 0 comments
Closed

RFC: Enhancements to ResourceDefintion #402

jaredcnance opened this issue Sep 11, 2018 · 0 comments
Labels
enhancement RFC Request for comments. These issues have major impact on the direction of the library.

Comments

@jaredcnance
Copy link
Contributor

jaredcnance commented Sep 11, 2018

Description

The ResourceDefinition class exposes developer friendly hooks into how their resources are exposed. It is intended to improve the experience and reduce boilerplate for commonly required features.

As with the prior implementation, the ResourceDefinition will be resolved from the container and can accept any dependencies that have been registered.

Custom Filters

  • Introduce QueryFilters type which is just an "alias" to Dictionary in an attempt to improve DX
public class QueryFilters
  : Dictionary<string, Func<IQueryable<TEntity>, IQueryable<TEntity>>
{ }
  • The repository becomes responsible for loading the QueryFilters and applying them
  • Any keys present in the QueryFilters will not be applied using the default behavior

Example

public class FooResource : ResourceDefinition<Foo>
{
  protected override QueryFilters GetQueryFilters() => new QueryFilters { 
            { "key1", (query, value) => query.Select(x => x) },
            { "key2", (query, value) => query.Select(x => x) },
        };
}
 

Should be used to handle requests like:

/foos?filter[key1]=value1

Default Sort

Allow a resource to have a default sort if no sort key is provided.

  • Introduce PropertySortOrder type which is just an "alias" to ReadOnlyList in an attempt to improve DX
public class PropertySortOrder<T>
  : ReadOnlyList<(Expression<Func<T, dynamic>>, SortDirection)>
{ }
  • The repository becomes responsible for applying the default sort if no other sort has been requested

Example

public class FooResource : ResourceDefinition<Foo>
{
  public override PropertySortOrder<Foo> DefaultSortOrder = new { 
     (foo => foo.Bar, SortDirection.Ascending),
     (foo => foo.Baz, SortDirection.Descending),
  }
}
@jaredcnance jaredcnance added enhancement RFC Request for comments. These issues have major impact on the direction of the library. labels Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement RFC Request for comments. These issues have major impact on the direction of the library.
Development

No branches or pull requests

1 participant