Skip to content

Commit 563c958

Browse files
authored
Merge pull request #121 from DevKor-github/refactor/search-course
Refactor/search course
2 parents e8b1b0b + 605b6db commit 563c958

12 files changed

+274
-765
lines changed

src/course/course.controller.ts

Lines changed: 6 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
1+
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
22
import { CourseService } from './course.service';
33
import { ApiTags } from '@nestjs/swagger';
4-
import { CommonCourseResponseDto } from './dto/common-course-response.dto';
54
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
6-
import { SearchCourseCodeDto } from './dto/search-course-code.dto';
7-
import { SearchCourseNameDto } from './dto/search-course-name.dto';
8-
import { SearchProfessorNameDto } from './dto/search-professor-name.dto';
95
import { PaginatedCoursesDto } from './dto/paginated-courses.dto';
106
import { CourseDocs } from 'src/decorators/docs/course.decorator';
11-
import { GetGeneralCourseDto } from './dto/get-general-course.dto';
12-
import { GetMajorCourseDto } from './dto/get-major-course.dto';
13-
import { GetAcademicFoundationCourseDto } from './dto/get-academic-foundation-course.dto';
14-
import { SearchCoursesWithKeywordDto } from './dto/search-courses-with-keyword.dto';
7+
import { SearchCourseNewDto } from './dto/search-course-new.dto';
158

169
@ApiTags('course')
1710
@CourseDocs
@@ -20,139 +13,10 @@ export class CourseController {
2013
constructor(private courseService: CourseService) {}
2114

2215
@UseGuards(JwtAuthGuard)
23-
@Get('search-all')
24-
async searchAllCourses(
25-
@Query() searchCoursesWithKeywordDto: SearchCoursesWithKeywordDto,
16+
@Get()
17+
async searchCourses(
18+
@Query() searchCourseNewDto: SearchCourseNewDto,
2619
): Promise<PaginatedCoursesDto> {
27-
return await this.courseService.searchAllCourses(
28-
searchCoursesWithKeywordDto,
29-
);
30-
}
31-
32-
@UseGuards(JwtAuthGuard)
33-
@Get('search-major')
34-
async searchMajorCourses(
35-
@Query('major') major: string,
36-
@Query() searchCoursesWithKeywordDto: SearchCoursesWithKeywordDto,
37-
): Promise<PaginatedCoursesDto> {
38-
return await this.courseService.searchMajorCourses(
39-
major,
40-
searchCoursesWithKeywordDto,
41-
);
42-
}
43-
44-
@UseGuards(JwtAuthGuard)
45-
@Get('search-general')
46-
async searchGeneralCourses(
47-
@Query() searchCoursesWithKeywordDto: SearchCoursesWithKeywordDto,
48-
): Promise<PaginatedCoursesDto> {
49-
return await this.courseService.searchGeneralCourses(
50-
searchCoursesWithKeywordDto,
51-
);
52-
}
53-
54-
@UseGuards(JwtAuthGuard)
55-
@Get('search-academic-foundation')
56-
async searchAcademicFoundationCourses(
57-
@Query('college') college: string,
58-
@Query() searchCoursesWithKeywordDto: SearchCoursesWithKeywordDto,
59-
): Promise<PaginatedCoursesDto> {
60-
return await this.courseService.searchAcademicFoundationCourses(
61-
college,
62-
searchCoursesWithKeywordDto,
63-
);
64-
}
65-
66-
// 학수번호 검색
67-
@UseGuards(JwtAuthGuard)
68-
@Get('search-course-code')
69-
async searchCourseCode(
70-
@Query() searchCourseCodeDto: SearchCourseCodeDto,
71-
): Promise<PaginatedCoursesDto> {
72-
return await this.courseService.searchCourseCode(searchCourseCodeDto);
73-
}
74-
75-
// 전공 -- 과목명 검색
76-
@UseGuards(JwtAuthGuard)
77-
@Get('search-major-course-name')
78-
async searchMajorCourseName(
79-
@Query('major') major: string,
80-
@Query() searchCourseNameDto: SearchCourseNameDto,
81-
): Promise<PaginatedCoursesDto> {
82-
return await this.courseService.searchMajorCourseName(
83-
major,
84-
searchCourseNameDto,
85-
);
86-
}
87-
88-
// 교양 - 과목명 검색
89-
@UseGuards(JwtAuthGuard)
90-
@Get('search-general-course-name')
91-
async searchGeneralCourseName(
92-
@Query() searchCourseNameDto: SearchCourseNameDto,
93-
): Promise<PaginatedCoursesDto> {
94-
return await this.courseService.searchGeneralCourseName(
95-
searchCourseNameDto,
96-
);
97-
}
98-
99-
// 전공 - 교수님 성함 검색
100-
@UseGuards(JwtAuthGuard)
101-
@Get('search-major-professor-name')
102-
async searchMajorProfessorName(
103-
@Query('major') major: string,
104-
@Query() searchProfessorNameDto: SearchProfessorNameDto,
105-
): Promise<PaginatedCoursesDto> {
106-
return await this.courseService.searchMajorProfessorName(
107-
major,
108-
searchProfessorNameDto,
109-
);
110-
}
111-
112-
// 교양 - 교수님 성함 검색
113-
@UseGuards(JwtAuthGuard)
114-
@Get('search-general-professor-name')
115-
async searchGeneralProfessorName(
116-
@Query() searchProfessorNameDto: SearchProfessorNameDto,
117-
): Promise<PaginatedCoursesDto> {
118-
return await this.courseService.searchGeneralProfessorName(
119-
searchProfessorNameDto,
120-
);
121-
}
122-
123-
// 교양 리스트
124-
@UseGuards(JwtAuthGuard)
125-
@Get('general')
126-
async getGeneralCourses(
127-
@Query() getGeneralCourseDto: GetGeneralCourseDto,
128-
): Promise<PaginatedCoursesDto> {
129-
return await this.courseService.getGeneralCourses(getGeneralCourseDto);
130-
}
131-
132-
// 전공 리스트 (학부별)
133-
@UseGuards(JwtAuthGuard)
134-
@Get('major')
135-
async getMajorCourses(
136-
@Query() getMajorCourseDto: GetMajorCourseDto,
137-
): Promise<PaginatedCoursesDto> {
138-
return await this.courseService.getMajorCourses(getMajorCourseDto);
139-
}
140-
141-
// 학문의 기초 리스트
142-
@UseGuards(JwtAuthGuard)
143-
@Get('academic-foundation')
144-
async getAcademicFoundationCourses(
145-
@Query() getAcademicFoundationCourseDto: GetAcademicFoundationCourseDto,
146-
): Promise<PaginatedCoursesDto> {
147-
return await this.courseService.getAcademicFoundationCourses(
148-
getAcademicFoundationCourseDto,
149-
);
150-
}
151-
152-
@Get('/:courseId')
153-
async getCourse(
154-
@Param('courseId') courseId: number,
155-
): Promise<CommonCourseResponseDto> {
156-
return await this.courseService.getCourse(courseId);
20+
return await this.courseService.searchCourses(searchCourseNewDto);
15721
}
15822
}

src/course/course.module.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,43 @@ import { CourseDetailRepository } from './course-detail.repository';
66
import { TypeOrmModule } from '@nestjs/typeorm';
77
import { CourseEntity } from 'src/entities/course.entity';
88
import { CourseDetailEntity } from 'src/entities/course-detail.entity';
9+
import { AcademicFoundationSearchStrategy } from './strategy/academic-foundation-search-strategy';
10+
import { GeneralSearchStrategy } from './strategy/general-search-strategy';
11+
import { MajorSearchStrategy } from './strategy/major-search-strategy';
12+
import { AllCoursesSearchStrategy } from './strategy/all-courses-search-strategy';
913

1014
@Module({
1115
imports: [TypeOrmModule.forFeature([CourseEntity, CourseDetailEntity])],
1216
controllers: [CourseController],
13-
providers: [CourseService, CourseRepository, CourseDetailRepository],
17+
providers: [
18+
CourseService,
19+
CourseRepository,
20+
CourseDetailRepository,
21+
AcademicFoundationSearchStrategy,
22+
GeneralSearchStrategy,
23+
MajorSearchStrategy,
24+
AllCoursesSearchStrategy,
25+
{
26+
provide: 'CourseSearchStrategy',
27+
useFactory: (
28+
academicFoundationSearchStrategy: AcademicFoundationSearchStrategy,
29+
generalSearchStrategy: GeneralSearchStrategy,
30+
majorSearchStrategy: MajorSearchStrategy,
31+
allCoursesSearchStrategy: AllCoursesSearchStrategy,
32+
) => [
33+
academicFoundationSearchStrategy,
34+
generalSearchStrategy,
35+
majorSearchStrategy,
36+
allCoursesSearchStrategy,
37+
],
38+
inject: [
39+
AcademicFoundationSearchStrategy,
40+
GeneralSearchStrategy,
41+
MajorSearchStrategy,
42+
AllCoursesSearchStrategy,
43+
],
44+
},
45+
],
1446
exports: [CourseService],
1547
})
1648
export class CourseModule {}

0 commit comments

Comments
 (0)