feat: checkpoint for api hooking up

This commit is contained in:
2024-07-28 13:44:25 -05:00
parent f24d6dc09c
commit 68358de0c8

View File

@@ -22,25 +22,31 @@ async function parseName() {
let department = document.getElementById('courseField').value.trim().toUpperCase(); let department = document.getElementById('courseField').value.trim().toUpperCase();
let departmentList = ''; let departmentList = '';
let semester = document.getElementById('semester').value; let semester = document.getElementById('semester').value;
let instructor = document.getElementById('courseInstructor').value;
await fetch('https://derec4.github.io/ut-grade-data/2022prefixes.json') await fetch('https://derec4.github.io/ut-grade-data/2022prefixes.json')
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
departmentList = data; departmentList = data;
}); });
if (!className && !classNum && !department) { if (!className && !classNum && !department) {
alert("At least fill out the form..."); alert("At least fill out the form...");
return; return;
} }
if (!department || !classNum) { if (!department || !classNum) {
alert("Missing fields") alert("Missing fields")
return; return;
} }
if (!departmentList.includes(department)) { if (!departmentList.includes(department)) {
alert("Invalid Department"); alert("Invalid Department");
return; return;
} }
console.log(department, classNum.toString(), className.trim(), semester);
await PapaParse(department, classNum.toString(), className.trim(), semester); console.log(department, classNum.toString(), className.trim(), instructor.trim(), semester);
await PapaParse(department, classNum.toString(), className.trim(), instructor.trim(), semester);
} }
/** /**
@@ -48,7 +54,7 @@ async function parseName() {
* Then, filter through the table based on the input data to get grade info for the class. * Then, filter through the table based on the input data to get grade info for the class.
* Displays an alert if nothing could be found. * Displays an alert if nothing could be found.
*/ */
async function PapaParse(department, num, name, sem) { async function PapaParse(department, num, name, instructor, sem) {
const semesterURLs = { const semesterURLs = {
'sp2024': 'https://derec4.github.io/ut-grade-data/2024%20Spring.json', 'sp2024': 'https://derec4.github.io/ut-grade-data/2024%20Spring.json',
'f2023': 'https://derec4.github.io/ut-grade-data/2023%20Fall.json', 'f2023': 'https://derec4.github.io/ut-grade-data/2023%20Fall.json',
@@ -71,10 +77,25 @@ async function PapaParse(department, num, name, sem) {
const cData = await response.json(); const cData = await response.json();
let selectedClass = cData.filter(cData => cData["Course Prefix"] == department); let selectedClass = cData.filter(cData => cData["Course Prefix"] == department);
const altUrl = new URL('https://ut-grade-data.vercel.app/v2/query');
const params = {
department: department,
sem: sem,
num: num,
professor: instructor
};
Object.keys(params).forEach(key => {
if (params[key]) {
url.searchParams.append(key, params[key]);
}
});
// temp code below
const url2 = 'https://ut-grade-data.vercel.app/v2/query?department=Computer Science&sem=Fall 2023&num=439&professor=Norman'; const url2 = 'https://ut-grade-data.vercel.app/v2/query?department=Computer Science&sem=Fall 2023&num=439&professor=Norman';
try { try {
const response = await fetch(url2); const response = await fetch(altUrl);
const data = await response.json(); const data = await response.json();
if (data.length === 0) { if (data.length === 0) {
@@ -83,11 +104,10 @@ async function PapaParse(department, num, name, sem) {
} }
console.log(data); console.log(data);
} catch (error) {
console.error("Error fetching data:", error);
alert("An error occurred while fetching data. Please try again.");
} }
catch (error) {
console.error("Error fetching data:", error);
alert("An error occurred while fetching data. Please try again.");
}
if (sem.substring(0, 2) === 's2') { if (sem.substring(0, 2) === 's2') {
/** /**