From 8fe68e885c20effb56179c25fb9e92e39a45481f Mon Sep 17 00:00:00 2001 From: Caio Almeida Date: Wed, 12 Aug 2015 21:19:38 -0300 Subject: [PATCH] API: Adding endpoint followed by me --- app/models/person.rb | 4 ++-- lib/noosfero/api/helpers.rb | 4 ++-- lib/noosfero/api/v1/articles.rb | 5 +++++ test/unit/article_follower_test.rb | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index a16a9e4..db9125d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -4,7 +4,7 @@ class Person < Profile attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, - :custom_area_of_study, :professional_activity, :organization_website, :following_articiles + :custom_area_of_study, :professional_activity, :organization_website, :following_articles SEARCH_FILTERS = { :order => %w[more_recent more_popular more_active], @@ -89,7 +89,7 @@ class Person < Profile #Article followers relation has_many :article_followers, :dependent => :destroy - has_many :following_articiles, :class_name => 'Article', :through => :article_followers, :source => :article + has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article has_many :friendships, :dependent => :destroy has_many :friends, :class_name => 'Person', :through => :friendships diff --git a/lib/noosfero/api/helpers.rb b/lib/noosfero/api/helpers.rb index c3850db..63c6f72 100644 --- a/lib/noosfero/api/helpers.rb +++ b/lib/noosfero/api/helpers.rb @@ -97,8 +97,8 @@ require 'grape' present article, :with => Entities::Article, :fields => params[:fields] end - def present_articles(asset) - articles = find_articles(asset) + def present_articles(asset, method = 'articles') + articles = find_articles(asset, method) articles = paginate articles present articles, :with => Entities::Article, :fields => params[:fields] end diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index 393f0f2..486b6e7 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -25,6 +25,11 @@ module Noosfero present_articles(environment) end + desc "Return the articles followed by me" + get 'followed_by_me' do + present_articles(current_person, 'following_articles') + end + desc "Return the article id" get ':id' do present_article(environment) diff --git a/test/unit/article_follower_test.rb b/test/unit/article_follower_test.rb index dcafd96..237aecb 100644 --- a/test/unit/article_follower_test.rb +++ b/test/unit/article_follower_test.rb @@ -72,7 +72,7 @@ class ArticleFollowerTest < ActiveSupport::TestCase article_follower.person = p1 article_follower.save! - assert_equal p1.following_articiles.size, 2 + assert_equal p1.following_articles.size, 2 end -- libgit2 0.21.2