Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed May 5, 2024
1 parent f7cdb07 commit 6c4e886
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Add down migration script here
-- was never used
create table rooms
(
key text primary key not null,
tumonline_org_id integer not null,
tumonline_calendar_id integer not null,
tumonline_room_id integer not null,
last_scrape timestamp without time zone not null
);

-- migrating to
DROP TABLE en;
create table en
(
key text not null
primary key
references de,
name text not null,
tumonline_room_nr integer,
type text not null,
type_common_name text not null,
lat double precision not null,
lon double precision not null,
data text not null,
last_calendar_scrape_at timestamp with time zone
);
comment on column en.last_calendar_scrape_at is 'the last time the calendar was scraped for this room';

DROP TABLE de;
create table de
(
key text not null primary key,
name text not null,
tumonline_room_nr integer,
type text not null,
type_common_name text not null,
lat double precision not null,
lon double precision not null,
data text not null,
last_calendar_scrape_at timestamp with time zone
);
comment on column de.last_calendar_scrape_at is 'the last time the calendar was scraped for this room';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Add up migration script here
-- was never used
DROP TABLE rooms;

-- migrating to using the json type instead of having elaborate insertion logic
alter table de alter column data type json using data::json;

alter table de drop column lat;
alter table de add column lat FLOAT NOT NULL GENERATED ALWAYS AS (CAST (data->'coords'->>'lat' AS FLOAT)) STORED;
alter table de drop column lon;
alter table de add column lon FLOAT NOT NULL GENERATED ALWAYS AS (CAST (data->'coords'->>'lon' AS FLOAT)) STORED;
alter table de drop column name;
alter table de add column name TEXT NOT NULL GENERATED ALWAYS AS (CAST (data->>'name' AS TEXT)) STORED;
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;

11 changes: 6 additions & 5 deletions server/main-api/src/calendar/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use actix_web::{get, web, HttpResponse};
use actix_web::{get, HttpResponse, web};
use chrono::{DateTime, Utc};
use log::error;
use serde::Deserialize;
Expand Down Expand Up @@ -45,10 +45,11 @@ pub async fn calendar_handler(
}
Ok(Some(loc)) => loc,
};
let calendar_url = format!(
"https://campus.tum.de/tumonline/wbKalender.wbRessource?pResNr={id}",
id = 0
); // TODO: room.tumonline_calendar_id
let Some(calendar_url)=location.calendar_url else {
return HttpResponse::NotFound()
.content_type("text/plain")
.body("Room does not have a calendar");
};
let fetching_strategy =
fetch::StrategyExecutor::new(&data.db, &id, &args.start_after, &args.end_before);
match fetching_strategy
Expand Down
1 change: 1 addition & 0 deletions server/main-api/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Location {
pub name: String,
pub last_calendar_scrape_at: Option<DateTime<Utc>>,
pub tumonline_room_nr: Option<i32>,
pub calendar_url: Option<String>,
pub r#type: String,
pub type_common_name: String,
pub lat: f64,
Expand Down

0 comments on commit 6c4e886

Please sign in to comment.