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: wrapped routes & plausible script #312

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ jobs:
- run: npm ci
- run: npm run lint
- run: npm run build
migration-ci:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./migration
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run lint
- run: npm run build
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"main": "index.js",
"scripts": {
"lint": "eslint -c .eslintrc.js \"src/**/*.{js,ts,tsx}\" --quiet --fix",
"format": "prettier '**/*.ts' --write",
"build": "tsc",
"start": "npx prisma migrate deploy && node dist/src/index.js",
"dev": "NODE_ENV=dev tsx src/index.ts",
Expand Down
87 changes: 84 additions & 3 deletions backend/src/controllers/course.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ export class CourseController implements IController {
if (offsetStr !== undefined) {
offset = parseInt(offsetStr);
}
const result = await this.courseService.getCoursesFromOffset(
offset,
);
const result =
await this.courseService.getCoursesFromOffset(offset);
this.logger.info(`Responding to client in GET /courses`);
return res.status(200).json(result);
} catch (err: any) {
Expand All @@ -58,6 +57,64 @@ export class CourseController implements IController {
}
},
)
.get(
"/wrapped/course/highest-rated/:term",
async (
req: Request<{ term: string }, unknown>,
res: Response,
next: NextFunction,
) => {
this.logger.debug(
`Received request in GET /course/highest-rated/:term`,
);
try {
const term: string = req.params.term;
const result =
await this.courseService.getHighestRatedCourseInTerm(term);
this.logger.info(
`Responding to client in GET /wrapped/course/highest-rated/${term}`,
);
return res.status(200).json(result);
} catch (err: any) {
this.logger.warn(
`An error occurred when trying to GET /wrapped/course/highest-rated ${formatError(
err,
)}`,
);
return next(err);
}
},
)
.get(
"/wrapped/course/highest-attribute/:attribute",
async (
req: Request<{ attribute: string }, unknown>,
res: Response,
next: NextFunction,
) => {
this.logger.debug(
`Received request in GET /wrapped/course/highest-attribute/:attribute`,
);
try {
const attribute: string = req.params.attribute;
const result =
await this.courseService.getCourseWithHighestRatedAttribute(
attribute,
);
this.logger.info(
`Responding to client in GET /wrapped/course/highest-attribute/${attribute}`,
);
return res.status(200).json(result);
} catch (err: any) {
this.logger.warn(
`An error occurred when trying to GET /wrapped/course/highest-attribute ${formatError(
err,
)}`,
);
return next(err);
}
},
)
.get(
"/course/:courseCode",
async (
Expand Down Expand Up @@ -107,6 +164,30 @@ export class CourseController implements IController {
}
},
)
.get(
"/course/filter/:terms/:faculties/:searchTerm",
async (req: Request, res: Response, next: NextFunction) => {
this.logger.debug(`Received request in GET /course/filter`);
try {
const { terms, faculties, searchTerm } = req.params;

const result = await this.courseService.filterCourse(
terms,
faculties,
searchTerm,
);

return res.status(200).json(result);
} catch (err: any) {
this.logger.warn(
`An error occurred when trying to GET /course/filter ${formatError(
err,
)}`,
);
return next(err);
}
},
)
.delete(
"/cached/flush",
async (
Expand Down
31 changes: 25 additions & 6 deletions backend/src/controllers/review.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ export class ReviewController implements IController {
}
},
)
.get(
"/wrapped/reviews/most-liked",
async (req: Request, res: Response, next: NextFunction) => {
this.logger.debug(`Received request in /wrapped/reviews/most-liked`);
try {
const result = await this.reviewService.getMostLiked();
this.logger.info(
`Responding to client in GET /wrapped/reviews/most-liked`,
);
return res.status(200).json(result);
} catch (err: any) {
this.logger.warn(
`An error occurred when trying to GET /wrapped/reviews/most-liked ${formatError(
err,
)}`,
);
return next(err);
}
},
)
.get(
"/reviews/:courseCode",
async (
Expand All @@ -55,9 +75,8 @@ export class ReviewController implements IController {
this.logger.debug(`Received request in /reviews/:courseCode`);
try {
const courseCode: string = req.params.courseCode;
const result = await this.reviewService.getCourseReviews(
courseCode,
);
const result =
await this.reviewService.getCourseReviews(courseCode);
this.logger.info(
`Responding to client in GET /reviews/${courseCode}`,
);
Expand All @@ -72,6 +91,7 @@ export class ReviewController implements IController {
}
},
)

.post(
"/reviews",
[verifyToken, validationMiddleware(PostReviewSchema, "body")],
Expand Down Expand Up @@ -167,9 +187,8 @@ export class ReviewController implements IController {
try {
const reviewDetails = req.body;
if (!reviewDetails) throw new HTTPError(badRequest);
const result = await this.reviewService.bookmarkReview(
reviewDetails,
);
const result =
await this.reviewService.bookmarkReview(reviewDetails);
this.logger.info(`Responding to client in POST /reviews/bookmark`);
return res.status(200).json(result);
} catch (err: any) {
Expand Down
Loading
Loading