-
Notifications
You must be signed in to change notification settings - Fork 0
get-course-info endpoint #22
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| # course-selection | ||
| # course-selection | ||
| # Running the Program -- Frontend. | ||
| To run the program, cd into the front_end directory. | ||
| Run ```npm install``` to install the required packages. | ||
| Use ```npm start``` to run the program. It will run on localhost:3000 | ||
|
|
||
|
|
||
| # Running the Program -- Backend. | ||
| To run the program, ensure that your .env files are set up. See back_end README.md for instructions. | ||
|
|
||
| Then, use ```flask run``` to run the program. It will run on localhost:5000 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from flask import jsonify | ||
| from pymongo import MongoClient | ||
| from dotenv import load_dotenv | ||
| import logging | ||
|
|
@@ -27,9 +28,11 @@ def __init__(self): | |
| self.db = self.client.course_selection | ||
|
|
||
| def connect(self): | ||
| self.client = MongoClient(os.getenv("MONGO"), tlsCAFile=certifi.where()) | ||
| self.client = MongoClient(os.getenv("MONGO"), | ||
| tlsCAFile=certifi.where()) | ||
| self.db_admin = self.client.admin | ||
| logger.info(f"MongoDB server status: {self.db_admin.command('serverStatus')}") | ||
| logger.info( | ||
| f"MongoDB server status: {self.db_admin.command('serverStatus')}") | ||
|
|
||
| def get_all_test(self): | ||
| # note that when you are returning, you want it to be jsonify-able, | ||
|
|
@@ -48,11 +51,60 @@ def get_all_test(self): | |
| ret = None | ||
| return ret | ||
|
|
||
| def get_course_info(self, course_id, semester): | ||
| """ | ||
| Retrieves course info from the database for a specific | ||
| course_id, from a given semester | ||
|
|
||
| Semester is of format Spring/Summer/Fall Year | ||
|
|
||
| This information includes all course evaluation data across | ||
| different terms for this course_id | ||
|
|
||
| params: query = { | ||
| "course_id": "the course_id", | ||
| "semester = "semester_in_words" | ||
|
Comment on lines
+65
to
+66
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formatting of one of these two lines is off. I know this is just documentation so it doesn't affect the functionality, but best to clean it before merging in. |
||
| } | ||
|
|
||
| Example from COS 126, Fall 2021: | ||
| query = { "course_id": "002051", "semester": "Fall 2021" } | ||
| """ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also specify what the format of the returned value is? I can find it by running it, but it's good to document the format. |
||
| if course_id == "": | ||
| return [], [] | ||
|
|
||
| try: | ||
| # Assume semester is passed in as "[Fall/Spring/Summer] [Year]" | ||
| term_data = self.db.semesters.find_one( | ||
| {"name": semester}, {"_id": 0, "code": 1} | ||
| ) | ||
| if term_data is not None: | ||
| term = term_data["code"] | ||
|
|
||
| course_db = self.db.courses | ||
| evals_db = self.db.evaluations | ||
| course_query_string = {'course_id': course_id, 'term': term} | ||
| course_res = course_db.find(course_query_string, | ||
| {"_id": 0}) | ||
| eval_query_string = {'course_id': course_id} | ||
| eval_res = evals_db.find(eval_query_string, {"_id": 0}) | ||
| course_res = list(course_res) | ||
| eval_res = list(eval_res) | ||
| ret = course_res + eval_res | ||
| except Exception as e: | ||
| logger.error( | ||
| f"Failed to get information for course_id {course_id}. " | ||
| f"Error displayed below:\n{e}" | ||
| ) | ||
| ret = None | ||
| # Note, right now this returns a ton of information | ||
| # If this information is difficult to use on the front end | ||
| # This code can be modified going forward to meet this need | ||
| return ret | ||
|
|
||
| def close(self): | ||
| self.client.close() | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| # a basic example of how to use, can remove later | ||
| db = DatabaseAPI() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for documenting this! We should probably expand this readme even further at some point with more specific instructions, as well as an overview of the project (in a future pull request, of course, not here!).