1# frozen_string_literal: true 2 3module API 4 module Entities 5 class IssuableTimeStats < Grape::Entity 6 format_with(:time_tracking_formatter) do |time_spent| 7 Gitlab::TimeTrackingFormatter.output(time_spent) 8 end 9 10 expose :time_estimate 11 expose :total_time_spent 12 expose :human_time_estimate 13 14 with_options(format_with: :time_tracking_formatter) do 15 expose :total_time_spent, as: :human_total_time_spent 16 end 17 18 # rubocop: disable CodeReuse/ActiveRecord 19 def total_time_spent 20 # Avoids an N+1 query since timelogs are preloaded 21 object.timelogs.map(&:time_spent).sum 22 end 23 # rubocop: enable CodeReuse/ActiveRecord 24 end 25 end 26end 27