From 21ff6741a0818c0bcd53c346f478d25d166d180c Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Wed, 1 Feb 2023 15:26:58 +0530 Subject: [PATCH] feat: add timestamp to benchmark submissions --- migrations/20230131114916_survey_bench_date.sql | 2 ++ src/api/v1/bench.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 migrations/20230131114916_survey_bench_date.sql diff --git a/migrations/20230131114916_survey_bench_date.sql b/migrations/20230131114916_survey_bench_date.sql new file mode 100644 index 0000000..f2e96b4 --- /dev/null +++ b/migrations/20230131114916_survey_bench_date.sql @@ -0,0 +1,2 @@ +ALTER TABLE survey_responses + ADD COLUMN submitted_at TIMESTAMPTZ NOT NULL DEFAULT now(); diff --git a/src/api/v1/bench.rs b/src/api/v1/bench.rs index c85f521..f989ee4 100644 --- a/src/api/v1/bench.rs +++ b/src/api/v1/bench.rs @@ -214,6 +214,7 @@ async fn submit( let user_id = Uuid::from_str(&username).unwrap(); let payload = payload.into_inner(); + let now = OffsetDateTime::now_utc(); struct ID { id: i32, @@ -225,14 +226,16 @@ async fn submit( campaign_id, device_user_provided, device_software_recognised, - threads - ) VALUES ($1, $2, $3, $4, $5) + threads, + submitted_at + ) VALUES ($1, $2, $3, $4, $5, $6) RETURNING ID;", &user_id, &campaign_id, &payload.device_user_provided, &payload.device_software_recognised, - &payload.threads + &payload.threads, + &now ) .fetch_one(&data.db) .await?;