Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[breaking, api] Removed /api/get/root route #1154

Merged
merged 10 commits into from
May 6, 2024
4 changes: 4 additions & 0 deletions data/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def main() -> None:
search.add_ranking_combined(data)

logging.info("-- 100 Export and generate Sitemap")
# the root entry is somewhat arbitrary
# leaving it here and thus having it delivered by the other apis leads to bad ergonomics
# => we construct the frontpage "manually" with the most popular buildings
data.pop("root")
export.export_for_search(data, "output/search_data.json")
export.export_for_api(data, "output/api_data.json")
sitemap.generate_sitemap() # only for deployments
Expand Down
17 changes: 9 additions & 8 deletions data/processors/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from external.models.common import PydanticConfiguration
from utils import TranslatableStr
from utils import TranslatableStr as _

OUTPUT_DIR = Path(__file__).parent.parent / "output"
SLUGIFY_REGEX = re.compile(r"[^a-zA-Z0-9-äöüß.]+")
Expand Down Expand Up @@ -42,21 +43,21 @@ def export_for_search(data: dict, path: str) -> None:
"""Export a subset of the data for the /search api"""
export = []
for _id, entry in data.items():
# Currently, the "root" entry is excluded from search
if _id == "root":
continue

building_parents_index = len(entry["parents"])
if entry["type"] in {"room", "virtual_room"}:
for i, parent in enumerate(entry["parents"]):
if parent == "root":
continue
if data[parent]["type"] in {"building", "joined_building"}:
building_parents_index = i
break

# The 'campus name' is the campus of site of this building or room
campus_name = None
if entry["type"] not in {"root", "campus", "site"}:
if entry["type"] not in {"campus", "site"}:
for parent in entry["parents"]:
if parent == "root":
continue
if data[parent]["type"] in {"campus", "site"}:
campus = data[parent]
campus_name = campus.get("short_name", campus["name"])
Expand Down Expand Up @@ -124,8 +125,7 @@ def export_for_api(data: dict, path: str) -> None:
"""Add some more information about parents to the data and export for the /get/:id api"""
export_data = []
for _id, entry in data.items():
if entry["type"] != "root":
entry.setdefault("maps", {})["default"] = "interactive"
entry.setdefault("maps", {})["default"] = "interactive"

entry["aliases"] = []
if arch_name := extract_arch_name(entry):
Expand All @@ -139,8 +139,9 @@ def export_for_api(data: dict, path: str) -> None:

def extract_exported_item(data, entry):
"""Extract the item that will be finally exported to the api"""
parent_names = [data[p]["name"] if not p == "root" else _("Standorte", "Sites") for p in entry["parents"]]
result = {
"parent_names": [data[p]["name"] for p in entry["parents"]],
"parent_names": parent_names,
**entry,
}
if "children" in result:
Expand Down
5 changes: 0 additions & 5 deletions data/processors/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def _extract_sitemap_data(new_data: list, old_data: list, old_sitemaps: Simplifi
# so it's unlikely that we'll hit this limit without adding a lot of
# data. But for the case that a new type of entry is introduced, the
# sitemap is split into one for rooms and one for the rest.
# Note that the root element is not included, because it just redirects
# to the main page.
sitemaps: Sitemaps = {
"room": [],
"other": [],
Expand All @@ -93,9 +91,6 @@ def _extract_sitemap_data(new_data: list, old_data: list, old_sitemaps: Simplifi
new_data_dict = {entry["id"]: entry for entry in new_data}
changed_count = 0
for _id, entry in new_data_dict.items():
if entry["type"] == "root":
continue

sitemap_name: Literal["room"] | Literal["other"] = entry["type"] if entry["type"] in sitemaps else "other"

# Just copied from the webclient.
Expand Down
Loading
Loading