fixes to post/pool apis

This commit is contained in:
albert
2013-02-26 22:29:59 -08:00
parent 5bf22e9c67
commit 540d64682d
4 changed files with 34 additions and 0 deletions

View File

@@ -34,6 +34,9 @@ class PostQueryBuilder
when :lte
relation.where(["#{field} <= ?", arr[1]])
when :in
relation.where(["#{field} in (?)", arr[1]])
when :between
relation.where(["#{field} BETWEEN ? AND ?", arr[1], arr[2]])

View File

@@ -114,6 +114,10 @@ class Pool < ActiveRecord::Base
name.tr("_", " ")
end
def creator_name
User.id_to_name(creator_id)
end
def normalize_post_ids
self.post_ids = self.class.normalize_post_ids(post_ids)
end
@@ -237,4 +241,27 @@ class Pool < ActiveRecord::Base
@neighbor_posts = nil
clear_post_id_array
end
def to_xml(options = {}, &block)
# to_xml ignores the serializable_hash method
options ||= {}
options[:methods] = [:creator_name]
super(options, &block)
end
def serializable_hash(options = {})
return {
"created_at" => created_at,
"creator_id" => creator_id,
"creator_name" => creator_name,
"description" => description,
"id" => id,
"is_active" => is_active?,
"is_deleted" => is_deleted?,
"name" => name,
"post_count" => post_count,
"post_ids" => post_ids,
"updated_at" => updated_at
}
end
end

View File

@@ -817,6 +817,7 @@ class Post < ActiveRecord::Base
def to_xml(options = {}, &block)
# to_xml ignores the serializable_hash method
options ||= {}
options[:methods] = [:uploader_name]
options[:except] ||= []
options[:except] += hidden_attributes
super(options, &block)

View File

@@ -199,6 +199,9 @@ class Tag < ActiveRecord::Base
when /\A>(.+)/
return [:gt, parse_cast($1, type)]
when /,/
return [:in, range.split(/,/)]
else
return [:eq, parse_cast(range, type)]