forked from stringer-rss/stringer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstories_controller.rb
More file actions
48 lines (34 loc) · 1.09 KB
/
stories_controller.rb
File metadata and controls
48 lines (34 loc) · 1.09 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
require_relative "../repositories/story_repository"
require_relative "../commands/stories/mark_all_as_read"
class Stringer < Sinatra::Base
get "/news" do
@unread_stories = StoryRepository.unread
erb :index
end
get "/feed/:feed_id" do
@feed = FeedRepository.fetch(params[:feed_id])
@stories = StoryRepository.feed(params[:feed_id])
@unread_stories = @stories.find_all {|story| !story.is_read }
erb :feed
end
get "/archive" do
@read_stories = StoryRepository.read(params[:page])
erb :archive
end
get "/starred" do
@starred_stories = StoryRepository.starred(params[:page])
erb :starred
end
put "/stories/:id" do
json_params = JSON.parse(request.body.read, symbolize_names: true)
story = StoryRepository.fetch(params[:id])
story.is_read = !!json_params[:is_read]
story.keep_unread = !!json_params[:keep_unread]
story.is_starred = !!json_params[:is_starred]
StoryRepository.save(story)
end
post "/stories/mark_all_as_read" do
MarkAllAsRead.new(params[:story_ids]).mark_as_read
redirect to("/news")
end
end