diff --git a/server/.sqlx/query-0129b39fb399d5d3d41b2053c9bf617a646c40ec0e2f614d035948f240c8b245.json b/server/.sqlx/query-0129b39fb399d5d3d41b2053c9bf617a646c40ec0e2f614d035948f240c8b245.json new file mode 100644 index 000000000..661285ae5 --- /dev/null +++ b/server/.sqlx/query-0129b39fb399d5d3d41b2053c9bf617a646c40ec0e2f614d035948f240c8b245.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO en(key,data)VALUES ($1,$2)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Json" + ] + }, + "nullable": [] + }, + "hash": "0129b39fb399d5d3d41b2053c9bf617a646c40ec0e2f614d035948f240c8b245" +} diff --git a/server/.sqlx/query-866f41f41ff9e68e92736009d98b37f497aeb87f11eeafa13eadd4fefda706b5.json b/server/.sqlx/query-866f41f41ff9e68e92736009d98b37f497aeb87f11eeafa13eadd4fefda706b5.json deleted file mode 100644 index 25293b974..000000000 --- a/server/.sqlx/query-866f41f41ff9e68e92736009d98b37f497aeb87f11eeafa13eadd4fefda706b5.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO en(key,data,name,tumonline_room_nr,type,type_common_name,lat,lon)\n VALUES ($1,$2,$3,$4,$5,$6,$7,$8)", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Text", - "Int4", - "Text", - "Text", - "Float8", - "Float8" - ] - }, - "nullable": [] - }, - "hash": "866f41f41ff9e68e92736009d98b37f497aeb87f11eeafa13eadd4fefda706b5" -} diff --git a/server/.sqlx/query-874f7f834952dc9935690debfad3d161757d7ce6fcee59c23c23abbf45e803cb.json b/server/.sqlx/query-874f7f834952dc9935690debfad3d161757d7ce6fcee59c23c23abbf45e803cb.json index f1a625cd9..0163984be 100644 --- a/server/.sqlx/query-874f7f834952dc9935690debfad3d161757d7ce6fcee59c23c23abbf45e803cb.json +++ b/server/.sqlx/query-874f7f834952dc9935690debfad3d161757d7ce6fcee59c23c23abbf45e803cb.json @@ -10,43 +10,48 @@ }, { "ordinal": 1, - "name": "name", - "type_info": "Text" + "name": "tumonline_room_nr", + "type_info": "Int4" }, { "ordinal": 2, - "name": "tumonline_room_nr", - "type_info": "Int4" + "name": "data", + "type_info": "Json" }, { "ordinal": 3, - "name": "type", - "type_info": "Text" + "name": "last_calendar_scrape_at", + "type_info": "Timestamptz" }, { "ordinal": 4, - "name": "type_common_name", - "type_info": "Text" + "name": "lat", + "type_info": "Float8" }, { "ordinal": 5, - "name": "lat", + "name": "lon", "type_info": "Float8" }, { "ordinal": 6, - "name": "lon", - "type_info": "Float8" + "name": "name", + "type_info": "Text" }, { "ordinal": 7, - "name": "data", + "name": "type_common_name", "type_info": "Text" }, { "ordinal": 8, - "name": "last_calendar_scrape_at", - "type_info": "Timestamptz" + "name": "type", + "type_info": "Text" + }, + { + "ordinal": 9, + "name": "calendar_url", + "type_info": "Text" } ], "parameters": { @@ -56,6 +61,7 @@ }, "nullable": [ false, + true, false, true, false, diff --git a/server/.sqlx/query-9f518183559171969ae448a0f3f0de7a221ce7d9bb8378028c695e1b665c55c5.json b/server/.sqlx/query-9f518183559171969ae448a0f3f0de7a221ce7d9bb8378028c695e1b665c55c5.json index ebe2808cc..f3747183a 100644 --- a/server/.sqlx/query-9f518183559171969ae448a0f3f0de7a221ce7d9bb8378028c695e1b665c55c5.json +++ b/server/.sqlx/query-9f518183559171969ae448a0f3f0de7a221ce7d9bb8378028c695e1b665c55c5.json @@ -6,7 +6,7 @@ { "ordinal": 0, "name": "data", - "type_info": "Text" + "type_info": "Json" } ], "parameters": { diff --git a/server/.sqlx/query-a16d239da728e396e283aea0782d9b32f08c86626db9f4d63249dfc2cd77b80c.json b/server/.sqlx/query-a16d239da728e396e283aea0782d9b32f08c86626db9f4d63249dfc2cd77b80c.json index 8b2ce6edc..653b8f972 100644 --- a/server/.sqlx/query-a16d239da728e396e283aea0782d9b32f08c86626db9f4d63249dfc2cd77b80c.json +++ b/server/.sqlx/query-a16d239da728e396e283aea0782d9b32f08c86626db9f4d63249dfc2cd77b80c.json @@ -6,7 +6,7 @@ { "ordinal": 0, "name": "data", - "type_info": "Text" + "type_info": "Json" } ], "parameters": { diff --git a/server/.sqlx/query-a87d33b55872d9135ab82391b36d1a495534817fb39a9e25f6720267c6025965.json b/server/.sqlx/query-a87d33b55872d9135ab82391b36d1a495534817fb39a9e25f6720267c6025965.json index 89d01e799..2fe88fcc6 100644 --- a/server/.sqlx/query-a87d33b55872d9135ab82391b36d1a495534817fb39a9e25f6720267c6025965.json +++ b/server/.sqlx/query-a87d33b55872d9135ab82391b36d1a495534817fb39a9e25f6720267c6025965.json @@ -10,43 +10,48 @@ }, { "ordinal": 1, - "name": "name", - "type_info": "Text" + "name": "tumonline_room_nr", + "type_info": "Int4" }, { "ordinal": 2, - "name": "tumonline_room_nr", - "type_info": "Int4" + "name": "data", + "type_info": "Json" }, { "ordinal": 3, - "name": "type", - "type_info": "Text" + "name": "last_calendar_scrape_at", + "type_info": "Timestamptz" }, { "ordinal": 4, - "name": "type_common_name", - "type_info": "Text" + "name": "lat", + "type_info": "Float8" }, { "ordinal": 5, - "name": "lat", + "name": "lon", "type_info": "Float8" }, { "ordinal": 6, - "name": "lon", - "type_info": "Float8" + "name": "name", + "type_info": "Text" }, { "ordinal": 7, - "name": "data", + "name": "type_common_name", "type_info": "Text" }, { "ordinal": 8, - "name": "last_calendar_scrape_at", - "type_info": "Timestamptz" + "name": "type", + "type_info": "Text" + }, + { + "ordinal": 9, + "name": "calendar_url", + "type_info": "Text" } ], "parameters": { @@ -56,6 +61,7 @@ }, "nullable": [ false, + true, false, true, false, diff --git a/server/.sqlx/query-acfccc2d96fcc85154dc3a6dd969ffdcaa2465cb27b510f9e50682f15980c45f.json b/server/.sqlx/query-acfccc2d96fcc85154dc3a6dd969ffdcaa2465cb27b510f9e50682f15980c45f.json new file mode 100644 index 000000000..48d0d982a --- /dev/null +++ b/server/.sqlx/query-acfccc2d96fcc85154dc3a6dd969ffdcaa2465cb27b510f9e50682f15980c45f.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO de(key,data)VALUES ($1,$2)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Json" + ] + }, + "nullable": [] + }, + "hash": "acfccc2d96fcc85154dc3a6dd969ffdcaa2465cb27b510f9e50682f15980c45f" +} diff --git a/server/.sqlx/query-e08d77584b88d04d53710630fc11af9a99868a7dee15c2f32ccca3c9b1c8b2b6.json b/server/.sqlx/query-e08d77584b88d04d53710630fc11af9a99868a7dee15c2f32ccca3c9b1c8b2b6.json deleted file mode 100644 index c02d9fc75..000000000 --- a/server/.sqlx/query-e08d77584b88d04d53710630fc11af9a99868a7dee15c2f32ccca3c9b1c8b2b6.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO de(key,data,name,tumonline_room_nr,type,type_common_name,lat,lon)\n VALUES ($1,$2,$3,$4,$5,$6,$7,$8)", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Text", - "Int4", - "Text", - "Text", - "Float8", - "Float8" - ] - }, - "nullable": [] - }, - "hash": "e08d77584b88d04d53710630fc11af9a99868a7dee15c2f32ccca3c9b1c8b2b6" -} diff --git a/server/main-api/migrations/20240505224430_fix-calendar-id-not-extracted.up.sql b/server/main-api/migrations/20240505224430_fix-calendar-id-not-extracted.up.sql index 47eeab564..6db63d0d2 100644 --- a/server/main-api/migrations/20240505224430_fix-calendar-id-not-extracted.up.sql +++ b/server/main-api/migrations/20240505224430_fix-calendar-id-not-extracted.up.sql @@ -14,7 +14,6 @@ alter table de drop column type_common_name; alter table de add column type_common_name TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type_common_name' AS TEXT)) STORED; alter table de drop column type; alter table de add column type TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type' AS TEXT)) STORED; -alter table de drop column calendar_url; alter table de add column calendar_url TEXT GENERATED ALWAYS AS (CAST (data->'props'->>'calendar_url' AS TEXT)) STORED; alter table en alter column data type json using data::json; @@ -28,5 +27,4 @@ alter table en drop column type_common_name; alter table en add column type_common_name TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type_common_name' AS TEXT)) STORED; alter table en drop column type; alter table en add column type TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'type' AS TEXT)) STORED; -alter table en drop column calendar_url; alter table en add column calendar_url TEXT GENERATED ALWAYS AS (CAST (data->'props'->>'calendar_url' AS TEXT)) STORED; diff --git a/server/main-api/src/details.rs b/server/main-api/src/details.rs index 6f5911a69..913f75cea 100644 --- a/server/main-api/src/details.rs +++ b/server/main-api/src/details.rs @@ -30,8 +30,8 @@ pub async fn get_handler( Ok(d) => match d { None => HttpResponse::NotFound().body("Not found"), Some(d) => { - let mut response_json = d.clone(); - // We don not want to serialise this data at any point in the server. + let mut response_json = serde_json::to_string(&d).unwrap(); + // We don't want to serialise this data at any point in the server. // This just flows through the server, but adding redirect_url to the response is necessary response_json.pop(); // remove last } response_json.push_str(&format!(",\"redirect_url\":\"{redirect_url}\"}}",)); diff --git a/server/main-api/src/models.rs b/server/main-api/src/models.rs index 03c90a60e..4b6a362cf 100644 --- a/server/main-api/src/models.rs +++ b/server/main-api/src/models.rs @@ -1,4 +1,5 @@ use chrono::{DateTime, Utc}; +use serde_json::Value; #[derive(Debug, Clone)] pub struct Location { @@ -11,7 +12,7 @@ pub struct Location { pub type_common_name: String, pub lat: f64, pub lon: f64, - pub data: String, + pub data: Value, } #[derive(Debug, Clone)] diff --git a/server/main-api/src/setup/database/data.rs b/server/main-api/src/setup/database/data.rs index 3bfce57fb..2db9f6938 100644 --- a/server/main-api/src/setup/database/data.rs +++ b/server/main-api/src/setup/database/data.rs @@ -4,11 +4,10 @@ use std::time::Instant; use log::info; use serde_json::Value; - struct DelocalisedValues { key: String, - de: HashMap, - en: HashMap, + de: Value, + en: Value, } impl From> for DelocalisedValues { @@ -63,15 +62,21 @@ impl DelocalisedValues { self, tx: &mut sqlx::Transaction<'_, sqlx::Postgres>, ) -> Result<(), sqlx::Error> { - let data = serde_json::to_string(&self.de).unwrap(); - sqlx::query!(r#"INSERT INTO de(key,data)VALUES ($1,$2)"#, self.key, data) - .execute(&mut **tx) - .await?; + sqlx::query!( + r#"INSERT INTO de(key,data)VALUES ($1,$2)"#, + self.key, + self.de + ) + .execute(&mut **tx) + .await?; - let data = serde_json::to_string(&self.en).unwrap(); - sqlx::query!(r#"INSERT INTO en(key,data)VALUES ($1,$2)"#, self.key, data) - .execute(&mut **tx) - .await?; + sqlx::query!( + r#"INSERT INTO en(key,data)VALUES ($1,$2)"#, + self.key, + self.en + ) + .execute(&mut **tx) + .await?; Ok(()) }