Commit 8fe68e885c20effb56179c25fb9e92e39a45481f
1 parent
3b69b25a
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
API: Adding endpoint followed by me
Showing
4 changed files
with
10 additions
and
5 deletions
Show diff stats
app/models/person.rb
| @@ -4,7 +4,7 @@ class Person < Profile | @@ -4,7 +4,7 @@ class Person < Profile | ||
| 4 | attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, | 4 | attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, |
| 5 | :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, | 5 | :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, |
| 6 | :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, | 6 | :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, |
| 7 | - :custom_area_of_study, :professional_activity, :organization_website, :following_articiles | 7 | + :custom_area_of_study, :professional_activity, :organization_website, :following_articles |
| 8 | 8 | ||
| 9 | SEARCH_FILTERS = { | 9 | SEARCH_FILTERS = { |
| 10 | :order => %w[more_recent more_popular more_active], | 10 | :order => %w[more_recent more_popular more_active], |
| @@ -89,7 +89,7 @@ class Person < Profile | @@ -89,7 +89,7 @@ class Person < Profile | ||
| 89 | 89 | ||
| 90 | #Article followers relation | 90 | #Article followers relation |
| 91 | has_many :article_followers, :dependent => :destroy | 91 | has_many :article_followers, :dependent => :destroy |
| 92 | - has_many :following_articiles, :class_name => 'Article', :through => :article_followers, :source => :article | 92 | + has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article |
| 93 | 93 | ||
| 94 | has_many :friendships, :dependent => :destroy | 94 | has_many :friendships, :dependent => :destroy |
| 95 | has_many :friends, :class_name => 'Person', :through => :friendships | 95 | has_many :friends, :class_name => 'Person', :through => :friendships |
lib/noosfero/api/helpers.rb
| @@ -97,8 +97,8 @@ require 'grape' | @@ -97,8 +97,8 @@ require 'grape' | ||
| 97 | present article, :with => Entities::Article, :fields => params[:fields] | 97 | present article, :with => Entities::Article, :fields => params[:fields] |
| 98 | end | 98 | end |
| 99 | 99 | ||
| 100 | - def present_articles(asset) | ||
| 101 | - articles = find_articles(asset) | 100 | + def present_articles(asset, method = 'articles') |
| 101 | + articles = find_articles(asset, method) | ||
| 102 | articles = paginate articles | 102 | articles = paginate articles |
| 103 | present articles, :with => Entities::Article, :fields => params[:fields] | 103 | present articles, :with => Entities::Article, :fields => params[:fields] |
| 104 | end | 104 | end |
lib/noosfero/api/v1/articles.rb
| @@ -25,6 +25,11 @@ module Noosfero | @@ -25,6 +25,11 @@ module Noosfero | ||
| 25 | present_articles(environment) | 25 | present_articles(environment) |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | + desc "Return the articles followed by me" | ||
| 29 | + get 'followed_by_me' do | ||
| 30 | + present_articles(current_person, 'following_articles') | ||
| 31 | + end | ||
| 32 | + | ||
| 28 | desc "Return the article id" | 33 | desc "Return the article id" |
| 29 | get ':id' do | 34 | get ':id' do |
| 30 | present_article(environment) | 35 | present_article(environment) |
test/unit/article_follower_test.rb
| @@ -72,7 +72,7 @@ class ArticleFollowerTest < ActiveSupport::TestCase | @@ -72,7 +72,7 @@ class ArticleFollowerTest < ActiveSupport::TestCase | ||
| 72 | article_follower.person = p1 | 72 | article_follower.person = p1 |
| 73 | article_follower.save! | 73 | article_follower.save! |
| 74 | 74 | ||
| 75 | - assert_equal p1.following_articiles.size, 2 | 75 | + assert_equal p1.following_articles.size, 2 |
| 76 | end | 76 | end |
| 77 | 77 | ||
| 78 | 78 |