24 lines
662 B
Ruby
Raw Permalink Normal View History

2024-12-11 18:18:02 -03:00
# 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
2024-12-12 15:10:26 +01:00
option :user
option :date
2024-12-11 18:18:02 -03:00
def call
calendar =
Post
.where(user: user)
2024-12-12 15:10:26 +01:00
.where(created_at: date)
2024-12-11 18:18:02 -03:00
.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