Skip to content
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

Ordering #10

Closed
blakechambers opened this issue Mar 26, 2015 · 1 comment
Closed

Ordering #10

blakechambers opened this issue Mar 26, 2015 · 1 comment

Comments

@blakechambers
Copy link
Owner

Ordering

While json api does support sorting, it's version is more specific to providing something flexible for all types of sorting and ordering.

While this is nice, in a production system (and certainly for public apis) locking down the ordering to some named that can be managed server-side is a little more realistic. This becomes more important when using named indices in the database, especially with larger datasets.

That said, we should consider a lighter weight ordering syntax, that can match 1-to-1 with any indexed sets you want to provide.

Here's an example syntax of what's being proposed:

class Article
  include Mongoid::Document
  include Mongoid::Timestamps

  field :title
  field :number_of_comments

  belongs_to :author
end

class ArticlesController < ApplicationController
  include Matterhorn::Ordering

  allow_order 'oldest', :created_at.asc
  allow_order 'recent', :created_at.desc

  # first ordered by number_of_comments, then created_at
  allow_order 'most_comments', :number_of_comments.desc, :created_at.desc

  default_order 'oldest'
end

Controller methods

  • allow_order - creates a named order. In the above example should pass directly to mongoids sorting on collections. Reserve the keyword 'none', in the future we can add order=none to override default_order
  • default_order - specifies which order will be chosen when the order param is not requested

Serialization

Order should be merged into the request env and passed down the chain until it gets interpreted during serialization.

Links

When using ordering, Links should be added for the different named orders. For example, the above controller should add links as such:

GET /articles.json

{
  "orders": {
    "oldest" : "http://example.org/articles?order=oldest",
    "recent" : "http://example.org/articles?order=recent",
  },
  ...

This should allow sorting to be implemented and used alongside ordering in future versions.

@blakechambers blakechambers added this to the 0.1.0 - Initial release milestone Mar 26, 2015
@blakechambers blakechambers self-assigned this Apr 6, 2015
@blakechambers blakechambers removed their assignment Apr 22, 2015
@blakechambers
Copy link
Owner Author

closed by #56

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

No branches or pull requests

1 participant