Commit 38750cc9c000ee22a5d460f358125ecb3b3023b6

Authored by Gabriela Navarro
1 parent d79c2285
Exists in master

Add articles on the JSON.

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
controllers/colab_integration_plugin_controller.rb
1 class ColabIntegrationPluginController < ApplicationController 1 class ColabIntegrationPluginController < ApplicationController
2 def index 2 def index
3 - render json: { 3 + data = {
4 "total" => environment.profiles.count, 4 "total" => environment.profiles.count,
5 - "profiles" =>  
6 - environment.profiles.each do |profile|  
7 - profile.attr_to_json  
8 - end  
9 - }.to_json 5 + "profiles" => []
  6 + }
  7 +
  8 + environment.profiles.each do |profile|
  9 + data["profiles"] << profile.attr_to_json
  10 + end
  11 +
  12 + render json: data.to_json
10 end 13 end
11 end 14 end
lib/ext/article.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +require_dependency "article"
  2 +
  3 +class Article
  4 + def attr_to_json
  5 + {
  6 + "type" => self.type,
  7 + "data" => {
  8 + "id" => self.id,
  9 + "parent_id" => self.parent_id,
  10 + "title" => self.title,
  11 + "body" => self.body,
  12 + "path" => self.path,
  13 + "slug" => self.slug,
  14 + "published" => self.published,
  15 + "show_to_followers" => self.show_to_followers,
  16 + "author_id" => self.author_id
  17 + }
  18 + }
  19 + end
  20 +end
lib/ext/profile.rb
@@ -2,19 +2,21 @@ require_dependency &#39;profile&#39; @@ -2,19 +2,21 @@ require_dependency &#39;profile&#39;
2 2
3 class Profile 3 class Profile
4 def attr_to_json 4 def attr_to_json
5 - { 5 + attrs = {
6 "type" => "#{self.type}", 6 "type" => "#{self.type}",
7 "data" => { 7 "data" => {
8 "id" => "#{self.id}", 8 "id" => "#{self.id}",
9 "identifier" => "#{self.identifier}", 9 "identifier" => "#{self.identifier}",
10 "name" => "#{self.name}", 10 "name" => "#{self.name}",
11 "description" => "#{self.description}" 11 "description" => "#{self.description}"
12 - },  
13 - # "articles" => [  
14 - # self.articles.each do |article|  
15 - # { article.attr_to_json }  
16 - # end  
17 - # ]  
18 - }.to_json 12 + }
  13 + }
  14 +
  15 + attrs['articles'] = []
  16 + self.articles.each do |article|
  17 + attrs['articles'] << article.attr_to_json
  18 + end
  19 +
  20 + attrs
19 end 21 end
20 end 22 end