Skip to content

Commit

Permalink
removed json import and added abort to canvas functions
Browse files Browse the repository at this point in the history
  • Loading branch information
star-nox committed Oct 2, 2023
1 parent 2e10cc8 commit a38fb90
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ai_ta_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import time
from typing import List
import json

from dotenv import load_dotenv
from flask import Flask, Response, abort, jsonify, request
Expand Down Expand Up @@ -401,6 +400,15 @@ def ingest_canvas():
canvas = CanvasAPI()
canvas_course_id: str = request.args.get('course_id')
course_name: str = request.args.get('course_name')

if canvas_course_id == '' or course_name == '':
# proper web error "400 Bad request"
abort(
400,
description=
f"Missing one or more required parameters: 'course_id' and 'course_name' must be provided. course_id: `{canvas_course_id}`, course_name: `{course_name}`"
)

success_or_failure = canvas.ingest_course_content(canvas_course_id, course_name)
response = jsonify({"outcome": success_or_failure})
response.headers.add('Access-Control-Allow-Origin', '*')
Expand All @@ -414,6 +422,15 @@ def update_canvas():
canvas = CanvasAPI()
canvas_course_id: str = request.args.get('course_id')
course_name: str = request.args.get('course_name')

if canvas_course_id == '' or course_name == '':
# proper web error "400 Bad request"
abort(
400,
description=
f"Missing one or more required parameters: 'course_id' and 'course_name' must be provided. course_id: `{canvas_course_id}`, course_name: `{course_name}`"
)

success_or_failure = canvas.update_course_content(canvas_course_id, course_name)
response = jsonify({"outcome": success_or_failure})
response.headers.add('Access-Control-Allow-Origin', '*')
Expand Down

0 comments on commit a38fb90

Please sign in to comment.