diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 6b11c39..fc00819 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -46,6 +46,19 @@ module API end end + + def make_conditions_with_parameter(params = {}) + conditions = {} + from_date = DateTime.parse(params[:from]) if params[:from] + until_date = DateTime.parse(params[:until]) if params[:until] + + conditions[:type] = parse_content_type(params[:content_type]) unless params[:content_type].nil? + + conditions[:created_at] = period(from_date, until_date) + + conditions + end + #FIXME see if its needed # def paginate(relation) # per_page = params[:per_page].to_i diff --git a/lib/api/v1/articles.rb b/lib/api/v1/articles.rb index 4234d77..3f5487c 100644 --- a/lib/api/v1/articles.rb +++ b/lib/api/v1/articles.rb @@ -19,16 +19,13 @@ module API # :params => API::Entities::Article.documentation # } get do - from_date = DateTime.parse(params[:from]) if params[:from] - until_date = DateTime.parse(params[:until]) if params[:until] - - conditions = {} #FIXME remove this line when hub be implemented - params[:content_type] = 'Folder' if params[:content_type].downcase == 'hub' + params[:content_type] = 'Folder' if ((params[:content_type].nil? ? '' : params[:content_type].downcase) == 'hub') + params[:content_type] = 'Folder' if ((params[:content_type].nil? ? '' : params[:content_type]) == 'CommunityHubPlugin::Hub') + + conditions = make_conditions_with_parameter(params) - conditions[:type] = parse_content_type(params[:content_type]) - conditions[:created_at] = period(from_date, until_date) if params[:reference_id] articles = environment.articles.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") else @@ -46,9 +43,7 @@ module API from_date = DateTime.parse(params[:from]) if params[:from] until_date = DateTime.parse(params[:until]) if params[:until] - conditions = {} - conditions[:type] = parse_content_type(params[:content_type]) - conditions[:created_at] = period(from_date, until_date) + conditions = make_conditions_with_parameter(params) if params[:reference_id] articles = environment.articles.find(params[:id]).children.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") else diff --git a/lib/api/v1/comments.rb b/lib/api/v1/comments.rb index 166c870..76509b9 100644 --- a/lib/api/v1/comments.rb +++ b/lib/api/v1/comments.rb @@ -16,11 +16,9 @@ module API # Example Request: # GET /articles/12/comments?oldest&limit=10&reference_id=23 get ":id/comments" do - from_date = DateTime.parse(params[:from]) if params[:from] - until_date = DateTime.parse(params[:until]) if params[:until] - conditions = {} - conditions[:created_at] = period(from_date, until_date) + conditions = make_conditions_with_parameter(params) + if params[:reference_id] comments = environment.articles.find(params[:id]).comments.send("#{params.key?(:oldest) ? 'older_than' : 'newer_than'}", params[:reference_id]).find(:all, :conditions => conditions, :limit => limit, :order => "created_at DESC") else -- libgit2 0.21.2