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

user and friend endpoints #851

Merged
merged 53 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9d89faa
oidc tests
Rayahhhmed May 10, 2024
1407cb1
added nestjs support with auto timetabling
Rayahhhmed May 10, 2024
5c53bc6
added nestjs support with auto timetabling
Rayahhhmed May 10, 2024
ae0e8c7
removing controller test files for main app
Rayahhhmed May 10, 2024
0a926a7
testing out no frozen lockfile for docker image
Rayahhhmed May 10, 2024
f6c15dd
Update ci.yml
Rayahhhmed May 10, 2024
9af7d36
added the old endpoints: Auth user, prisma and user as well as the pr…
Rayahhhmed May 11, 2024
bc0b681
TLS error potentially caused by UNSW IT not renewing cert
Rayahhhmed May 11, 2024
d45b109
updating dockerignore to ignore extra bloat and gitignore to ignore m…
Rayahhhmed May 12, 2024
18a4de6
Updated format for files
Rayahhhmed May 12, 2024
7e18c5c
Prisma migration removed for now
Rayahhhmed May 12, 2024
18f3808
added example env files
Rayahhhmed May 12, 2024
adebb6a
Add PUT user/profile endpoint, and complete PUT user settings endpoint
M7s7 May 13, 2024
b8e1215
Complete POST timetable endpoint
M7s7 May 13, 2024
04f65d2
Edit timetable endpoint completed (not tested though lol - will do la…
M7s7 May 13, 2024
a5bf4d1
GET profile endpoint fixed and completed
M7s7 May 14, 2024
82b890b
Complete GET settings endpoint
M7s7 May 14, 2024
95c0fb8
GET timetable is working now
M7s7 May 14, 2024
68ace61
Delete timetable endpoint completed
M7s7 May 14, 2024
28ede1b
added better mapping for sql name convention
Rayahhhmed May 19, 2024
5ed1842
Add friend/unfriend endpoints
M7s7 May 20, 2024
d8ac30e
Add friends get req
M7s7 May 20, 2024
f392753
Friend request endpoints completed
M7s7 May 22, 2024
48c1a93
added groups endpoints
Rayahhhmed May 25, 2024
31b6bcb
added all the endpoints
Rayahhhmed May 25, 2024
ad72ad0
group post merged
Rayahhhmed May 26, 2024
1d239c9
added seed script
Rayahhhmed May 26, 2024
c22f262
added seed script
Rayahhhmed May 26, 2024
6cb13d7
adding some minor changes with source copying
Rayahhhmed May 26, 2024
0f3b5e7
seed file was causing crashes
Rayahhhmed May 26, 2024
6d92dc0
testing out types
Rayahhhmed May 26, 2024
5d1cf20
adding ci prisma gen
Rayahhhmed May 26, 2024
14207dd
User profile endpoint
M7s7 May 27, 2024
2160a56
Completed edit timetable endpoint, simplified create timetable endpoint:
M7s7 May 27, 2024
7dbe43e
Added fixed user endpoints andn modified schema from old branch
M7s7 May 28, 2024
64b8c48
Slowly piecing together framework for mocking prisma client and testi…
M7s7 Jun 4, 2024
f9ecedb
test: Removed unit tests as they are quite useless for db testing; re…
M7s7 Jun 6, 2024
86dd636
minor changes to schema/dtos, and finished user tests
M7s7 Jun 7, 2024
662c70a
test: add friends tests
M7s7 Jun 7, 2024
074a879
test refactored
M7s7 Jun 11, 2024
0c92086
refactor: remove all class data and fields, and add classNo property
M7s7 Jun 16, 2024
32a7fa3
Change schema and interfaces to give enough data to reconstruct. Also…
M7s7 Jun 16, 2024
b06beb5
Inital implementation of scraper data makes my eyes want to explode
M7s7 Jun 16, 2024
d2d6e60
fix: get user endpoint properly fetches timetables, and get timetable…
M7s7 Jun 17, 2024
4a2016a
test: update tests to work with returned scraped class data
M7s7 Jun 21, 2024
1f7ad6e
chore: I remember you was conflicted (not anymore)
M7s7 Aug 17, 2024
a872e83
style: added linting for server + linted client and server
Shzmj Aug 29, 2024
e3e4f83
chore: remove comments
M7s7 Aug 30, 2024
bc2dadd
Merge branch 'testing-endpoints' of github.com:devsoc-unsw/notangles …
M7s7 Aug 30, 2024
48d3921
chore: add class time DTO; clean up codebase
M7s7 Aug 30, 2024
c32edb7
refactor: add reconstructed timetable creation method
M7s7 Aug 30, 2024
ef6cc65
schema: change terms to string, remove term enum
M7s7 Aug 30, 2024
38b0579
style: remove unused comments
M7s7 Aug 30, 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
Prev Previous commit
Next Next commit
Change schema and interfaces to give enough data to reconstruct. Also…
… added helper func to call scraper public endpoint
  • Loading branch information
M7s7 committed Jun 16, 2024
commit 32a7fa3bcf6d1e65755d846df28ad73b7725bc4a
11 changes: 10 additions & 1 deletion server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ model Event {

model Class {
id String @unique
// classType ClassType
classNo String // From scraper (not unique in db, but between classes)
term Term
year String
courseCode String
Timetable Timetable? @relation(fields: [timetableId], references: [id], onDelete: Cascade)
timetableId String?
@@map("classes")
Expand Down Expand Up @@ -109,6 +111,13 @@ enum GroupVisibility {
@@map("group_visibility")
}

enum Term {
U1
T1
T2
T3
}

// enum ClassType {
// LECTURE
// TUTORIAL
Expand Down
15 changes: 15 additions & 0 deletions server/src/user/dto/timetable.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ export class TimetableDto {
name?: string;
}

export class ReconstructedTimetableDto {
@IsString()
timetableId: string; // Randomly generated on the backend

@IsArray()
@IsString({ each: true })
selectedCourses: string[];
selectedClasses: ReconstructedClassDto[];
createdEvents: EventDto[];
name?: string;
}

export class ClassDto {
id: string;
classNo: string; // From scraper
year: string;
term: 'T1' | 'T2' | 'T3' | 'U1';
courseCode: string;
timetableId?: string;
}

Expand Down
40 changes: 34 additions & 6 deletions server/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,43 @@ import {
TimetableDto,
ClassDto,
InitUserDTO,
ReconstructedTimetableDto,
} from './dto';
import { PrismaService } from 'src/prisma/prisma.service';
import { v4 as uuidv4 } from 'uuid';
import { Timetable, User } from '@prisma/client';

const API_URL = 'https://timetable.csesoc.app/api/terms';
@Injectable()
export class UserService {
constructor(private readonly prisma: PrismaService) {}

private async convertClasses(classes: ClassDto[]) {
try {
// For each class in class DTO, we need to fetch information
const cache = {};

for (const clz of classes) {
const k = `${clz.year}-${clz.term}/courses/${clz.courseCode}`;
if (!(k in cache)) {
const data = await fetch(`${API_URL}/${k}`);
const json = await data.json();

cache[k] = json.classes;
}
}

return classes.map((clz) => {
const k = `${clz.year}-${clz.term}/courses/${clz.courseCode}`;
const data = cache[k].find((c) => c.classID === clz.classNo);
// TODO: MORE CONVERSION HERE
return data;
});
} catch (e) {
throw new Error('uhh');
}
}

async getUserInfo(_userID: string): Promise<UserDTO> {
const { userID, timetables, ...userData } =
await this.prisma.user.findUniqueOrThrow({
Expand Down Expand Up @@ -96,7 +125,8 @@ export class UserService {
}
}

async getUserTimetables(_userID: string): Promise<TimetableDto[]> {
async getUserTimetables(_userID: string): Promise<any[]> {
// ): Promise<ReconstructedTimetableDto[]> {
try {
const res = await this.prisma.timetable.findMany({
where: { userID: _userID },
Expand Down Expand Up @@ -136,11 +166,8 @@ export class UserService {
const classes = _selectedClasses.map((c) => {
// const classId = uuidv4(); // on second thought, its already been generated on the frontend, and I think there are advantages to this
return {
...c,
// timetableId: _timetableId,
id: c.id,
// section: c.section,
// courseCode: c.courseCode,
// classType: c.classType,
};
});

Expand Down Expand Up @@ -236,7 +263,8 @@ export class UserService {
}
}

async getTimetablesByIDs(timetableIDs: string[]): Promise<Timetable[]> {
async getTimetablesByIDs(timetableIDs: string[]): Promise<any[]> {
// ): Promise<ReconstructedTimetableDto[]> {
try {
const timetables = await this.prisma.timetable.findMany({
where: {
Expand Down
7 changes: 5 additions & 2 deletions server/test/db.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,13 @@ describe('Integration testing for user/friend db endpoints', () => {
selectedCourses: ['COMP2511', 'COMP2521'],
selectedClasses: [
timetable.selectedClasses[1],
{ ...timetable.selectedClasses[2], section: 'A321' },
{ ...timetable.selectedClasses[2], term: 'T1', classNo: '8839' },
{
id: 'c4',
classNo: '11127',
classNo: '8930',
year: '2024',
term: 'T2',
courseCode: 'COMP2521',
},
],
createdEvents: [
Expand Down
25 changes: 20 additions & 5 deletions server/test/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ const mockData = {
selectedClasses: [
{
id: 'c1',
classNo: '11069',
classNo: '8713',
year: '2024',
term: 'T1',
courseCode: 'COMP1511',
},
{
id: 'c2',
classNo: '8332',
classNo: '8714',
year: '2024',
term: 'T1',
courseCode: 'COMP1511',
},
],
createdEvents: [
Expand Down Expand Up @@ -82,15 +88,24 @@ const mockData = {
selectedClasses: [
{
id: 'c1',
classNo: '11069',
classNo: '8713',
year: '2024',
term: 'T1',
courseCode: 'COMP1511',
},
{
id: 'c2',
classNo: '8332',
classNo: '8714',
year: '2024',
term: 'T1',
courseCode: 'COMP1511',
},
{
id: 'c3',
classNo: '8364',
classNo: '8890',
year: '2024',
term: 'T2',
courseCode: 'COMP2511',
},
],
createdEvents: [
Expand Down