From 6927687c90d50b76916afddf308ca620b3962071 Mon Sep 17 00:00:00 2001 From: Joshua Backfield Date: Thu, 11 Apr 2024 22:48:09 -0400 Subject: [PATCH 1/2] 97 Added database table and endpoint for average number of days for claim completion. --- .../average_days_for_claim_completion_controller.rb | 13 +++++++++++++ app/models/average_days_for_claim_completion.rb | 2 ++ config/routes.rb | 2 ++ ...944_create_average_days_for_claim_completions.rb | 10 ++++++++++ db/schema.rb | 8 +++++++- 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/controllers/v0/average_days_for_claim_completion_controller.rb create mode 100644 app/models/average_days_for_claim_completion.rb create mode 100644 db/migrate/20240411153944_create_average_days_for_claim_completions.rb diff --git a/app/controllers/v0/average_days_for_claim_completion_controller.rb b/app/controllers/v0/average_days_for_claim_completion_controller.rb new file mode 100644 index 00000000000..d0f92a9b7aa --- /dev/null +++ b/app/controllers/v0/average_days_for_claim_completion_controller.rb @@ -0,0 +1,13 @@ +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 diff --git a/app/models/average_days_for_claim_completion.rb b/app/models/average_days_for_claim_completion.rb new file mode 100644 index 00000000000..988d752beb8 --- /dev/null +++ b/app/models/average_days_for_claim_completion.rb @@ -0,0 +1,2 @@ +class AverageDaysForClaimCompletion < ApplicationRecord +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ebf6efc99a0..f04c3f86e30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -148,6 +148,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' diff --git a/db/migrate/20240411153944_create_average_days_for_claim_completions.rb b/db/migrate/20240411153944_create_average_days_for_claim_completions.rb new file mode 100644 index 00000000000..ffb9a46abdb --- /dev/null +++ b/db/migrate/20240411153944_create_average_days_for_claim_completions.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 92987f8f693..329a50836bf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_04_10_212727) do +ActiveRecord::Schema[7.1].define(version: 2024_04_11_153944) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_stat_statements" @@ -205,6 +205,12 @@ t.index ["user_uuid"], name: "index_async_transactions_on_user_uuid" end + create_table "average_days_for_claim_completions", id: :serial, force: :cascade do |t| + t.float "average_days", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "base_facilities", id: false, force: :cascade do |t| t.string "unique_id", null: false t.string "name", null: false From 823a1e84d03f0a02b61cfda8513f75261b204702 Mon Sep 17 00:00:00 2001 From: Joshua Backfield Date: Fri, 12 Apr 2024 13:03:11 -0400 Subject: [PATCH 2/2] 97 Added SPEC file for unittest coverage and also linted everything. --- ...ge_days_for_claim_completion_controller.rb | 4 +- .../average_days_for_claim_completion.rb | 4 +- ...ys_for_claim_completion_controller_spec.rb | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb diff --git a/app/controllers/v0/average_days_for_claim_completion_controller.rb b/app/controllers/v0/average_days_for_claim_completion_controller.rb index d0f92a9b7aa..9c3ef7de693 100644 --- a/app/controllers/v0/average_days_for_claim_completion_controller.rb +++ b/app/controllers/v0/average_days_for_claim_completion_controller.rb @@ -1,10 +1,12 @@ +# 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 + rtn = AverageDaysForClaimCompletion.order('created_at DESC').first render json: { average_days: rtn.present? ? rtn.average_days : -1.0 } diff --git a/app/models/average_days_for_claim_completion.rb b/app/models/average_days_for_claim_completion.rb index 988d752beb8..78bb6d78a42 100644 --- a/app/models/average_days_for_claim_completion.rb +++ b/app/models/average_days_for_claim_completion.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class AverageDaysForClaimCompletion < ApplicationRecord -end \ No newline at end of file +end diff --git a/spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb b/spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb new file mode 100644 index 00000000000..a4e54bde0bf --- /dev/null +++ b/spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb @@ -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