Skip to content

Commit

Permalink
Merge branch '97-add_endpoint_for_avg_number_of_days' into 97-average…
Browse files Browse the repository at this point in the history
…_number_of_days_db
  • Loading branch information
jbackfieldVA committed Apr 15, 2024
2 parents 6990d3f + 823a1e8 commit d5bc0e7
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/v0/average_days_for_claim_completion_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module V0
class AverageDaysForClaimCompletionController < ApplicationController
service_tag 'average-days-to-completion'
skip_before_action :authenticate, only: :index

def index
rtn = AverageDaysForClaimCompletion.order('created_at DESC').first
render json: {
average_days: rtn.present? ? rtn.average_days : -1.0
}
end
end
end
4 changes: 4 additions & 0 deletions app/models/average_days_for_claim_completion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class AverageDaysForClaimCompletion < ApplicationRecord
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
get 'claim_letters', to: 'claim_letters#index'
get 'claim_letters/:document_id', to: 'claim_letters#show'

get 'average_days_for_claim_completion', to: 'average_days_for_claim_completion#index'

get 'virtual_agent_claim_letters', to: 'virtual_agent_claim_letters#index'
get 'virtual_agent_claim_letters/:document_id', to: 'virtual_agent_claim_letters#show'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This migration comes from vye (originally 20240229184515)
class CreateAverageDaysForClaimCompletions < ActiveRecord::Migration[7.1]
def change
create_table :average_days_for_claim_completions do |t|
t.float average_days

t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe V0::AverageDaysForClaimCompletionController, type: :controller do
context 'when querying with nothing in db' do
it 'returns -1 for value' do
get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['average_days']).to eq(-1.0)
end
end

context 'when querying with record in db' do
before do
AverageDaysForClaimCompletion.create(average_days: 100)
end

it 'returns the value' do
get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['average_days']).to eq(100.0)
end
end

context 'when querying with multiple records in db' do
before do
AverageDaysForClaimCompletion.create(average_days: 100)
AverageDaysForClaimCompletion.create(average_days: 200)
AverageDaysForClaimCompletion.create(average_days: 300)
end

it 'returns the value' do
get :index
expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['average_days']).to eq(300.0)
end
end
end

0 comments on commit d5bc0e7

Please sign in to comment.