Skip to content

Commit

Permalink
update regex on routes to take care of leading 0, update renaming of …
Browse files Browse the repository at this point in the history
…top_project_conrtibutions param for easier follow flow/readability
  • Loading branch information
yuenmichelle1 committed Jul 25, 2023
1 parent b023a81 commit 3c30f64
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/user_classification_count_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def sanitize_params

def serializer_opts_from_params
{ period: params[:period],
show_time_spent: params[:time_spent],
time_spent: params[:time_spent],
top_project_contributions: params[:top_project_contributions] }
end

Expand Down
7 changes: 3 additions & 4 deletions app/serializers/user_classification_counts_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ def initialize(counts_scope)

def as_json(options)
serializer_options = options[:serializer_options]
show_time_spent = serializer_options[:show_time_spent]
num_top_projects_to_show = serializer_options[:top_project_contributions]
show_time_spent = serializer_options[:time_spent]
total_count = user_classification_counts.sum(&:count).to_i
response = { total_count: }
calculate_time_spent(user_classification_counts, response) if show_time_spent
show_proj_contributions(response, num_top_projects_to_show) if num_top_projects_to_show
response[:data] = response_data(user_classification_counts, num_top_projects_to_show, show_time_spent) if serializer_options[:period]
show_proj_contributions(response, serializer_options[:top_project_contributions]) if serializer_options[:top_project_contributions]
response[:data] = response_data(user_classification_counts, serializer_options[:top_project_contributions], show_time_spent) if serializer_options[:period]
response
end

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
post 'kinesis', to: 'kinesis#create'

get '/comments', action: :query, controller: 'comment_count'
get '/classifications/users/:id', action: :query, controller: 'user_classification_count', constraints: { id: /[1-9]\d*/ }
get '/classifications/users/:id', action: :query, controller: 'user_classification_count', constraints: { id: /\d+/ }
get '/classifications', action: :query, controller: 'classification_count'
# get '/classifications/user_groups/:id, action: :query_by_user_group, controller: 'user_group_classification_count'
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
expect(serialized[:total_count]).to eq(user_classification_count.count)
end

it 'returns total_count & time_spent if show_time_spent is true' do
serialized = count_serializer.as_json(serializer_options: { show_time_spent: true })
it 'returns total_count & time_spent if time_spent is true' do
serialized = count_serializer.as_json(serializer_options: { time_spent: true })
expect(serialized).to have_key(:total_count)
expect(serialized).to have_key(:time_spent)
expect(serialized[:time_spent]).to eq(user_classification_count.session_time)
Expand All @@ -42,7 +42,7 @@
count2 = build(:daily_user_project_classification_count)
classification_counts = [user_classification_count, count2]
serializer = described_class.new(classification_counts)
serialized = serializer.as_json(serializer_options: { show_time_spent: true })
serialized = serializer.as_json(serializer_options: { time_spent: true })
expect(serialized[:time_spent]).to eq(classification_counts.sum(&:session_time))
end

Expand Down Expand Up @@ -94,7 +94,7 @@
end

it 'shows response data with session_times bucketed by period' do
serialized = serializer.as_json(serializer_options: { top_project_contributions: 10, period: 'day', show_time_spent: true })
serialized = serializer.as_json(serializer_options: { top_project_contributions: 10, period: 'day', time_spent: true })
expect(serialized[:data].length).to eq(2)
expect(serialized[:data][0][:session_time]).to eq(user_diff_period_classification_count.session_time)
expect(serialized[:data][1][:session_time]).to eq(user_classification_count.session_time + user_diff_proj_count.session_time)
Expand Down

0 comments on commit 3c30f64

Please sign in to comment.