Sieve icon indicating copy to clipboard operation
Sieve copied to clipboard

Question: Including related data and data shaping functionalities

Open bpkinez opened this issue 6 years ago • 6 comments

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

bpkinez avatar Feb 14 '18 15:02 bpkinez

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.

Biarity avatar Feb 15 '18 05:02 Biarity

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

a-patel avatar Mar 17 '18 16:03 a-patel

@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! :)

BigNiceStef avatar Aug 07 '19 18:08 BigNiceStef

@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.

Biarity avatar Aug 07 '19 22:08 Biarity

@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! :)

BigNiceStef avatar Aug 07 '19 23:08 BigNiceStef

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

emouawad avatar Jan 03 '20 10:01 emouawad