[Git][noosfero/noosfero][api] 2 commits: api: avoid exception treatment case for every presentation
Rodrigo Souto
gitlab at gitlab.com
Tue Jun 23 12:15:34 BRT 2015
Rodrigo Souto pushed to branch api at Noosfero / noosfero
Commits:
991c68a4 by Rodrigo Souto at 2015-06-23T12:14:57Z
api: avoid exception treatment case for every presentation
- - - - -
0eba5453 by Rodrigo Souto at 2015-06-23T12:15:17Z
api: use where search on categories
- - - - -
2 changed files:
- lib/noosfero/api/entity.rb
- lib/noosfero/api/v1/categories.rb
Changes:
=====================================
lib/noosfero/api/entity.rb
=====================================
--- a/lib/noosfero/api/entity.rb
+++ b/lib/noosfero/api/entity.rb
@@ -6,9 +6,7 @@ class Noosfero::API::Entity < Grape::Entity
end
def self.represent(objects, options = {})
- if options[:is_inner_data]
- super objects, options
- else
+ if options[:has_exception]
data = super objects, options.merge(is_inner_data: true)
if objects.is_a? Exception
data.merge ok: false, error: {
@@ -18,6 +16,8 @@ class Noosfero::API::Entity < Grape::Entity
else
data.merge ok: true, error: { type: 'Success', message: '' }
end
+ else
+ super objects, options
end
end
=====================================
lib/noosfero/api/v1/categories.rb
=====================================
--- a/lib/noosfero/api/v1/categories.rb
+++ b/lib/noosfero/api/v1/categories.rb
@@ -11,7 +11,7 @@ module Noosfero
include_parent = params[:include_parent] == 'true'
include_children = params[:include_children] == 'true'
- categories = type.nil? ? environment.categories : environment.categories.find(:all, :conditions => {:type => type})
+ categories = type.nil? ? environment.categories : environment.categories.where(:type => type)
present categories, :with => Entities::Category, parent: include_parent, children: include_children
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/9efdcbd7c0888f533da6deee3aafc96264732f70...0eba5453a0cc705a912a9d88bade81ad76457f65
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150623/a0c8382e/attachment.html>
More information about the Noosfero-dev
mailing list