Skip to content

Commit

Permalink
add history stats to info mobile api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vol1ura committed Jan 18, 2025
1 parent 1df2663 commit 684139a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion app/controllers/api/mobile/athletes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ module Mobile
class AthletesController < ApplicationController
before_action :find_athlete

def info; end
def info
@history_stats =
@athlete
.volunteering
.where(activity: { date: 5.months.ago.beginning_of_month.. })
.unscope(:order)
.group(:role, Arel.sql("date_part('month', date)"))
.count
.each_with_object({}) do |(k, v), h|
h[k.first] ||= Array.new(6, 0)
h[k.first][5 - ((Date.current.mon - k.last) % 12)] = v
end
end

private

Expand Down
5 changes: 4 additions & 1 deletion app/views/api/mobile/athletes/info.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
json.call(@athlete, :name, :male)
json.home_event @athlete.event&.name
json.volunteering do
json.stats @athlete.stats['volunteers']
json.stats do
json.general @athlete.stats['volunteers']
json.history @history_stats
end
json.scheduled(
@athlete
.volunteering
Expand Down

0 comments on commit 684139a

Please sign in to comment.