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

View courses #31

Merged
merged 4 commits into from
Feb 27, 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
9 changes: 9 additions & 0 deletions apps/backend/src/courses/course.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Controller, Get, Post, Query } from "@nestjs/common";
import { CoursesService } from "./course.service";

@Controller()
export class CoursesController {
constructor(readonly courseService: CoursesService) {}
// Responsibility: handle API requests

}
7 changes: 7 additions & 0 deletions apps/backend/src/courses/course.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class CourseDTO{
cid: number;
courseName: string;
department: string;
courseNumber: number;
description: string;
}
12 changes: 12 additions & 0 deletions apps/backend/src/courses/course.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { CoursesController } from './course.controller';
import { CoursesService } from './course.service';
import { TypeOrmModule } from "@nestjs/typeorm";
import { Course } from '../entities/course.entity';

@Module({
imports: [TypeOrmModule.forFeature([Course])],
controllers: [CoursesController],
providers: [CoursesService],
})
export class CoursesModule {}
25 changes: 25 additions & 0 deletions apps/backend/src/courses/course.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Course } from '../entities/course.entity';
import { CourseDTO } from './course.dto';

@Injectable()
export class CoursesService {
constructor(
@InjectRepository(Course)
private courseRepository: Repository<Course>,
) {}

// Responsibility: handle business logic - make DB requests
async getCourses(department: string): Promise<CourseDTO[]> {
//Make DB Request
const courses = await this.courseRepository.find({
where: {
department,
},
});

return courses;
}
}
14 changes: 14 additions & 0 deletions apps/backend/src/degrees/degree.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Controller, Get, Post, Query } from "@nestjs/common";
import { DegreeService } from "./degree.service";
import { DegreeDTO } from "./degree.dto";

@Controller()
export class DegreeController {
constructor(readonly degreeService: DegreeService) {}
// Responsibility: handle API requests

@Get()
async findAll(): Promise<DegreeDTO[]>{
return this.degreeService.findAll();
}
}
4 changes: 4 additions & 0 deletions apps/backend/src/degrees/degree.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class DegreeDTO{
did: number;
name: string;
}
12 changes: 12 additions & 0 deletions apps/backend/src/degrees/degree.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { DegreeController } from './degree.controller';
import { DegreeService } from './degree.service';
import { TypeOrmModule } from "@nestjs/typeorm";
import { Degree } from '../entities/degree.entity';

@Module({
imports: [TypeOrmModule.forFeature([Degree])],
controllers: [DegreeController],
providers: [DegreeService],
})
export class DegreeModule {}
17 changes: 17 additions & 0 deletions apps/backend/src/degrees/degree.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Degree } from '../entities/degree.entity';
import { DegreeDTO } from './degree.dto';

@Injectable()
export class DegreeService {
constructor(
@InjectRepository(Degree)
private readonly degreeRepository: Repository<Degree>,
) {}

async findAll(): Promise<DegreeDTO[]>{
return this.degreeRepository.find();
}
}
9 changes: 0 additions & 9 deletions apps/backend/src/entities/section.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,9 @@ export class Section {
@Column()
sectionName: string;

@Column()
locationID: number;

@Column()
tid: number;

@Column()
time: string;

@Column()
cid: number;

@Column()
professor: string;

Expand Down
16 changes: 8 additions & 8 deletions apps/backend/src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ export class User {
@Column({ default: '' })
pictureProfile: string;

// @ManyToOne(() => Degree, (degree) => degree.users)
// degree: Degree;
@ManyToOne(() => Degree, (degree) => degree.users)
degree: Degree;

// @ManyToMany(() => Course)
// @JoinTable()
// courses: Relation<Course[]>;
@ManyToMany(() => Course)
@JoinTable()
courses: Relation<Course[]>;

// @ManyToMany(() => Section)
// @JoinTable()
// sections: Relation<Section[]>;
@ManyToMany(() => Section)
@JoinTable()
sections: Relation<Section[]>;

// constructor(user: Partial<User>) {
// Object.assign(this, user);
Expand Down
26 changes: 19 additions & 7 deletions apps/backend/src/routes.module.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Module } from '@nestjs/common';
//import { HelloModule } from './hello/hello.module';
import { RouterModule } from '@nestjs/core';
import { AuthModule } from '../src/auth/auth.module';
import { TermModule } from './terms/term.module';
import { DegreeModule } from './degrees/degree.module';
import { UserModule } from './users/user.module';
import { AuthModule } from './auth/auth.module';
import { ProfileModule } from './profile/profile.module';

@Module({
imports: [
//HelloModule,
TermModule,
DegreeModule,
UserModule,
AuthModule,
RouterModule.register([
{
path: '/rest-api',
children: [
// {
// path: '/hello',
// module: HelloModule,
// },
{
path: '/auth',
module: AuthModule,
Expand All @@ -24,6 +24,18 @@ import { ProfileModule } from './profile/profile.module';
path: '/profile',
module: ProfileModule,
},
{
path: '/term',
module: TermModule,
},
{
path: '/degree',
module: DegreeModule,
},
{
path: '/user',
module: UserModule,
},
],
},
]),
Expand Down
10 changes: 10 additions & 0 deletions apps/backend/src/sections/section.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller, Get, Post, Query } from "@nestjs/common";
import { SectionService } from "./section.service";
import { SectionDTO } from "./section.dto";

@Controller()
export class SectionController {
constructor(readonly sectionService: SectionService) {}


}
6 changes: 6 additions & 0 deletions apps/backend/src/sections/section.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class SectionDTO{
sid: number;
sectionName: string;
time: string;
professor: string;
}
12 changes: 12 additions & 0 deletions apps/backend/src/sections/section.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { SectionController } from './section.controller';
import { SectionService } from "./section.service";
import { Section } from '../entities/section.entity';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
imports: [TypeOrmModule.forFeature([Section])],
controllers: [SectionController],
providers: [SectionService],
})
export class SectionModule {}
14 changes: 14 additions & 0 deletions apps/backend/src/sections/section.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable, Query } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Section } from '../entities/section.entity';
import { SectionDTO } from './section.dto';

@Injectable()
export class SectionService {
constructor(
@InjectRepository(Section)
private SectionRepository: Repository<Section>,
) {}

}
27 changes: 27 additions & 0 deletions apps/backend/src/terms/term.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Controller, Get, Post, Query } from "@nestjs/common";
import { TermService } from "./term.service";
import { CourseDTO } from "../courses/course.dto";
import { TermDTO } from "./term.dto";

@Controller()
export class TermController {
constructor(readonly termService: TermService) {}

// Responsibility: handle API requests
@Get()
async findAll():Promise<TermDTO[]>{
return this.termService.findAll();
}
@Get('searchCurrent')
async findCurrent(): Promise<number>{
return this.termService.findCurrentTerm();
}

@Get('search')
async find(
@Query('tid') tid: number,
@Query('department') department: string
): Promise<CourseDTO[]>{
return this.termService.find(tid,department);
}
}
5 changes: 5 additions & 0 deletions apps/backend/src/terms/term.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class TermDTO{
tid: number;
year: number;
season: string;
}
14 changes: 14 additions & 0 deletions apps/backend/src/terms/term.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { TermController } from './term.controller';
import { TermService } from './term.service';
import { TypeOrmModule } from "@nestjs/typeorm";
import { Term } from '../entities/term.entity';
import { getRepositoryToken } from '@nestjs/typeorm';

@Module({
imports: [TypeOrmModule.forFeature([Term])],
controllers: [TermController],
providers: [TermService],

})
export class TermModule {}
38 changes: 38 additions & 0 deletions apps/backend/src/terms/term.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Injectable, Query } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Term } from '../entities/term.entity';
import { CourseDTO } from '../courses/course.dto';
import { TermDTO } from "./term.dto";

@Injectable()
export class TermService {
constructor(
@InjectRepository(Term)
private readonly termRepository: Repository<Term>,
) {}

// Responsibility: handle business logic - make DB requests
async findAll(): Promise<TermDTO[]>{
return await this.termRepository.find();
}

async findCurrentTerm():Promise<number>{
const terms = await this.findAll();
const maxTid = Math.max(...terms.map(term => term.tid));
return maxTid;
}

async find(tid: any, department: string): Promise<CourseDTO[]>{
const termCourse = await this.termRepository.findOne({
relations:{
courses:true
},
where: {
tid: tid
}
});

return termCourse.courses.filter(CourseDTO => CourseDTO.department === department);
}
}
38 changes: 38 additions & 0 deletions apps/backend/src/users/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Controller, Get, Post, Query } from "@nestjs/common";
import { UserService } from "./user.service";
import { UserDTO } from "./user.dto";
import { SectionDTO } from "../sections/section.dto";

@Controller()
export class UserController {
constructor(readonly userService: UserService) {}

// Responsibility: handle API requests
@Get()
async findAll():Promise<UserDTO[]>{
return this.userService.findAll();
}

@Get('search')
async findOne(
@Query('uid') tid: number,
): Promise<UserDTO>{
return this.userService.find(tid);
}

@Get('searchSection')
async findSection(
@Query('uid') uid: number,
@Query('tid') tid:number,
): Promise<SectionDTO[]>{
return this.userService.findSection(uid, tid);
}

@Get('searchActive')
async findActive(
@Query('uid') uid: number,
@Query('tid') tid:number,
): Promise<SectionDTO[]>{
return this.userService.findActive(uid, tid);
}
}
6 changes: 6 additions & 0 deletions apps/backend/src/users/user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class UserDTO{
uid: number;
fullName: string;
username: string;
pictureProfile: string;
}
Loading