Skip to content

Commit

Permalink
made sure that we are ready for the comming ConnecTUM API-Change (#1281)
Browse files Browse the repository at this point in the history
made sure that we are ready for the comming api change
  • Loading branch information
CommanderStorm authored Jul 21, 2024
1 parent aaf991a commit 2419b82
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 71 deletions.
8 changes: 4 additions & 4 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
32 changes: 16 additions & 16 deletions server/main-api/src/calendar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async fn get_from_db(
) -> Result<LimitedHashMap<String, LocationEvents>, crate::BoxedError> {
let mut located_events: HashMap<String, LocationEvents> = 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?;
Expand Down Expand Up @@ -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(),
},
Expand All @@ -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(),
},
Expand All @@ -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(),
},
Expand All @@ -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(),
},
Expand All @@ -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(),
},
Expand Down
24 changes: 12 additions & 12 deletions server/main-api/src/calendar/models.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{DateTime, Duration, Utc};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::fmt::Display;

Expand Down Expand Up @@ -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
Expand All @@ -43,11 +43,11 @@ pub(super) struct Event {
/// e.g. 2019-01-01T00:00:00
pub(super) end_at: DateTime<Utc>,
/// 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<String>,
/// e.g. lecture
/// in reality this is a [EventType]
pub(super) entry_type: String,
Expand All @@ -61,23 +61,23 @@ impl Event {
tx: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<sqlx::postgres::PgQueryResult, sqlx::Error> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions webclient/app/api_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion webclient/app/components/CalendarFull.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function fetchEvents(arg: EventSourceFuncArg): Promise<EventInput[]> {
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(),
Expand Down

0 comments on commit 2419b82

Please sign in to comment.