-
Notifications
You must be signed in to change notification settings - Fork 2
/
dao.py
28 lines (26 loc) · 1.02 KB
/
dao.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def get_course_config(courses_collection, course_code):
if courses_collection.find_one({"course_code": course_code}) == None:
# create a new course config
courses_collection.insert_one({
"course_code": course_code,
"course_description": "",
"uploaded_files": {
"slides": [],
"assignments": [],
"syllabus": []
},
"system_prompt": "",
"course_title": "",
"messages": []
})
return courses_collection.find_one({"course_code": course_code})
else:
return courses_collection.find_one({"course_code": course_code})
def update_course_config(courses_collection, course_code, new_config):
if courses_collection.find_one({"course_code": course_code}) == None:
# insert to config
courses_collection.insert_one(new_config)
else:
# update config
courses_collection.update_one(
{"course_code": course_code}, {"$set": new_config})