Spaces:
Running
Running
Update routes.py
Browse files
routes.py
CHANGED
|
@@ -35,12 +35,35 @@ def requires_auth(f):
|
|
| 35 |
return decorated
|
| 36 |
|
| 37 |
# /student endpoint: returns student data without schedule details.
|
|
|
|
| 38 |
@bp.route('/student', methods=['GET'])
|
| 39 |
@requires_auth
|
| 40 |
def get_student():
|
| 41 |
try:
|
|
|
|
| 42 |
student_copy = student_data.copy()
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
return jsonify(student_copy)
|
| 45 |
except Exception as e:
|
| 46 |
logger.exception("Error processing /student endpoint.")
|
|
|
|
| 35 |
return decorated
|
| 36 |
|
| 37 |
# /student endpoint: returns student data without schedule details.
|
| 38 |
+
# /student endpoint: returns student data AND schedule details.
|
| 39 |
@bp.route('/student', methods=['GET'])
|
| 40 |
@requires_auth
|
| 41 |
def get_student():
|
| 42 |
try:
|
| 43 |
+
# Make a copy of student data
|
| 44 |
student_copy = student_data.copy()
|
| 45 |
+
|
| 46 |
+
# Retrieve the current schedule from the student data
|
| 47 |
+
current_schedule = student_copy.get('current_schedule')
|
| 48 |
+
|
| 49 |
+
# If current_schedule is a list and not empty, gather details from courses_data
|
| 50 |
+
if isinstance(current_schedule, list) and current_schedule:
|
| 51 |
+
detailed_schedule = []
|
| 52 |
+
for course_code in current_schedule:
|
| 53 |
+
course = next((c for c in courses_data if c.get('code') == course_code), None)
|
| 54 |
+
if course:
|
| 55 |
+
detailed_schedule.append({
|
| 56 |
+
"code": course.get("code"),
|
| 57 |
+
"title": course.get("title"),
|
| 58 |
+
"tentative_schedule": course.get("tentative_schedule")
|
| 59 |
+
})
|
| 60 |
+
# Replace the course codes in student_copy with the fully detailed schedule
|
| 61 |
+
student_copy['current_schedule'] = detailed_schedule
|
| 62 |
+
else:
|
| 63 |
+
# If no courses are registered, set a descriptive string
|
| 64 |
+
student_copy['current_schedule'] = "No courses registered - schedule is currently free"
|
| 65 |
+
|
| 66 |
+
logger.info("Returning student data (including schedule) for user: %s", student_copy.get('username'))
|
| 67 |
return jsonify(student_copy)
|
| 68 |
except Exception as e:
|
| 69 |
logger.exception("Error processing /student endpoint.")
|