Moved content array walker to Category#to_json

As requested by reviewer this change moves the content array walker from the API endpoint to the Category class.
This commit is contained in:
Frank de Lange 2021-10-12 16:04:24 +00:00
parent d37b69fb20
commit a8e3349577
2 changed files with 8 additions and 8 deletions

View File

@ -238,7 +238,13 @@ class Category
def to_json(locale, json : JSON::Builder)
json.object do
json.field "title", self.title
json.field "contents", self.contents
json.field "contents" do
json.array do
self.contents.each do |item|
item.to_json(locale, json)
end
end
end
end
end

View File

@ -36,13 +36,7 @@ module Invidious::Routes::API::V1::Search
JSON.build do |json|
json.array do
search_results.each do |item|
if item.is_a?(Category)
item.contents.each do |cat_item|
cat_item.to_json(locale, json)
end
else
item.to_json(locale, json)
end
item.to_json(locale, json)
end
end
end