mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-08-02 09:03:29 +00:00
24 lines
662 B
Ruby
24 lines
662 B
Ruby
# frozen_string_literal: true
|
|
|
|
# For a GitHub like calendar
|
|
# https://docs.github.com/assets/cb-35216/mw-1440/images/help/profile/contributions-graph.webp
|
|
module DiscourseRewind
|
|
class Rewind::Action::PostingCalendar < Service::ActionBase
|
|
option :user
|
|
option :date
|
|
|
|
def call
|
|
calendar =
|
|
Post
|
|
.where(user: user)
|
|
.where(created_at: date)
|
|
.select("DATE(created_at) as date, count(*) as count")
|
|
.group("DATE(created_at)")
|
|
.order("DATE(created_at)")
|
|
.map { |post| { date: post.date, count: post.count } }
|
|
|
|
{ data: calendar, identifier: "posting-calendar" }
|
|
end
|
|
end
|
|
end
|