From 0d1fb25658c53a17c223d3fd4b062092a5dc601b Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 4 Apr 2024 23:38:27 +1100 Subject: [PATCH] add courses run in prev years to /dump route (#1114) --- backend/server/routers/courses.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/backend/server/routers/courses.py b/backend/server/routers/courses.py index 18bfb5a53..10d38411d 100644 --- a/backend/server/routers/courses.py +++ b/backend/server/routers/courses.py @@ -89,17 +89,34 @@ def get_jsonified_course(courseCode: str) -> str: def get_courses() -> list[Dict]: """ Gets all courses in the database. - (For CSElectives), by yours truly, Aimen 💫 + (For CSElectives) """ - courses = [] - for course in coursesCOL.find(): - course["is_legacy"] = False + + def generate_course(course, is_legacy): + course["is_legacy"] = is_legacy course.setdefault("school", None) del course["_id"] with suppress(KeyError): del course["exclusions"]["leftover_plaintext"] - courses.append(course) - return courses + return course + + all_courses = fetch_all_courses() + + courses = dict() + for course in coursesCOL.find(): + courses[course["code"]] = generate_course(course, False) + + years = list(map(str, sorted(ARCHIVED_YEARS, reverse=True))) + for course_code in all_courses: + if course_code in courses: + continue + for year in years: + course = archivesDB[year].find_one({"code": course_code}) + if course: + courses[course["code"]] = generate_course(course, True) + break + + return list(courses.values()) @router.get( "/getCourse/{courseCode}",