Skip to content

Commit

Permalink
testing add methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdul-123456 committed Oct 25, 2023
1 parent 1a17c15 commit cb4f39f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
19 changes: 10 additions & 9 deletions src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,11 @@ async def addBulkFinals(file : UploadFile):
return finals if not error else Response(content=error, status_code=500)


@app.post('/api/finals/addFinal/{msg}')
async def addFinal(msg : str):
info = msg.split(",")
info, error = finals_info.add_final(info[0], info[1], info[2], info[3], info[4], info[5], info[6])
@app.get('/api/finals/addFinal')
async def addFinal():
#info = msg.split(",")
info, error = finals_info.add_final("Mathematics", "MATH 4100", "01", "DCC 318", "Monday", "1-May", "600")
#info, error = finals_info.add_final(info[0], info[1], info[2], info[3], info[4], info[5], info[7])
return info if not error else Response(content=error, status_code=500)

#get all finals info
Expand Down Expand Up @@ -442,12 +443,12 @@ async def get_finals_by_hour(room: str):
return finals if not error else Response(content=error, status_code=500)

#delete by course code and section
@app.delete('/api/finals/remove')
@app.get('/api/finals/remove')
async def delete_final_by_courseCodeSection(courseCode: str, section: str):
message, error = finals_info.remove_final(courseCode, section)
finals_info.db_conn.commit()
return message if not error else Response(content=error, status_code=500)

return finals_info.remove_final(courseCode, section)
# message, error = finals_info.remove_final(courseCode, section)
# #finals_info.db_conn.commit()
# return message if not error else Response(content=error, status_code=500)

#delete all finals
@app.delete('/api/finals/removeBulkFinal')
Expand Down
43 changes: 27 additions & 16 deletions src/api/db/finals.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Finals:
def __init__(self, db_conn, cache):
self.db_conn = db_conn
self.cache = cache

def add_bulk_final(self, file):
list = []
with open(file, "r") as json_file:
Expand All @@ -40,8 +40,8 @@ def add_bulk_final(self, file):

def add_final(self, department, courseCode,
section, room, dof, day, hour):
query = "SELECT COUNT(*) FROM finals WHERE courseCode = \'" + courseCode + "\' AND section = " + str(section) + ";"
records = self.db_conn.execute(query)
# query = "SELECT COUNT(*) FROM finals WHERE courseCode = \'" + courseCode + "\' AND section = " + str(section) + ";"
# records = self.db_conn.execute(query)
if department is None:
return (False, "Department cannot be none")
elif courseCode is None:
Expand All @@ -56,13 +56,20 @@ def add_final(self, department, courseCode,
return (False, "Day cannot be none")
elif hour is None:
return (False, "Hour cannot be none")
elif (records[0] > 0):
return(False, "A record with the Course Code" + courseCode + " and Section = " + section + " already exists")
# elif (records[0] > 0):
# return(False, "A record with the Course Code" + courseCode + " and Section = " + section + " already exists")
else:
query = "INSERT INTO finals VALUES(%s, %s, %s, %s, %s, %s, %s);"
values = (department, courseCode, section, room, dof, day, hour)
return self.db_conn.execute(query, values, True)

query = "BEGIN TRANSACTION; INSERT INTO finals (department, courseCode, section, room, dayOfWeek, day, hour) VALUES(%(department)s, %(courseCode)s, %(section)s, %(room)s, %(dayOfWeek)s, %(day)s, %(hour)s); COMMIT;"
return self.db_conn.execute(query, {
"department": department,
"courseCode": courseCode,
"section": section,
"room": room,
"dayOfWeek": dof,
"day": day,
"hour": hour
}, False)

def clear_cache(self):
try:
loop = asyncio.get_running_loop()
Expand Down Expand Up @@ -146,13 +153,17 @@ def remove_bulk_final(self, file):
return list

def remove_final(self, courseCode, section):
if courseCode is None:
return (False, "Course Code cannot be none")
elif section is None:
return (False, "Section cannot be none")
query = "DELETE FROM finals WHERE courseCode = \'" + courseCode + "\' AND section = \'" + section + "\';"
return self.db_conn.execute(query, None, True)

self.clear_cache()
return self.db_conn.execute("""
BEGIN TRANSACTION;
DELETE FROM finals
WHERE courseCode=%(courseCode)s AND section=%(section)s;
COMMIT;
""", {
"courseCode": courseCode,
"section": section
}, isSELECT=False)

def update_final(self, courseCode, section, column : str, value : str):
if courseCode is None:
return (False, "CourseCode cannot be none")
Expand Down
1 change: 1 addition & 0 deletions src/web/src/pages/EditFinals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export default {
console.log("add_final");
let str = this.deparmtent + "," + this.courseCode + "," + this.section + "," + this.room + "," + this.dayOfWeek + "," + this.day + "," + this.hour;
this.result = add_final(str);
//this.result = add_final(this.deparmtent, this.courseCode, this.section, this.room, this.dayOfWeek, this.day, this.hour)
console.log(this.result);
},
remove_bulk_final() {
Expand Down

0 comments on commit cb4f39f

Please sign in to comment.