2024-12-07 17:30:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
module ::DiscourseRewind
|
|
|
|
|
class RewindsController < ::ApplicationController
|
|
|
|
|
requires_plugin PLUGIN_NAME
|
|
|
|
|
|
2025-01-13 18:17:02 +01:00
|
|
|
requires_login
|
|
|
|
|
|
2025-11-26 15:12:59 -03:00
|
|
|
def index
|
2025-01-20 16:50:51 +01:00
|
|
|
DiscourseRewind::FetchReports.call(service_params) do
|
2025-11-19 09:36:08 +10:00
|
|
|
on_model_not_found(:year) do
|
|
|
|
|
raise Discourse::NotFound.new(nil, custom_message: "discourse_rewind.invalid_year")
|
|
|
|
|
end
|
|
|
|
|
on_model_not_found(:reports) do
|
|
|
|
|
raise Discourse::NotFound.new(nil, custom_message: "discourse_rewind.report_failed")
|
|
|
|
|
end
|
2025-11-26 15:12:59 -03:00
|
|
|
on_success do |reports:, total_available:|
|
|
|
|
|
render json: { reports: reports, total_available: total_available }, status: :ok
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
DiscourseRewind::FetchReport.call(service_params) do
|
|
|
|
|
on_model_not_found(:year) do
|
|
|
|
|
raise Discourse::NotFound.new(nil, custom_message: "discourse_rewind.invalid_year")
|
|
|
|
|
end
|
|
|
|
|
on_model_not_found(:report_class) do
|
|
|
|
|
raise Discourse::NotFound.new(
|
|
|
|
|
nil,
|
|
|
|
|
custom_message: "discourse_rewind.invalid_report_index",
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
on_model_not_found(:report) do
|
|
|
|
|
raise Discourse::NotFound.new(nil, custom_message: "discourse_rewind.report_failed")
|
|
|
|
|
end
|
|
|
|
|
on_success { |report:| render json: { report: report }, status: :ok }
|
2024-12-07 18:40:23 +01:00
|
|
|
end
|
2024-12-07 17:30:25 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|