Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
Co-Authored-By: samhpark1 <97241842+samhpark1@users.noreply.github.com>
  • Loading branch information
Abdul-123456 and samhpark1 committed Oct 24, 2023
1 parent 79c665f commit 1a17c15
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 34 deletions.
5 changes: 5 additions & 0 deletions src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ async def get_finals_by_hour(hour: str):
finals, error = finals_info.get_info_by_hour(hour)
return finals if not error else Response(content=error, status_code=500)

@app.get('/api/finals/room/{room}')
async def get_finals_by_hour(room: str):
finals, error = finals_info.get_info_by_room(room)
return finals if not error else Response(content=error, status_code=500)

#delete by course code and section
@app.delete('/api/finals/remove')
async def delete_final_by_courseCodeSection(courseCode: str, section: str):
Expand Down
56 changes: 31 additions & 25 deletions src/api/db/finals.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,6 @@ def add_bulk_final(self, file):
self.clear_cache()
return list

def remove_bulk_final(self, file):
list = []

with open(file, "r") as json_file:
data = json.load(json_file)

for i in data:
if i['Section'] == "(ALL SECTIONS)":
section = "AllSections"
else:
section = i['Section']
list.append(self.remove_final(i['CourseCode'], section))
self.db_conn.commit()
self.clear_cache()
return list

def add_final(self, department, courseCode,
section, room, dof, day, hour):
query = "SELECT COUNT(*) FROM finals WHERE courseCode = \'" + courseCode + "\' AND section = " + str(section) + ";"
Expand Down Expand Up @@ -89,6 +73,14 @@ def clear_cache(self):
loop.create_task(self.cache.clear(namespace="API_CACHE"))
else:
asyncio.run(self.cache.clear("API_CACHE"))

def findCol(self, column):
i=0
for cols in columns:
if cols.lower() == column:
return (True, crr[i])
i+=1
return (False, column)

def get_all_final_info(self):
return self.db_conn.execute("SELECT * FROM finals;", None, True)
Expand Down Expand Up @@ -130,22 +122,36 @@ def get_info_by_hour(self, hour):
return(False, "Hour cannot be None")
query = "SELECT * FROM finals WHERE hour = \'" + hour + "\';"
return self.db_conn.execute(query, None, True)


def get_info_by_room(self, room):
if room is None:
return(False, "Room cannot be None")
query = "SELECT * FROM finals WHERE room = \'" + room + "\';"
return self.db_conn.execute(query, None, True)

def remove_bulk_final(self, file):
list = []

with open(file, "r") as json_file:
data = json.load(json_file)

for i in data:
if i['Section'] == "(ALL SECTIONS)":
section = "AllSections"
else:
section = i['Section']
list.append(self.remove_final(i['CourseCode'], section))
self.db_conn.commit()
self.clear_cache()
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)

def findCol(self, column):
i=0
for cols in columns:
if cols.lower() == column:
return (True, crr[i])
i+=1
return (False, column)

def update_final(self, courseCode, section, column : str, value : str):
if courseCode is None:
Expand Down
66 changes: 58 additions & 8 deletions src/web/src/pages/EditFinals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,36 @@
placeholder="Enter Hour"
/>
</div>
<div class="form-group">
<label for="hour">File:</label>
<input
v-model="file"
type="text"
class="form-control"
id="file"
placeholder="Enter File Name"
/>
</div>
<div class="form-group">
<label for="updateColumn">Update Column:</label>
<input
v-model="updateColumn"
type="text"
class="form-control"
id="updateColumn"
placeholder="Enter Column Name"
/>
</div>
<div class="form-group">
<label for="updateVal">Update Value:</label>
<input
v-model="updateVal"
type="text"
class="form-control"
id="updateVal"
placeholder="Enter Update Value"
/>
</div>
<div class="form-group">
<label for="result">Result:</label>
<p id="result">{{ this.result }}</p>
Expand All @@ -83,8 +113,12 @@
<button @click="get_info_by_day()" class="btn btn-primary">Get Final by Day</button>
<button @click="get_info_by_department()" class="btn btn-primary">Get Final by Department</button>
<button @click="get_info_by_hour()" class="btn btn-primary">Get Final by Hour</button>
<button @click="get_info_by_room()" class="btn btn-primary">Get Final by Room</button>
<button @click="add_final()" class="btn btn-success">Add Final</button>
<button @click="add_bulk_final()" class="btn btn-success">Add Bulk Final</button>
<button @click="remove_final()" class="btn btn-danger">Remove Final</button>
<button @click="remove_bulk_final()" class="btn btn-danger">Remove Bulk Final</button>
<button @click="update_final()" class="btn btn-primary">Update Final</button>
</section>
</b-container>
</template>
Expand All @@ -98,13 +132,14 @@ import {
get_info_by_department,
get_info_by_DOW,
get_info_by_hour,
get_info_by_room,
} from "@/services/YacsService";
import {
// add_bulk_final,
// remove_bulk_final,
add_bulk_final,
remove_bulk_final,
add_final,
remove_final,
// update_final,
update_final,
} from "@/services/AdminService";
export default {
Expand Down Expand Up @@ -157,22 +192,37 @@ export default {
this.result = get_info_by_hour(this.hour);
console.log(this.result);
},
get_info_by_room() {
console.log("get_info_by_room");
this.result = get_info_by_room(this.room);
console.log(this.result);
},
add_final() {
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);
console.log(this.result);
},
remove_bulk_final() {
console.log("remove_bulk_final");
this.result = remove_bulk_final(this.file);
console.log(this.result);
},
remove_final() {
console.log("remove_final");
this.result = remove_final(this.courseCode, this.section);
console.log(this.result);
},
// update_final() {
// console.log("update_final");
// this.result = update_final(this.courseCode, this.section, this.column, this.value);
// console.log(this.result);
// }
update_final() {
console.log("update_final");
this.result = update_final(this.courseCode, this.section, this.updateColumn, this.updateVal);
console.log(this.result);
},
add_bulk_final() {
console.log("add_bulk_final");
this.result = add_bulk_final(this.file);
console.log(this.result);
}
},
};
</script>
Expand Down
12 changes: 12 additions & 0 deletions src/web/src/services/AdminService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ export const addProfessorsTest = () =>

export const add_final = (msg) =>
client.post("/finals/addFinal/" + msg).then((res) => res.data);

export const add_bulk_final = (file) =>
client.post("/finals/addBulkFinals?file=" + file).then((res) => res.data);

export const remove_bulk_final = (file) =>
client.delete("/finals/removeBulkFinal?file=" + file).then((res) => res.data);

export const remove_final = (courseCode, section) =>
client.delete("/finals/remove?courseCode=" + courseCode + "&section=" + section).then((res) => res.data);

export const update_final = (courseCode, section, column, val) =>
client.put("/finals/update?courseCode=" + courseCode + "&section=" + section + "&column=" + column + "&value=" + val).then((res) => res.data);
5 changes: 4 additions & 1 deletion src/web/src/services/YacsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,7 @@ export const get_info_by_department = (department) =>
client.get("/finals/department/" + department).then((res) => res.data);

export const get_info_by_hour = (hour) =>
client.get("/finals/hour/" + hour).then((res) => res.data);
client.get("/finals/hour/" + hour).then((res) => res.data);

export const get_info_by_room = (room) =>
client.get("/finals/room/" + room).then((res) => res.data);

0 comments on commit 1a17c15

Please sign in to comment.