wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
340 stars 130 forks source link

Enable pagination result with QueryResult<T> #257

Open marinasundstrom opened 3 years ago

marinasundstrom commented 3 years ago

This adds the ability to get the current Total and TotalPage in the result of a query, by adding the QueryResult<T> class.

I chose to go the easy way, similar to other places in the code, parse the headers of the last request, and put them and the resulting items into QueryResult<T>.

The QueryResult is a custom collection class that substitutes the use of IEnumerable<T> as return type for IQueryOperation<TClass, QClass>.Query(...). It implements IEnumerable<T> so enumeration will still be possible.

XML documentation TBA

I will remove the Test project

ThomasPe commented 2 years ago

Hey @marinasundstrom, so sorry for not looking at this any sooner! Are you still interested in getting this merged? @navjot50 any thoughts on this implementation?

navjot50 commented 2 years ago

Hi @ThomasPe I briefly worked on the post count feature and I have some draft code here https://github.com/navjot50/WordPressPCL/tree/feature-posts-count. Basically, here I didn't introduce a custom result but rather introduced a new interface ICountOperation with a GetCountAsync where the implementation sends a HEAD request which just returns response headers without any payload (lightweight request) and then it returns the value of X-WP-Total header. This will be the minimum solution.

However, since we can introduce breaking changes in release2.0 we can go also go with a more custom result depending on what the library users want the most.