add most viewed posts page
This commit is contained in:
17
app/logical/post_sets/most_viewed.rb
Normal file
17
app/logical/post_sets/most_viewed.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user