From 3e5cd4c0d9e38489e6f6a5abab73b11cb08169e5 Mon Sep 17 00:00:00 2001 From: Andrew Orals Date: Wed, 21 Feb 2024 11:51:26 -0600 Subject: [PATCH] Make extensions api route atomic --- src/routes_api.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/routes_api.py b/src/routes_api.py index 28aa639..92f0e79 100644 --- a/src/routes_api.py +++ b/src/routes_api.py @@ -69,10 +69,15 @@ def add_extensions(cid, aid): assignment = db.get_assignment(cid, aid) if not assignment: - return util.error("Invalid course or assignment. Please try again.") + return util.error("Invalid course or assignment.\nPlease try again.") if util.check_missing_fields(form, "extensions"): return util.error(f"Missing fields extensions.\nPlease try again.") + + if type(form["extensions"]) != list: + return util.error(f"Field extensions must be a list.\nPlease try again.") + + extensions_to_add = [] for ext_json in form["extensions"]: missing = util.check_missing_fields(ext_json, "netids", "max_runs", "start", "end") @@ -105,7 +110,11 @@ def add_extensions(cid, aid): return util.error("Start must be before End.") for student_netid in student_netids: - db.add_extension(cid, aid, student_netid, max_runs, start, end) + extensions_to_add.append((student_netid, max_runs, start, end)) + + for student_netid, max_runs, start, end in extensions_to_add: + db.add_extension(cid, aid, student_netid, max_runs, start, end) + return util.success("Successfully uploaded extensions", HTTPStatus.OK) @blueprint.route("/api//add_assignment", methods=["POST"])