From 005b31d77e2726a2858e49dd78d24874344a0593 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 3 Jul 2024 18:27:25 +0200 Subject: [PATCH] made sure that we are ready for the comming api change --- openapi.yaml | 8 ++--- ...aff2842cad45867c3a72f807ae08c1b10cb37.json | 22 ------------- ...d6216530909e31c417d5234ac270e4d851c8.json} | 10 +++--- ...e94adea3223725f8906025b3abebd24704ee4.json | 22 +++++++++++++ ...0703163202_more_complete_calendar.down.sql | 7 ++++ ...240703163202_more_complete_calendar.up.sql | 10 ++++++ server/main-api/src/calendar/mod.rs | 32 +++++++++---------- server/main-api/src/calendar/models.rs | 24 +++++++------- ...ain_api__calendar__tests__index_get-5.snap | 16 +++++----- ...ain_api__calendar__tests__index_get-6.snap | 11 ++++++- webclient/app/api_types/index.ts | 4 +-- webclient/app/components/CalendarFull.vue | 2 +- 12 files changed, 97 insertions(+), 71 deletions(-) delete mode 100644 server/.sqlx/query-1ffddd843ece79fa10cfb98c2e8aff2842cad45867c3a72f807ae08c1b10cb37.json rename server/.sqlx/{query-bc0955e2d7a86890ddbe05808ef57645c4b7413815693ebe3db92a62f2909dab.json => query-2668c0418c9e4853fe9f65d84d59d6216530909e31c417d5234ac270e4d851c8.json} (75%) create mode 100644 server/.sqlx/query-3f063afa6b1cee235b60edc06dee94adea3223725f8906025b3abebd24704ee4.json create mode 100644 server/main-api/migrations/20240703163202_more_complete_calendar.down.sql create mode 100644 server/main-api/migrations/20240703163202_more_complete_calendar.up.sql diff --git a/openapi.yaml b/openapi.yaml index 1546a5ee7..fa890da0b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -2099,12 +2099,12 @@ components: format: int32 examples: - 42 - stp_title_de: + title_de: description: The german title of the Entry type: string examples: - Quantenteleportation - stp_title_en: + title_en: description: The english title of the Entry type: string examples: @@ -2137,8 +2137,8 @@ components: - Vorlesung mit Zentralübung required: - id - - stp_title_de - - stp_title_en + - title_de + - title_en - start_at - end_at - entry_type diff --git a/server/.sqlx/query-1ffddd843ece79fa10cfb98c2e8aff2842cad45867c3a72f807ae08c1b10cb37.json b/server/.sqlx/query-1ffddd843ece79fa10cfb98c2e8aff2842cad45867c3a72f807ae08c1b10cb37.json deleted file mode 100644 index 227c836a8..000000000 --- a/server/.sqlx/query-1ffddd843ece79fa10cfb98c2e8aff2842cad45867c3a72f807ae08c1b10cb37.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO calendar (id,room_code,start_at,end_at,stp_title_de,stp_title_en,stp_type,entry_type,detailed_entry_type)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)\n ON CONFLICT (id) DO UPDATE SET\n room_code = EXCLUDED.room_code,\n start_at = EXCLUDED.start_at,\n end_at = EXCLUDED.end_at,\n stp_title_de = EXCLUDED.stp_title_de,\n stp_title_en = EXCLUDED.stp_title_en,\n stp_type = EXCLUDED.stp_type,\n entry_type = EXCLUDED.entry_type,\n detailed_entry_type = EXCLUDED.detailed_entry_type", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int4", - "Varchar", - "Timestamptz", - "Timestamptz", - "Text", - "Text", - "Text", - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "1ffddd843ece79fa10cfb98c2e8aff2842cad45867c3a72f807ae08c1b10cb37" -} diff --git a/server/.sqlx/query-bc0955e2d7a86890ddbe05808ef57645c4b7413815693ebe3db92a62f2909dab.json b/server/.sqlx/query-2668c0418c9e4853fe9f65d84d59d6216530909e31c417d5234ac270e4d851c8.json similarity index 75% rename from server/.sqlx/query-bc0955e2d7a86890ddbe05808ef57645c4b7413815693ebe3db92a62f2909dab.json rename to server/.sqlx/query-2668c0418c9e4853fe9f65d84d59d6216530909e31c417d5234ac270e4d851c8.json index 78422b683..c99be185f 100644 --- a/server/.sqlx/query-bc0955e2d7a86890ddbe05808ef57645c4b7413815693ebe3db92a62f2909dab.json +++ b/server/.sqlx/query-2668c0418c9e4853fe9f65d84d59d6216530909e31c417d5234ac270e4d851c8.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id,room_code,start_at,end_at,stp_title_de,stp_title_en,stp_type,entry_type,detailed_entry_type\n FROM calendar\n WHERE room_code = $1 AND start_at >= $2 AND end_at <= $3", + "query": "SELECT id,room_code,start_at,end_at,title_de,title_en,stp_type,entry_type,detailed_entry_type\n FROM calendar\n WHERE room_code = $1 AND start_at >= $2 AND end_at <= $3", "describe": { "columns": [ { @@ -25,12 +25,12 @@ }, { "ordinal": 4, - "name": "stp_title_de", + "name": "title_de", "type_info": "Text" }, { "ordinal": 5, - "name": "stp_title_en", + "name": "title_en", "type_info": "Text" }, { @@ -63,10 +63,10 @@ false, false, false, - false, + true, false, false ] }, - "hash": "bc0955e2d7a86890ddbe05808ef57645c4b7413815693ebe3db92a62f2909dab" + "hash": "2668c0418c9e4853fe9f65d84d59d6216530909e31c417d5234ac270e4d851c8" } diff --git a/server/.sqlx/query-3f063afa6b1cee235b60edc06dee94adea3223725f8906025b3abebd24704ee4.json b/server/.sqlx/query-3f063afa6b1cee235b60edc06dee94adea3223725f8906025b3abebd24704ee4.json new file mode 100644 index 000000000..22d13f8fe --- /dev/null +++ b/server/.sqlx/query-3f063afa6b1cee235b60edc06dee94adea3223725f8906025b3abebd24704ee4.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO calendar (id,room_code,start_at,end_at,title_de,title_en,stp_type,entry_type,detailed_entry_type)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)\n ON CONFLICT (id) DO UPDATE SET\n room_code = EXCLUDED.room_code,\n start_at = EXCLUDED.start_at,\n end_at = EXCLUDED.end_at,\n title_de = EXCLUDED.title_de,\n title_en = EXCLUDED.title_en,\n stp_type = EXCLUDED.stp_type,\n entry_type = EXCLUDED.entry_type,\n detailed_entry_type = EXCLUDED.detailed_entry_type", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Varchar", + "Timestamptz", + "Timestamptz", + "Text", + "Text", + "Text", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "3f063afa6b1cee235b60edc06dee94adea3223725f8906025b3abebd24704ee4" +} diff --git a/server/main-api/migrations/20240703163202_more_complete_calendar.down.sql b/server/main-api/migrations/20240703163202_more_complete_calendar.down.sql new file mode 100644 index 000000000..b4f9bc15b --- /dev/null +++ b/server/main-api/migrations/20240703163202_more_complete_calendar.down.sql @@ -0,0 +1,7 @@ +-- Add down migration script here + +ALTER TABLE calendar RENAME COLUMN title_de TO stp_title_de; +ALTER TABLE calendar RENAME COLUMN title_en TO stp_title_en; + +DELETE FROM calendar where stp_type is null; +ALTER TABLE calendar ALTER COLUMN stp_type SET NOT NULL; diff --git a/server/main-api/migrations/20240703163202_more_complete_calendar.up.sql b/server/main-api/migrations/20240703163202_more_complete_calendar.up.sql new file mode 100644 index 000000000..aa5f13733 --- /dev/null +++ b/server/main-api/migrations/20240703163202_more_complete_calendar.up.sql @@ -0,0 +1,10 @@ +-- Add up migration script here +-- these are pretty major changes => we should re-download everything +UPDATE en SET last_calendar_scrape_at = null WHERE last_calendar_scrape_at is not null; +UPDATE de SET last_calendar_scrape_at = null WHERE last_calendar_scrape_at is not null; +delete from calendar where 1=1; + +ALTER TABLE calendar RENAME COLUMN stp_title_de TO title_de; +ALTER TABLE calendar RENAME COLUMN stp_title_en TO title_en; + +ALTER TABLE calendar ALTER COLUMN stp_type drop not null; diff --git a/server/main-api/src/calendar/mod.rs b/server/main-api/src/calendar/mod.rs index 448a7cd9a..50d352e3d 100644 --- a/server/main-api/src/calendar/mod.rs +++ b/server/main-api/src/calendar/mod.rs @@ -116,7 +116,7 @@ async fn get_from_db( ) -> Result, crate::BoxedError> { let mut located_events: HashMap = HashMap::new(); for location in locations { - let events = sqlx::query_as!(Event, r#"SELECT id,room_code,start_at,end_at,stp_title_de,stp_title_en,stp_type,entry_type,detailed_entry_type + let events = sqlx::query_as!(Event, r#"SELECT id,room_code,start_at,end_at,title_de,title_en,stp_type,entry_type,detailed_entry_type FROM calendar WHERE room_code = $1 AND start_at >= $2 AND end_at <= $3"#, location.key, start_after, end_before).fetch_all(pool).await?; @@ -199,9 +199,9 @@ mod tests { room_code: "5121.EG.003".into(), start_at: *TIME_2012, end_at: *TIME_2014, - stp_title_de: "Quantenteleportation".into(), - stp_title_en: "Quantum teleportation".into(), - stp_type: "Vorlesung mit Zentralübung".into(), + title_de: "Quantenteleportation".into(), + title_en: "Quantum teleportation".into(), + stp_type: Some("Vorlesung mit Zentralübung".into()), entry_type: models::EventType::Lecture.to_string(), detailed_entry_type: "Abhaltung".into(), }, @@ -210,9 +210,9 @@ mod tests { room_code: "5121.EG.003".into(), start_at: *TIME_2014, end_at: *TIME_2016, - stp_title_de: "Quantenteleportation 2".into(), - stp_title_en: "Quantum teleportation 2".into(), - stp_type: "Vorlesung mit Zentralübung".into(), + title_de: "Quantenteleportation 2".into(), + title_en: "Quantum teleportation 2".into(), + stp_type: Some("Vorlesung mit Zentralübung".into()), entry_type: models::EventType::Lecture.to_string(), detailed_entry_type: "Abhaltung".into(), }, @@ -221,9 +221,9 @@ mod tests { room_code: "5121.EG.001".into(), start_at: *TIME_2014, end_at: *TIME_2016, - stp_title_de: "Wartung".into(), - stp_title_en: "maintenance".into(), - stp_type: "Vorlesung mit Zentralübung".into(), + title_de: "Wartung".into(), + title_en: "maintenance".into(), + stp_type: Some("Vorlesung mit Zentralübung".into()), entry_type: models::EventType::Barred.to_string(), detailed_entry_type: "Abhaltung".into(), }, @@ -232,9 +232,9 @@ mod tests { room_code: "5121.EG.001".into(), start_at: *TIME_Y2K, end_at: *TIME_2020, - stp_title_de: "Quantenteleportation 3".into(), - stp_title_en: "Quantum teleportation 3".into(), - stp_type: "Vorlesung".into(), + title_de: "Quantenteleportation 3".into(), + title_en: "Quantum teleportation 3".into(), + stp_type: Some("Vorlesung".into()), entry_type: models::EventType::Other.to_string(), detailed_entry_type: "Abhaltung".into(), }, @@ -243,9 +243,9 @@ mod tests { room_code: "5121.EG.001".into(), start_at: *TIME_Y2K, end_at: *TIME_2010, - stp_title_de: "Quantenteleportation 3".into(), - stp_title_en: "Quantum teleportation 3".into(), - stp_type: "Vorlesung".into(), + title_de: "Quantenteleportation 3".into(), + title_en: "Quantum teleportation 3".into(), + stp_type: Some("Vorlesung".into()), entry_type: models::EventType::Exam.to_string(), detailed_entry_type: "Abhaltung".into(), }, diff --git a/server/main-api/src/calendar/models.rs b/server/main-api/src/calendar/models.rs index 622e6db8e..bb06b6a98 100644 --- a/server/main-api/src/calendar/models.rs +++ b/server/main-api/src/calendar/models.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::fmt::Display; @@ -33,7 +33,7 @@ pub(super) struct LocationEvents { pub(super) location: CalendarLocation, } -#[derive(Serialize, Deserialize, Clone, Debug, sqlx::Type)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub(super) struct Event { pub(super) id: i32, /// e.g. 5121.EG.003 @@ -43,11 +43,11 @@ pub(super) struct Event { /// e.g. 2019-01-01T00:00:00 pub(super) end_at: DateTime, /// e.g. Quantenteleportation - pub(super) stp_title_de: String, + pub(super) title_de: String, /// e.g. Quantum teleportation - pub(super) stp_title_en: String, + pub(super) title_en: String, /// e.g. Vorlesung mit Zentralübung - pub(super) stp_type: String, + pub(super) stp_type: Option, /// e.g. lecture /// in reality this is a [EventType] pub(super) entry_type: String, @@ -61,23 +61,23 @@ impl Event { tx: &mut sqlx::Transaction<'_, sqlx::Postgres>, ) -> Result { sqlx::query!( - r#"INSERT INTO calendar (id,room_code,start_at,end_at,stp_title_de,stp_title_en,stp_type,entry_type,detailed_entry_type) + r#"INSERT INTO calendar (id,room_code,start_at,end_at,title_de,title_en,stp_type,entry_type,detailed_entry_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (id) DO UPDATE SET room_code = EXCLUDED.room_code, start_at = EXCLUDED.start_at, end_at = EXCLUDED.end_at, - stp_title_de = EXCLUDED.stp_title_de, - stp_title_en = EXCLUDED.stp_title_en, + title_de = EXCLUDED.title_de, + title_en = EXCLUDED.title_en, stp_type = EXCLUDED.stp_type, entry_type = EXCLUDED.entry_type, detailed_entry_type = EXCLUDED.detailed_entry_type"#, self.id, self.room_code, - self.start_at + Duration::hours(1), - self.end_at + Duration::hours(1), - self.stp_title_de, - self.stp_title_en, + self.start_at, + self.end_at, + self.title_de, + self.title_en, self.stp_type, self.entry_type, self.detailed_entry_type, diff --git a/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-5.snap b/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-5.snap index ec55ce02d..7c26ee280 100644 --- a/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-5.snap +++ b/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-5.snap @@ -5,23 +5,23 @@ expression: actual 5121.EG.003: events: - detailed_entry_type: Abhaltung - end_at: "2014-01-01T01:00:00Z" + end_at: "2014-01-01T00:00:00Z" entry_type: lecture id: 1 room_code: 5121.EG.003 - start_at: "2012-01-01T01:00:00Z" - stp_title_de: Quantenteleportation - stp_title_en: Quantum teleportation + start_at: "2012-01-01T00:00:00Z" stp_type: Vorlesung mit Zentralübung + title_de: Quantenteleportation + title_en: Quantum teleportation - detailed_entry_type: Abhaltung - end_at: "2016-01-01T01:00:00Z" + end_at: "2016-01-01T00:00:00Z" entry_type: lecture id: 2 room_code: 5121.EG.003 - start_at: "2014-01-01T01:00:00Z" - stp_title_de: Quantenteleportation 2 - stp_title_en: Quantum teleportation 2 + start_at: "2014-01-01T00:00:00Z" stp_type: Vorlesung mit Zentralübung + title_de: Quantenteleportation 2 + title_en: Quantum teleportation 2 location: calendar_url: "https://campus.tum.de/3" key: 5121.EG.003 diff --git a/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-6.snap b/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-6.snap index fde86b0ed..6d1ac80a7 100644 --- a/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-6.snap +++ b/server/main-api/src/calendar/snapshots/navigatum_main_api__calendar__tests__index_get-6.snap @@ -12,7 +12,16 @@ expression: actual type: room type_common_name: Versuchshalle 5121.EG.003: - events: [] + events: + - detailed_entry_type: Abhaltung + end_at: "2014-01-01T00:00:00Z" + entry_type: lecture + id: 1 + room_code: 5121.EG.003 + start_at: "2012-01-01T00:00:00Z" + stp_type: Vorlesung mit Zentralübung + title_de: Quantenteleportation + title_en: Quantum teleportation location: calendar_url: "https://campus.tum.de/3" key: 5121.EG.003 diff --git a/webclient/app/api_types/index.ts b/webclient/app/api_types/index.ts index 4e891ab4a..460313df5 100644 --- a/webclient/app/api_types/index.ts +++ b/webclient/app/api_types/index.ts @@ -532,9 +532,9 @@ export type components = { */ readonly id: number; /** @description The german title of the Entry */ - readonly stp_title_de: string; + readonly title_de: string; /** @description The english title of the Entry */ - readonly stp_title_en: string; + readonly title_en: string; /** * Format: date-time * @description The start of the entry diff --git a/webclient/app/components/CalendarFull.vue b/webclient/app/components/CalendarFull.vue index b891631e3..79e4a0907 100644 --- a/webclient/app/components/CalendarFull.vue +++ b/webclient/app/components/CalendarFull.vue @@ -65,7 +65,7 @@ async function fetchEvents(arg: EventSourceFuncArg): Promise { for (const [k, v] of Object.entries(data)) { items.push( ...v.events.map((e) => { - const title = locale.value == "de" ? e.stp_title_de : e.stp_title_en; + const title = locale.value == "de" ? e.title_de : e.title_en; const color = colorForType(e.entry_type); return { id: e.id.toString(),