API sorting improvements:

- Add endpoints for getting/updating sorting methods
- Results from library and title endpoints are now sorted
This commit is contained in:
Alex Ling
2022-03-22 10:46:38 +00:00
parent a5a7396edd
commit 7ecdb1c0dd
4 changed files with 116 additions and 11 deletions
+10 -3
View File
@@ -139,14 +139,21 @@ class Library
titles.flat_map &.deep_entries
end
def build_json(*, slim = false, depth = -1)
def build_json(*, slim = false, depth = -1, sort_context = nil)
JSON.build do |json|
json.object do
json.field "dir", @dir
json.field "titles" do
json.array do
self.titles.each do |title|
json.raw title.build_json(slim: slim, depth: depth)
_titles = if sort_context
sorted_titles sort_context[:username],
sort_context[:opt]
else
self.titles
end
_titles.each do |title|
json.raw title.build_json(slim: slim, depth: depth,
sort_context: sort_context)
end
end
end