Biarity / Sieve

⚗️ Clean & extensible Sorting, Filtering, and Pagination for ASP.NET Core
Other
1.2k stars 132 forks source link

Question: Including related data and data shaping functionalities #10

Open bpkinez opened 6 years ago

bpkinez commented 6 years ago

Hi,

thanks for great library. Do you have plans on extending library with 2 addidtional common functionalities that robust REST API should implement:
1) Including related data. E.g., we have Post.cs class with related property Comments and by default related properties are not sent in JSON response to reduce payload data:

Post.cs

public int Id { get; set; }

[Sieve(CanFilter = true, CanSort = true)]
public string Title { get; set; }

[Sieve(CanFilter = true, CanSort = true)]
public int LikeCount { get; set; }

[Sieve(CanFilter = true, CanSort = true)]
public int CommentCount { get; set; }

[Sieve(CanFilter = true, CanSort = true, Name = "created")]
public DateTimeOffset DateCreated { get; set; } = DateTimeOffset.UtcNow;

// related data
public ICollection<Comment> Comments { get; set; } = new List<Comment>();

Comment.cs

public int Id { get; set; }
public string Title { get; set; }
public string Message { get; set; }
public string CommenterName { get; set; }
public DateTimeOffset DateCreated { get; set; } = DateTimeOffset.UtcNow;

and we want to include related data in results with request query string like:

GET /GetPosts

?sorts=     LikeCount,CommentCount,-created         // sort by likes, then comments, then descendingly by date created 
&filters=   LikeCount>10, Title@=awesome title,     // filter to posts with more than 10 likes, and a title that contains the phrase "awesome title"
&include=   Comments                                // include related data
&page=      1                                       // get the first page...
&pageSize=  10                                      // ...which contains 10 posts


2) Shape response data with fields that only we want to reduce payload data. E.g.:

GET /GetPosts

?sorts=     LikeCount,CommentCount,-created         // sort by likes, then comments, then descendingly by date created 
&filters=   LikeCount>10, Title@=awesome title,     // filter to posts with more than 10 likes, and a title that contains the phrase "awesome title"
&include=   Comments                                // include related data
&fields=    Id, Title, LikeCount                    // posts with only wanted fields
&page=      1                                       // get the first page...
&pageSize=  10                                      // ...which contains 10 posts
Biarity commented 6 years ago

I'll be eventually implementing relationships, links, and sparse fieldsets. The plan is to support most of the JSON API Spec in the future. Will keep you updated by referencing related commits in this issue. In the meantime, you can recreate most of this functionality via custom filters where needed.

a-patel commented 6 years ago

@Biarity , I also want similar kind of thing. This is very very nice library, thank for that.

BigNiceStef commented 5 years ago

@Biarity any news on implementing relationships? This library is very nice and I was wondering if you are about to implement it or if I should try to do it?

Thanks for the lib! :)

Biarity commented 5 years ago

@BigNiceStef Unfortunately I've been very busy lately so I don't think I can work on this anytime soon. Might try in a few months if someone hasn't submitted a PR already.

BigNiceStef commented 5 years ago

@BigNiceStef Unfortunately I've been very busy lately so I don't think I can work on this anytime soon. Might try in a few months if someone hasn't submitted a PR already.

Alrighty then, I'll give it a go! :)

emouawad commented 4 years ago

@BigNiceStef @bpkinez have u managed to find a way to do that?