Skip to content
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

feat: migrate to API rewrite #351

Merged
merged 26 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
99e9495
feat: initial migrate test
ecxyzzy Sep 12, 2023
e95e9bb
feat: stable ground (no more ts errors)
ecxyzzy Sep 14, 2023
0be7ea0
feat: everything works(?)
ecxyzzy Sep 14, 2023
9203d9a
fix: update footer
ecxyzzy Sep 14, 2023
aad7f0e
feat: more cleanup
ecxyzzy Sep 15, 2023
a818227
fix: properly case GitHub
ecxyzzy Sep 15, 2023
932a80b
fix: sort grade dist quarter dropdown, misc fixes
ecxyzzy Sep 20, 2023
fd84899
fix: use async because it is almost 2024
ecxyzzy Sep 20, 2023
9c9fbf1
chore: merge master into api-next-migrate
ecxyzzy Nov 28, 2023
6a6a913
fix: address most comment changes
ecxyzzy Nov 29, 2023
4dc87c3
fix: show class title in prereq tree nodes, correct links
ecxyzzy Nov 30, 2023
f4f15ac
fix: less bad solution for prereq titles
ecxyzzy Nov 30, 2023
e20bb5b
feat: fetch course/instructor data on demand
ecxyzzy Dec 3, 2023
4796fe2
fixed prereq box to only appear when there is text (#367)
kylerpan Oct 20, 2023
0baca8c
fix: grab review form fix from #375
ecxyzzy Dec 4, 2023
406e43d
feat: use graphql for courses again, set endpoint to staging
ecxyzzy Dec 4, 2023
c522297
chore: migrate to latest api staging
ecxyzzy Dec 18, 2023
8c9432b
chore: merge main into api-next-migrate
ecxyzzy Dec 18, 2023
09e763a
fix: make prereq tree node labels consistently spaced
ecxyzzy Dec 18, 2023
8be9403
fix: reincorporate #391 changes
ecxyzzy Dec 19, 2023
65e958d
Merge branch 'master' into api-next-migrate
ecxyzzy Dec 19, 2023
a2243d7
feat: migrate to latest staging, hopefully fix perf issues
ecxyzzy Dec 28, 2023
87189e3
Merge remote-tracking branch 'origin/master' into api-next-migrate
js0mmer Jan 20, 2024
bae581d
Fix review form merging
js0mmer Jan 20, 2024
038d959
Restore original transformation fucntions
js0mmer Jan 21, 2024
b25c63b
Restore API url env vars
js0mmer Jan 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"connect-mongodb-session": "^3.1.1",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dayjs": "^1.11.7",
"dotenv": "^8.2.0",
"dotenv-flow": "^3.2.0",
"ejs": "^3.1.5",
Expand Down
14 changes: 10 additions & 4 deletions api/src/controllers/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ router.get('/api', (req: Request<{}, {}, {}, { courseID: string }>, res) => {
console.log(req.query.courseID)

r.then((response) => response.json())
.then((data) => res.send(data))
.then((data) => res.send(data.payload))
});

/**
Expand All @@ -44,7 +44,11 @@ router.post('/api/batch', (req: Request<{}, {}, { courses: string[] }>, res) =>
});

r.then((response) => response.json())
.then((data) => res.json(data.data))
.then((data) => res.json(
Object.fromEntries(
Object.entries(data.data).filter(([_, x]) => x !== null).map(([_, x]) => [(x as { id: string }).id, x])
)
))
}
});

Expand All @@ -53,10 +57,12 @@ router.post('/api/batch', (req: Request<{}, {}, { courses: string[] }>, res) =>
*/
router.get('/api/grades',
(req: Request<{}, {}, {}, { department: string; number: string; }>, res) => {
let r = fetch(process.env.PUBLIC_API_URL + 'grades/raw?department=' + encodeURIComponent(req.query.department) + '&number=' + req.query.number);
let r = fetch(process.env.PUBLIC_API_URL + 'grades/raw?department=' + encodeURIComponent(req.query.department) + '&courseNumber=' + req.query.number);

r.then((response) => response.json())
.then((data) => res.send(data))
.then((data) => {
res.send(data.payload)
})
});

export default router;
2 changes: 1 addition & 1 deletion api/src/controllers/professors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ router.get('/api/grades/:name', function (req, res, next) {
r.then((response) => {
status = response.status;
return response.json();
}).then((data) => res.status(status).send(data))
}).then((data) => res.status(status).send(data.payload))
});

export default router;
6 changes: 3 additions & 3 deletions api/src/controllers/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ router.delete("/", async (req, res, next) => {
* Upvote or downvote a review
*/
router.patch("/vote", async function (req, res) {
if (req.session.passport != null) {
if (req.session?.passport != null) {
//get id and delta score from initial vote
let id = req.body["id"];
let deltaScore = req.body["upvote"] ? 1 : -1;
Expand Down Expand Up @@ -249,7 +249,7 @@ router.patch("/vote", async function (req, res) {
*/
router.patch("/getVoteColor", async function (req, res) {
//make sure user is logged in
if (req.session.passport != null) {
if (req.session?.passport != null) {
//query of the user's email and the review id
let query = {
userID: req.session.passport.user.email,
Expand All @@ -276,7 +276,7 @@ router.patch("/getVoteColor", async function (req, res) {
* Get multiple review colors
*/
router.patch("/getVoteColors", async function (req, res) {
if (req.session.passport != null) {
if (req.session?.passport != null) {
//query of the user's email and the review id
let ids = req.body["ids"];
let colors = [];
Expand Down
24 changes: 14 additions & 10 deletions api/src/controllers/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/

import express from 'express';
import { getWeek } from '../helpers/week';
import { getCurrentQuarter } from '../helpers/currentQuarter';
import fetch from 'node-fetch';

var router = express.Router();
Expand All @@ -30,24 +28,29 @@ router.get("/getTerms", function (req, res) {
/**
* Get the current week
*/
router.get('/api/currentWeek', function (req, res, next) {
getWeek().then(week => res.send(week))
router.get('/api/currentWeek', async function (_, res) {
const apiResp = await fetch(`${process.env.PUBLIC_API_URL}week`);
const json = await apiResp.json();
res.send(json.payload)
});

/**
* Get the current quarter on websoc
*/
router.get('/api/currentQuarter', function (req, res, next) {
getCurrentQuarter().then(currentQuarter => res.send(currentQuarter))
router.get('/api/currentQuarter', async function (_, res) {
const apiResp = await fetch(`${process.env.PUBLIC_API_URL}websoc/terms`);
const json = await apiResp.json();
res.send(json.payload[0].longName)
});


/**
* Proxy for WebSOC, using PeterPortal API
*/
router.get('/api/:term/:department/:number', async function (req, res) {
const [year, quarter] = req.params.term.split(" ");
const result = await callPPAPIWebSoc({
term: req.params.term,
year, quarter,
department: req.params.department,
courseNumber: req.params.number
});
Expand All @@ -58,17 +61,18 @@ router.get('/api/:term/:department/:number', async function (req, res) {
* Proxy for WebSOC, using PeterPortal API
*/
router.get('/api/:term/:professor', async function (req, res) {
const [year, quarter] = req.params.term.split(" ");
const result = await callPPAPIWebSoc({
term: req.params.term,
year, quarter,
instructorName: req.params.professor
});
res.send(result);
});

async function callPPAPIWebSoc(params: Record<string, string>) {
const url: URL = new URL(process.env.PUBLIC_API_URL + 'schedule/soc?' +
const url: URL = new URL(process.env.PUBLIC_API_URL + 'websoc?' +
new URLSearchParams(params))
return await fetch(url).then(response => response.json());
return await fetch(url).then(response => response.json()).then(json => json.payload);
}

export default router;
4 changes: 2 additions & 2 deletions api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ router.get('/', function (req, res, next) {
*/
router.get('/isAdmin', function (req, res, next) {
// not logged in
if (!req.session.passport) {
if (!req.session?.passport) {
res.json({ admin: false });
}
else {
res.json({ admin: req.session.passport.admin ? true : false });
res.json({ admin: req.session.passport.admin });
}
});

Expand Down
45 changes: 0 additions & 45 deletions api/src/helpers/currentQuarter.ts

This file was deleted.

120 changes: 60 additions & 60 deletions api/src/helpers/gql.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
export function getCourseQuery(courseIDs: string[]) {
// start of query
let result = 'query {';
// request fields for each course
courseIDs.forEach((courseID, i) => {
// use number id here because cannot use special character names
result += `
${'_' + i}: course(id: "${courseID}"){
// start of query
let result = 'query {';

// request fields for each course
courseIDs.forEach((courseID, i) => {
// use number id here because cannot use special character names
result += `
${'_' + i}: course(courseId: "${courseID}") {
id
department
number
courseNumber
school
title
course_level
department_alias
units
courseLevel
minUnits
maxUnits
description
department_name
instructor_history{
name
ucinetid
shortened_name
departmentName
instructors {
ucinetid
name
shortenedName
}
prerequisite_tree
prerequisite_list {
id
department
number
title
prerequisiteTree
prerequisites {
id
department
courseNumber
title
}
prerequisite_text
prerequisite_for {
id
department
number
title
prerequisiteText
dependencies {
id
department
courseNumber
title
}
repeatability
concurrent
same_as
sameAs
restriction
overlap
corequisite
ge_list
ge_text
corequisites
geList
geText
terms
},
`
})
// close off query
result += '}';
return result;
`;
});

// close off query
result += '}';
return result;
}

export function getProfessorQuery(ucinetids: string[]) {
// start of query
let result = 'query {';
// request fields for each course
ucinetids.forEach((ucinetid, i) => {
// use number id here because cannot use special character names
result += `
// start of query
let result = 'query {';

// request fields for each course
ucinetids.forEach((ucinetid, i) => {
// use number id here because cannot use special character names
result += `
${'_' + i}: instructor(ucinetid: "${ucinetid}"){
name
shortened_name
shortenedName
ucinetid
title
department
schools
related_departments
course_history {
id
department
number
title
relatedDepartments
courses {
id
department
courseNumber
title
}
},
`
})
// close off query
result += '}';
return result;
}
`;
});

// close off query
result += '}';
return result;
}
Loading