2024-12-12 15:10:52 +01:00

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