From 9b80771492833877021d2174cd3a8b215d2c6a66 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 2 Jan 2025 23:02:54 +0100 Subject: [PATCH] made sure that the naming of details responses is consistent --- ...21e4c984144695bc3b0c2d5be6993126dbc1c.json | 14 -- ...02ebc44b6c9061b717e78a97c0a9549b5a84f.json | 46 ----- ...815374ee3368f45250987475cce81910eec57.json | 46 ----- ...e716e01bd0443ee11e11dfc30791c6477c7a6.json | 94 +++++++++ ...296dc9d5eed8498a8b225b213fd9bdbc0f996.json | 94 +++++++++ server/src/db/location.rs | 1 + server/src/routes/locations/details.rs | 194 +++++++++--------- 7 files changed, 289 insertions(+), 200 deletions(-) delete mode 100644 server/.sqlx/query-064abe062d039025429a814407c21e4c984144695bc3b0c2d5be6993126dbc1c.json delete mode 100644 server/.sqlx/query-1225dec3f33fb9e257be062530e02ebc44b6c9061b717e78a97c0a9549b5a84f.json delete mode 100644 server/.sqlx/query-4db847e83ba3061db424551812c815374ee3368f45250987475cce81910eec57.json create mode 100644 server/.sqlx/query-649f553a2379b1c67d36ec6d45be716e01bd0443ee11e11dfc30791c6477c7a6.json create mode 100644 server/.sqlx/query-7cda9051e4f9220648ebaf4f675296dc9d5eed8498a8b225b213fd9bdbc0f996.json diff --git a/server/.sqlx/query-064abe062d039025429a814407c21e4c984144695bc3b0c2d5be6993126dbc1c.json b/server/.sqlx/query-064abe062d039025429a814407c21e4c984144695bc3b0c2d5be6993126dbc1c.json deleted file mode 100644 index 4e09f8fb2..000000000 --- a/server/.sqlx/query-064abe062d039025429a814407c21e4c984144695bc3b0c2d5be6993126dbc1c.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n WITH rows_to_delete AS (\n SELECT id\n FROM calendar WHERE room_code = $1\n LIMIT 1000\n )\n \n DELETE FROM calendar\n WHERE id IN (SELECT id FROM rows_to_delete);", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text" - ] - }, - "nullable": [] - }, - "hash": "064abe062d039025429a814407c21e4c984144695bc3b0c2d5be6993126dbc1c" -} diff --git a/server/.sqlx/query-1225dec3f33fb9e257be062530e02ebc44b6c9061b717e78a97c0a9549b5a84f.json b/server/.sqlx/query-1225dec3f33fb9e257be062530e02ebc44b6c9061b717e78a97c0a9549b5a84f.json deleted file mode 100644 index b3ea124ae..000000000 --- a/server/.sqlx/query-1225dec3f33fb9e257be062530e02ebc44b6c9061b717e78a97c0a9549b5a84f.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT type,lat,lon,name,type_common_name FROM de WHERE key = $1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "type", - "type_info": "Text" - }, - { - "ordinal": 1, - "name": "lat", - "type_info": "Float8" - }, - { - "ordinal": 2, - "name": "lon", - "type_info": "Float8" - }, - { - "ordinal": 3, - "name": "name", - "type_info": "Text" - }, - { - "ordinal": 4, - "name": "type_common_name", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - false - ] - }, - "hash": "1225dec3f33fb9e257be062530e02ebc44b6c9061b717e78a97c0a9549b5a84f" -} diff --git a/server/.sqlx/query-4db847e83ba3061db424551812c815374ee3368f45250987475cce81910eec57.json b/server/.sqlx/query-4db847e83ba3061db424551812c815374ee3368f45250987475cce81910eec57.json deleted file mode 100644 index 7d5f17f87..000000000 --- a/server/.sqlx/query-4db847e83ba3061db424551812c815374ee3368f45250987475cce81910eec57.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT type,lat,lon,name,type_common_name FROM en WHERE key = $1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "type", - "type_info": "Text" - }, - { - "ordinal": 1, - "name": "lat", - "type_info": "Float8" - }, - { - "ordinal": 2, - "name": "lon", - "type_info": "Float8" - }, - { - "ordinal": 3, - "name": "name", - "type_info": "Text" - }, - { - "ordinal": 4, - "name": "type_common_name", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - false - ] - }, - "hash": "4db847e83ba3061db424551812c815374ee3368f45250987475cce81910eec57" -} diff --git a/server/.sqlx/query-649f553a2379b1c67d36ec6d45be716e01bd0443ee11e11dfc30791c6477c7a6.json b/server/.sqlx/query-649f553a2379b1c67d36ec6d45be716e01bd0443ee11e11dfc30791c6477c7a6.json new file mode 100644 index 000000000..685fc76cb --- /dev/null +++ b/server/.sqlx/query-649f553a2379b1c67d36ec6d45be716e01bd0443ee11e11dfc30791c6477c7a6.json @@ -0,0 +1,94 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT last_calendar_scrape_at,lat,lon,name,type_common_name,type,calendar_url,tumonline_room_nr,coordinate_accuracy,coordinate_source,comment,usage_id,operator_id\n FROM de\n WHERE key=$1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "last_calendar_scrape_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 1, + "name": "lat", + "type_info": "Float8" + }, + { + "ordinal": 2, + "name": "lon", + "type_info": "Float8" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "type_common_name", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "type", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "calendar_url", + "type_info": "Text" + }, + { + "ordinal": 7, + "name": "tumonline_room_nr", + "type_info": "Int4" + }, + { + "ordinal": 8, + "name": "coordinate_accuracy", + "type_info": "Text" + }, + { + "ordinal": 9, + "name": "coordinate_source", + "type_info": "Text" + }, + { + "ordinal": 10, + "name": "comment", + "type_info": "Text" + }, + { + "ordinal": 11, + "name": "usage_id", + "type_info": "Int4" + }, + { + "ordinal": 12, + "name": "operator_id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + true, + false, + false, + false, + false, + false, + true, + true, + true, + false, + true, + true, + true + ] + }, + "hash": "649f553a2379b1c67d36ec6d45be716e01bd0443ee11e11dfc30791c6477c7a6" +} diff --git a/server/.sqlx/query-7cda9051e4f9220648ebaf4f675296dc9d5eed8498a8b225b213fd9bdbc0f996.json b/server/.sqlx/query-7cda9051e4f9220648ebaf4f675296dc9d5eed8498a8b225b213fd9bdbc0f996.json new file mode 100644 index 000000000..d3ed3d4b3 --- /dev/null +++ b/server/.sqlx/query-7cda9051e4f9220648ebaf4f675296dc9d5eed8498a8b225b213fd9bdbc0f996.json @@ -0,0 +1,94 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT last_calendar_scrape_at,lat,lon,name,type_common_name,type,calendar_url,tumonline_room_nr,coordinate_accuracy,coordinate_source,comment,usage_id,operator_id\n FROM en\n WHERE key=$1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "last_calendar_scrape_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 1, + "name": "lat", + "type_info": "Float8" + }, + { + "ordinal": 2, + "name": "lon", + "type_info": "Float8" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "type_common_name", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "type", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "calendar_url", + "type_info": "Text" + }, + { + "ordinal": 7, + "name": "tumonline_room_nr", + "type_info": "Int4" + }, + { + "ordinal": 8, + "name": "coordinate_accuracy", + "type_info": "Text" + }, + { + "ordinal": 9, + "name": "coordinate_source", + "type_info": "Text" + }, + { + "ordinal": 10, + "name": "comment", + "type_info": "Text" + }, + { + "ordinal": 11, + "name": "usage_id", + "type_info": "Int4" + }, + { + "ordinal": 12, + "name": "operator_id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + true, + false, + false, + false, + false, + false, + true, + true, + true, + false, + true, + true, + true + ] + }, + "hash": "7cda9051e4f9220648ebaf4f675296dc9d5eed8498a8b225b213fd9bdbc0f996" +} diff --git a/server/src/db/location.rs b/server/src/db/location.rs index cd312d0e0..a3e2a07f8 100644 --- a/server/src/db/location.rs +++ b/server/src/db/location.rs @@ -45,6 +45,7 @@ impl Location { } } +#[allow(dead_code)] // used for testing out the repo pattern #[derive(Debug, Clone)] pub struct LocationKeyAlias { pub key: String, diff --git a/server/src/routes/locations/details.rs b/server/src/routes/locations/details.rs index b0d3aa97f..823d5898a 100644 --- a/server/src/routes/locations/details.rs +++ b/server/src/routes/locations/details.rs @@ -102,45 +102,13 @@ pub async fn get_handler( } } -/// Operator of a location -#[derive(Serialize, Deserialize, Debug, Clone, utoipa::ToSchema)] -struct Operator { - /// ID of the operator - #[schema(examples(51901))] - id: u32, - ///Link to the operator - #[schema(examples("https://campus.tum.de/tumonline/webnav.navigate_to?corg=51901"))] - url: String, - /// designation code of the operator - #[schema(examples("TUS7000"))] - code: String, - /// The full name of the operator (localized). Null for organisations that - /// are no longer active (e.g. id=38698), but where the operator has not been - /// updated in TUMonline. - #[schema(examples("TUM School of Social Sciences and Technology"))] - name: String, -} - -#[derive(Serialize, Deserialize, Debug, Default, utoipa::ToSchema)] -#[serde(rename_all = "snake_case")] -enum LocationType { - #[default] - Room, - Building, - JoinedBuilding, - Area, - Site, - Campus, - Poi, -} - #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] struct LocationDetailsResponse { /// The id, that was requested #[schema(examples("5606.EG.036"))] id: String, /// The type of the entry - r#type: LocationType, + r#type: LocationTypeResponse, /// The type of the entry in a human-readable form #[schema(examples("Büro"))] type_common_name: String, @@ -167,44 +135,77 @@ struct LocationDetailsResponse { #[schema(min_items=1, examples(json!(["Standorte","Garching Forschungszentrum","Fakultät Mathematik & Informatik (FMI oder MI)", "Finger 06 (BT06)"])))] parent_names: Vec, /// Data for the info-card table - props: Props, + props: PropsResponse, /// The information you need to request Images from the `/cdn/{size}/{id}_{counter}.webp` endpoint /// /// TODO: Sometimes missing, sometimes not.. so weird.. #[serde(skip_serializing_if = "Option::is_none")] - imgs: Option>, - ranking_factors: RankingFactors, + imgs: Option>, + ranking_factors: RankingFactorsResponse, /// Where we got our data from, should be displayed at the bottom of any page containing this data - sources: Sources, + sources: SourcesResponse, /// The url, this item should be displayed at. /// /// Present on both redirects and normal entries, to allow for the common /view/:id path #[schema(examples("/room/5606.EG.036"))] redirect_url: Option, /// Coordinate of the location - coords: Coordinate, + coords: CoordinateResponse, /// Print or overlay maps for said location - maps: Maps, - /// informations for different sectons on the page like the + maps: MapsResponse, + /// Information for different sections on the page like the /// - buildings overview, /// - rooms overview and /// - featured view #[serde(skip_serializing_if = "Option::is_none")] - sections: Option, + sections: Option, +} + +#[derive(Serialize, Deserialize, Debug, Default, utoipa::ToSchema)] +#[serde(rename_all = "snake_case")] +enum LocationTypeResponse { + #[default] + Room, + Building, + JoinedBuilding, + Area, + Site, + Campus, + Poi, + Other, +} + +/// Operator of a location +#[derive(Serialize, Deserialize, Debug, Clone, utoipa::ToSchema)] +struct OperatorResponse { + /// ID of the operator + #[schema(examples(51901))] + id: u32, + ///Link to the operator + #[schema(examples("https://campus.tum.de/tumonline/webnav.navigate_to?corg=51901"))] + url: String, + /// designation code of the operator + #[schema(examples("TUS7000"))] + code: String, + /// The full name of the operator (localized). Null for organisations that + /// are no longer active (e.g. id=38698), but where the operator has not been + /// updated in TUMonline. + #[schema(examples("TUM School of Social Sciences and Technology"))] + name: String, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct Sections { +struct SectionsResponse { #[serde(skip_serializing_if = "Option::is_none")] - buildings_overview: Option, + buildings_overview: Option, #[serde(skip_serializing_if = "Option::is_none")] - rooms_overview: Option, + rooms_overview: Option, #[serde(skip_serializing_if = "Option::is_none")] - featured_overview: Option, + featured_overview: Option, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct BuildingsOverviewItem { +struct BuildingsOverviewItemResponse { /// The id of the entry id: String, /// Human display name @@ -216,7 +217,7 @@ struct BuildingsOverviewItem { } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct FeaturedOverviewItem { +struct FeaturedOverviewItemResponse { /// The id of the entry id: String, /// Human display name @@ -228,54 +229,54 @@ struct FeaturedOverviewItem { } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct BuildingsOverview { - entries: Vec, +struct BuildingsOverviewResponse { + entries: Vec, n_visible: u32, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct RoomsOverviewUsageChild { +struct RoomsOverviewUsageChildResponse { id: String, name: String, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct RoomsOverviewUsage { +struct RoomsOverviewUsageResponse { name: String, count: u32, - children: Vec, + children: Vec, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct RoomsOverview { - usages: Vec, +struct RoomsOverviewResponse { + usages: Vec, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct FeaturedOverview { - entries: Vec, +struct FeaturedOverviewResponse { + entries: Vec, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct Maps { +struct MapsResponse { /// type of the Map that should be shown by default - default: DefaultMaps, + default: DefaultMapsResponse, #[serde(skip_serializing_if = "Option::is_none")] - roomfinder: Option, + roomfinder: Option, /// `None` would mean no overlay maps are displayed by default. /// For rooms, you should add a warning that no floor map is available for this room #[serde(skip_serializing_if = "Option::is_none")] - overlays: Option, + overlays: Option, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct RoomfinderMap { +struct RoomfinderMapResponse { /// The id of the map, that should be shown as a default #[schema(examples("rf142"))] default: String, - available: Vec, + available: Vec, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct RoomfinderMapEntry { +struct RoomfinderMapEntryResponse { /// human-readable name of the map name: String, /// machine-readable name of the map @@ -296,18 +297,18 @@ struct RoomfinderMapEntry { file: String, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct OverlayMaps { +struct OverlayMapsResponse { /// The floor-id of the map, that should be shown as a default. /// null means: /// - We suggest, you don't show a map by default. /// - This is only the case for buildings or other such entities and not for rooms, if we know where they are and a map exists #[schema(example = 0)] default: Option, - available: Vec, + available: Vec, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct OverlayMapEntry { +struct OverlayMapEntryResponse { /// Machine-readable floor-id of the map. /// /// Should start with 0 for the ground level (defined by the main entrance) and increase or decrease. @@ -333,7 +334,7 @@ struct OverlayMapEntry { #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] #[serde(rename_all = "snake_case")] -enum DefaultMaps { +enum DefaultMapsResponse { /// interactive maps should be shown first #[default] Interactive, @@ -342,7 +343,7 @@ enum DefaultMaps { } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct ExtraComputedProp { +struct ExtraComputedPropResponse { #[schema(examples("Genauere Angaben"))] #[serde(skip_serializing_if = "Option::is_none")] header: Option, @@ -354,24 +355,24 @@ struct ExtraComputedProp { } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct ComputedProp { +struct ComputedPropResponse { #[schema(examples("Raumkennung"))] name: String, #[schema(examples("5602.EG.001"))] text: String, #[serde(skip_serializing_if = "Option::is_none")] - extra: Option, + extra: Option, } /// Data for the info-card table #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct Props { +struct PropsResponse { /// The operator of the room #[serde(skip_serializing_if = "Option::is_none")] - operator: Option, - computed: Vec, + operator: Option, + computed: Vec, #[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")] - links: Vec, + links: Vec, /// A comment to show to an entry. /// /// It is used in the rare cases, where some aspect about the room/.. or its translation are misleading. @@ -387,7 +388,7 @@ struct Props { } #[derive(Serialize, Deserialize, Debug, utoipa::ToSchema)] -struct Source { +struct SourceResponse { /// Name of the provider #[schema(example = "NavigaTUM")] name: String, @@ -398,30 +399,30 @@ struct Source { } /// Where we got our data from, should be displayed at the bottom of any page containing this data #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct Sources { +struct SourcesResponse { /// Was this entry patched by us? (e.g. to fix a typo in the name/...) /// If so, we should not display the source, as it is not the original source. #[serde(skip_serializing_if = "Option::is_none")] patched: Option, // default = false /// What is the basis of the data we have - base: Vec, + base: Vec, } /// The information you need to request Images from the `/cdn/{size}/{id}_{counter}.webp` endpoint #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct ImageInfo { +struct ImageInfoResponse { /// The name of the image file. /// consists of {building_id}_{image_id}.webp, where image_id is a counter starting at 0 #[schema(examples("mi_0.webp"))] name: String, - author: URLRef, - source: PossibleURLRef, - license: PossibleURLRef, + author: URLRefResponse, + source: PossibleURLRefResponse, + license: PossibleURLRefResponse, } /// A link with a localized link text and url #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct PossibleURLRef { +struct PossibleURLRefResponse { text: String, #[serde(skip_serializing_if = "Option::is_none")] url: Option, @@ -429,24 +430,29 @@ struct PossibleURLRef { /// A link with a localized link text and url #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct URLRef { +struct URLRefResponse { text: String, url: Option, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct RankingFactors { - rank_combined: u32, - rank_type: u32, - rank_usage: u32, +struct RankingFactorsResponse { + #[schema(minimum = 0)] + rank_combined: i32, + #[schema(minimum = 0)] + rank_type: i32, + #[schema(minimum = 0)] + rank_usage: i32, #[serde(skip_serializing_if = "Option::is_none")] - rank_boost: Option, + #[schema(minimum = 0)] + rank_boost: Option, #[serde(skip_serializing_if = "Option::is_none")] - rank_custom: Option, + #[schema(minimum = 0)] + rank_custom: Option, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] -struct Coordinate { +struct CoordinateResponse { /// Latitude #[schema(example = 48.26244490906312)] lat: f64, @@ -455,24 +461,24 @@ struct Coordinate { lon: f64, /// Source of the Coordinates #[schema(example = "navigatum")] - source: CoordinateSource, + source: CoordinateSourceResponse, /// How accurate the coordinate is. /// Only present, if it is limited to a degree (e.g. we only know the building) #[serde(skip_serializing_if = "Option::is_none")] #[schema(example = "building")] - accuracy: Option, + accuracy: Option, } #[derive(Deserialize, Serialize, Debug, Default, utoipa::ToSchema)] #[serde(rename_all = "snake_case")] -enum CoordinateAccuracy { +enum CoordinateAccuracyResponse { #[default] Building, } #[derive(Serialize, Deserialize, Debug, Default, utoipa::ToSchema)] #[serde(rename_all = "snake_case")] -enum CoordinateSource { +enum CoordinateSourceResponse { #[default] Navigatum, Roomfinder,