add most viewed posts page

This commit is contained in:
r888888888
2017-11-10 16:21:01 -08:00
parent 6c4eb62957
commit 8b1fca4662
8 changed files with 109 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
module PostSets
class MostViewed < PostSets::Base
attr_reader :date
def initialize(date)
@date = date.blank? ? Time.zone.now : Time.zone.parse(date)
end
def posts
@posts ||= PostViewCountService.new.popular_posts(date)
end
def presenter
::PostSetPresenters::MostViewed.new(self)
end
end
end

View File

@@ -4,7 +4,7 @@ class PostViewCountService
end
def initialize
if !MissedSearchService.enabled?
if !PostViewCountService.enabled?
raise NotImplementedError.new("the Reportbooru service isn't configured. Missed searches are not available.")
end
end
@@ -30,4 +30,9 @@ class PostViewCountService
rescue JSON::ParserError
nil
end
def popular_posts(date = Date.today)
ranking = fetch_rank(date)
ranking.map {|x| Post.find(x[0])}
end
end