Commit d782d26ba04a20fac32968cce9472e906dfedfdd
1 parent
c279721d
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
API: adding tags endpoint
Showing
3 changed files
with
36 additions
and
0 deletions
Show diff stats
lib/noosfero/api/api.rb
@@ -45,6 +45,7 @@ module Noosfero | @@ -45,6 +45,7 @@ module Noosfero | ||
45 | mount V1::Enterprises | 45 | mount V1::Enterprises |
46 | mount V1::Categories | 46 | mount V1::Categories |
47 | mount V1::Tasks | 47 | mount V1::Tasks |
48 | + mount V1::Tags | ||
48 | mount V1::Environments | 49 | mount V1::Environments |
49 | mount Session | 50 | mount Session |
50 | 51 |
lib/noosfero/api/entities.rb
@@ -114,6 +114,11 @@ module Noosfero | @@ -114,6 +114,11 @@ module Noosfero | ||
114 | expose :type | 114 | expose :type |
115 | end | 115 | end |
116 | 116 | ||
117 | + class Tag < Entity | ||
118 | + root 'tags', 'tag' | ||
119 | + expose :name | ||
120 | + end | ||
121 | + | ||
117 | class Environment < Entity | 122 | class Environment < Entity |
118 | expose :name | 123 | expose :name |
119 | end | 124 | end |
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +module Noosfero | ||
2 | + module API | ||
3 | + module V1 | ||
4 | + class Tags < Grape::API | ||
5 | + before { authenticate! } | ||
6 | + | ||
7 | + resource :articles do | ||
8 | + | ||
9 | + resource ':id/tags' do | ||
10 | + | ||
11 | + get do | ||
12 | + article = find_article(environment.articles, params[:id]) | ||
13 | + present article.tag_list, :with => Entities::Tag | ||
14 | + end | ||
15 | + | ||
16 | + desc "Add a tag to an article" | ||
17 | + post do | ||
18 | + article = find_article(environment.articles, params[:id]) | ||
19 | + article.tag_list=params[:tags] | ||
20 | + article.save | ||
21 | + present article.tag_list, :with => Entities::Tag | ||
22 | + end | ||
23 | + | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + end | ||
28 | + end | ||
29 | + end | ||
30 | +end |