articles.rb
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module API
module V1
class Articles < Grape::API
before { authenticate! }
resource :articles do
#FIXME See if it's possible to use pagination instead of DateTime control. see a way to use this pagination logic genericaly
get do
first_update = DateTime.parse(params[:first_update]) if params[:first_update]
last_update = DateTime.parse(params[:last_update]) if params[:last_update]
if first_update.nil?
begin_date = Article.first.created_at
end_date = last_update.nil? ? DateTime.now : last_update
else
begin_date = first_update
end_date = DateTime.now
end
limit = params[:limit].to_i
limit = 20 if limit == 0
conditions = {}
conditions[:type] = params[:content_type] if params[:content_type] #FIXME validate type
conditions[:created_at] = begin_date...end_date
present Article.find(:all, :conditions => conditions, :offset => (first_update.nil? ? 0 : 1), :limit => limit, :order => "created_at DESC"), :with => Entities::Article
end
#FIXME load article with environment context
get ':id' do
present Article.find(params[:id]), :with => Entities::Article
end
#FIXME load article with environment context
get ':id/children' do
present Article.find(params[:id]).children, :with => Entities::Article
end
#FIXME load article with environment context
get ':id/children/:child_id' do
present Article.find(params[:id]).children.find(params[:child_id]), :with => Entities::Article
end
end
end
end
end