Skip to content

Commit

Permalink
Add result_count to SearchLog
Browse files Browse the repository at this point in the history
Whenever a search happens in Check, we want to record the number of
results returned. This will help with analysis and potentially provide
some UX insight.
  • Loading branch information
malcolmbaig committed Nov 20, 2023
1 parent 5db38ba commit 801530f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
12 changes: 7 additions & 5 deletions app/controllers/check_records/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ def show
if @search.invalid?
render :new
else
SearchLog.create!(
dsi_user: current_dsi_user,
last_name: @search.last_name,
date_of_birth: @search.date_of_birth.to_s
)
@total, @teachers =
QualificationsApi::Client.new(
token: ENV["QUALIFICATIONS_API_FIXED_TOKEN"]
).teachers(
date_of_birth: @search.date_of_birth,
last_name: @search.last_name
)

SearchLog.create!(
dsi_user: current_dsi_user,
last_name: @search.last_name,
date_of_birth: @search.date_of_birth.to_s,
result_count: @total
)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ shared:
- dsi_user_id
- last_name
- date_of_birth
- result_count
- created_at
- updated_at
:staff:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231116115727_add_result_count_to_search_log.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddResultCountToSearchLog < ActiveRecord::Migration[7.0]
def change
add_column :search_logs, :result_count, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_09_07_120219) do
ActiveRecord::Schema[7.0].define(version: 2023_11_16_115727) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -134,6 +134,7 @@
t.date "date_of_birth"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "result_count"
t.index ["dsi_user_id"], name: "index_search_logs_on_dsi_user_id"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ def then_the_trn_is_not_in_the_url
end

def and_my_search_is_logged
expect(SearchLog.last.last_name).to eq "Walsh"
expect(SearchLog.last.date_of_birth.to_s).to eq "1992-04-05"
search_log = SearchLog.last
expect(search_log.last_name).to eq "Walsh"
expect(search_log.date_of_birth.to_s).to eq "1992-04-05"
expect(search_log.result_count).to eq 1
end

def when_i_click_on_the_teacher_record
Expand Down

0 comments on commit 801530f

Please sign in to comment.