Skip to content

Commit

Permalink
further work
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Dec 25, 2024
1 parent 32015e0 commit 3d28303
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 24 deletions.
7 changes: 4 additions & 3 deletions server/Cargo.lock

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

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ actix-middleware-etag = "0.4.2"
utoipa-actix-web = "0.1.2"
utoipa = { version = "5.2.0", features = ["yaml", "chrono", "actix_extras", "url"] }
utoipa-redoc = { version = "5.0.0", features = ["actix-web"] }
url = "2.5.4"

[dev-dependencies]
insta = { version = "1.39.0", features = ["json", "redactions", "yaml"] }
Expand Down
5 changes: 2 additions & 3 deletions server/src/calendar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use serde_json::json;
pub struct Arguments {
/// ids you want the calendars for
///
/// The limit of max. 10 ids is pretty arbitrary.
/// We suspect that users don't need this.
/// If you need this limit increased, please send us a message
/// Limit of max. 10 ids is arbitraryly chosen, if you need this limit increased, please contact us
#[schema(max_items=10,min_items=1,example=json!(["5605.EG.011","5510.02.001","5606.EG.036","5304"]))]
ids: Vec<String>,
/// The first allowed time the calendar would like to display
Expand Down Expand Up @@ -69,6 +67,7 @@ impl Arguments {
tags=["calendar"],
responses(
(status = 200, description = "**Entries of the calendar** in the requested time span", body = HashMap<String, LocationEvents>, content_type = "application/json"),
(status = 400, description= "**Bad Request.** Not all fields in the body are present as defined above", body = String, example = "Too many ids to query. We suspect that users don't need this. If you need this limit increased, please send us a message"),
(status = 404, description = "**Not found.** The requested location does not have a calendar", body = String, content_type = "text/plain", example = "Not found"),
(status = 503, description = "**Not Ready.** please retry later", body = String, content_type = "text/plain", example = "Waiting for first sync with TUMonline"),
)
Expand Down
9 changes: 7 additions & 2 deletions server/src/feedback/post_feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use serde::{Deserialize, Serialize};

use super::github;
use super::tokens::RecordedTokens;
#[expect(
unused_imports,
reason = "has to be imported as otherwise utoipa generates incorrect code"
)]
use url::Url;

#[derive(Deserialize, Serialize, Default, utoipa::ToSchema)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -69,7 +74,7 @@ pub struct FeedbackPostData {
///
/// This posts the actual feedback to GitHub and returns the GitHub link.
/// This API will create issues instead of pull-requests
/// => all feedback is allowed, but `/api/feedback/propose_edit` is preferred, if it can be posted there.
/// => all feedback is allowed, but [`/api/feedback/propose_edits`](#tag/feedback/operation/propose_edits) is preferred, if it can be posted there.
///
/// For this Endpoint to work, you need to generate a token via the [`/api/feedback/get_token`](#tag/feedback/operation/get_token) endpoint.
///
Expand All @@ -80,7 +85,7 @@ pub struct FeedbackPostData {
#[utoipa::path(
tags=["feedback"],
responses(
(status = 201, description = "The feedback has been **successfully posted to GitHub**. We return the link to the GitHub issue.", body = String, content_type = "text/plain", example = "https://github.com/TUM-Dev/navigatum/issues/9"),
(status = 201, description = "The feedback has been **successfully posted to GitHub**. We return the link to the GitHub issue.", body = Url, content_type = "text/plain", example = "https://github.com/TUM-Dev/navigatum/issues/9"),
(status = 400, description = "**Bad Request.** Not all fields in the body are present as defined above"),
(status = 403, description = r#"**Forbidden.** Causes are (delivered via the body):
Expand Down
11 changes: 8 additions & 3 deletions server/src/feedback/proposed_edits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use actix_web::web::{Data, Json};
use actix_web::{post, HttpResponse};
use serde::Deserialize;
use tracing::error;
#[expect(
unused_imports,
reason = "has to be imported as otherwise utoipa generates incorrect code"
)]
use url::Url;

use crate::limited::hash_map::LimitedHashMap;

Expand Down Expand Up @@ -112,15 +117,15 @@ impl EditRequest {
///
/// This posts the actual feedback to GitHub and returns the github link.
/// This API will create pull-requests instead of issues => only a subset of feedback is allowed.
/// For this Endpoint to work, you need to generate a token via the `/api/feedback/get_token` endpoint.
/// For this Endpoint to work, you need to generate a token via the [`/api/feedback/get_token`](#tag/feedback/operation/get_token) endpoint.
///
/// # Note:
///
/// Tokens are only used if we return a 201 Created response. Otherwise, they are still valid
#[utoipa::path(
tags=["feedback"],
responses(
(status = 201, description= "The edit request feedback has been **successfully posted to GitHub**. We return the link to the GitHub issue.", body= String, content_type="text/plain", example="https://github.com/TUM-Dev/navigatum/issues/9"),
(status = 201, description= "The edit request feedback has been **successfully posted to GitHub**. We return the link to the GitHub issue.", body= Url, content_type="text/plain", example="https://github.com/TUM-Dev/navigatum/issues/9"),
(status = 400, description= "**Bad Request.** Not all fields in the body are present as defined above"),
(status = 403, description= r#"**Forbidden.** Causes are (delivered via the body):
Expand All @@ -134,7 +139,7 @@ impl EditRequest {
(status = 503, description= "Service unavailable. We have not configured a GitHub Access Token. This could be because we are experiencing technical difficulties or intentional. Please try again later."),
)
)]
#[post("/api/feedback/propose_edit")]
#[post("/api/feedback/propose_edits")]
pub async fn propose_edits(
recorded_tokens: Data<RecordedTokens>,
req_data: Json<EditRequest>,
Expand Down
47 changes: 37 additions & 10 deletions server/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,29 @@ pub struct SearchQueryArgs {
/// The amounts returned can be controlled using the `limit\*` paramerters.
///
/// The following query-filters are supported:
/// - `in:<parent>`: Only return rooms in the given parent (e.g. `in:5304` or `in:garching`)
/// alternative syntax:
/// - `@<parent>`
/// - `usage:<type>`: Only return entries of the given usage (e.g. `usage:wc` or `usage:büro`)
/// alternative syntax:
/// - `nutzung:<usage>`
/// - `=<usage>`
/// - `in:<parent>`/`@<parent>`: Only return rooms in the given parent (e.g. `in:5304` or `in:garching`)
/// - `usage:<type>`/`nutzung:<usage>`/`=<usage>`: Only return entries of the given usage (e.g. `usage:wc` or `usage:büro`)
/// - `type:<type>`: Only return entries of the given type (e.g. `type:building` or `type:room`)
/// - `near:<lat>,<lon>`: prioritise sorting the entries by distance to a coordinate
#[schema(
min_length = 1,
examples(
"mi hs1",
"sfarching",
"5606.EG.036",
"interims",
"AStA",
"WC @garching"
)
)]
// TODO ideally, this would be documented as below, but this does for some reaon not work.
// examples(
// ("mi hs1" = (summary = "\'misspelled\' (according to tumonline) lecture-hall", value = "mi hs1")),
// ("sfarching" = (summary = "misspelled campus garching", value = "sfarching")),
// ("5606.EG.036" = (summary = "regular room (fsmpic)", value = "5606.EG.036")),
// ("interims" = (summary = "\'interims\' Lecture halls", value = "interims")),
// ("AStA" = (summary = "common name synonyms for SV", value = "AStA")),
//))]
q: String,
/// Include adresses in the saerch
///
Expand Down Expand Up @@ -56,12 +71,24 @@ pub struct SearchQueryArgs {
/// string to include in front of highlighted sequences.
///
/// If this and `post_highlight` are empty, highlighting is disabled.
#[schema(default = "/u0019", max_length = 25, max_length = 0)]
/// For background on the default values, please see [Wikipedia](https://en.wikipedia.org/wiki/C0_and_C1_control_codes#Modified_C0_control_code_sets)).
#[schema(
default = "/u0019",
max_length = 25,
max_length = 0,
examples("/u0019", "<em>", "<ais-highlight-00000000>")
)]
pre_highlight: Option<String>,
/// string to include after the highlighted sequences.
///
/// If this and `pre_highlight` are empty, highlighting is disabled.
#[schema(default = "/u0017", max_length = 25, max_length = 0)]
/// For background on the default values, please see [Wikipedia](https://en.wikipedia.org/wiki/C0_and_C1_control_codes#Modified_C0_control_code_sets)).
#[schema(
default = "/u0017",
max_length = 25,
max_length = 0,
examples("/u0017", "</em>", "</ais-highlight-00000000>")
)]
post_highlight: Option<String>,
}

Expand Down Expand Up @@ -202,7 +229,7 @@ impl From<&SearchQueryArgs> for Highlighting {
(status = 200, description = "Search entries", body = Vec<SearchResults>, content_type = "application/json"),
(status = 400, description= "**Bad Request.** Not all fields in the body are present as defined above", body = String, content_type = "text/plain", example = "Query deserialize error: invalid digit found in string"),
(status = 404, description = "**Not found.** `q` is empty. Since searching for nothing is nonsensical, we dont support this.", body = String, content_type = "text/plain", example = "Not found"),
(status = 414, description = "The uri you are trying to request is unreasonably long. Search querys dont have thousands of chars..", body = String, content_type = "text/plain"),
(status = 414, description = "**URI Too Long.** The uri you are trying to request is unreasonably long. Search querys dont have thousands of chars..", body = String, content_type = "text/plain"),
)
)]
#[get("/api/search")]
Expand Down
10 changes: 7 additions & 3 deletions server/src/search/search_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod merger;
mod parser;
mod query;

#[derive(Serialize, Clone, Copy)]
#[derive(Serialize, Clone, Copy, utoipa::ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum ResultFacet {
SitesBuildings,
Expand All @@ -30,9 +30,8 @@ pub struct ResultsSection {
entries: Vec<ResultEntry>,
/// A recommendation how many of the entries should be displayed by default.
///
/// The number is usually from 0-5.
/// The number is usually from `0`..`5`.
/// More results might be displayed when clicking "expand".
/// If this field is not present, then all entries are displayed.
#[schema(example = 4)]
n_visible: usize,
/// The estimated (not exact) number of hits for that query
Expand Down Expand Up @@ -61,23 +60,28 @@ struct ResultEntry {
#[serde(skip)]
hit: MSHit,
/// The id of the location
#[schema(example = "5510.03.002")]
id: String,
/// the type of the site/building
#[schema(example = "room")]
r#type: String,
/// Subtext to show below the search result.
///
/// Usually contains the context of where this rooms is located in.
/// Currently not highlighted.
#[schema(example = "5510.03.002 (\x19MW\x17 2001, Empore)")]
name: String,
/// Subtext to show below the search result.
///
/// Usually contains the context of where this rooms is located in.
/// Currently not highlighted.
#[schema(example = "Maschinenwesen (MW)")]
subtext: String,
/// Subtext to show below the search (by default in bold and after the non-bold subtext).
///
/// Usually contains the arch-id of the room, which is another common room id format, and supports highlighting.
#[serde(skip_serializing_if = "Option::is_none")]
#[schema(example = "3002@5510")]
subtext_bold: Option<String>,
/// This is an optional feature, that is only supported for some rooms.
///
Expand Down

0 comments on commit 3d28303

Please sign in to comment.