Skip to content

Commit

Permalink
feat: 교양 필수 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
DWL21 committed Feb 4, 2025
1 parent bf7b065 commit c3db219
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yourssu.soongpt.domain.course.application

import com.yourssu.soongpt.common.business.dto.Response
import com.yourssu.soongpt.domain.course.application.dto.GeneralRequiredCourseRequest
import com.yourssu.soongpt.domain.course.application.dto.MajorElectiveCourseRequest
import com.yourssu.soongpt.domain.course.application.dto.MajorRequiredCourseRequest
import com.yourssu.soongpt.domain.course.business.CourseService
Expand Down Expand Up @@ -28,4 +29,10 @@ class CourseController(
val response = courseService.findByDepartmentNameInMajorElective(request.department)
return ResponseEntity.ok().body(Response(result = response))
}

@GetMapping("/general/required")
fun getGeneralRequiredCourses(@Valid @ModelAttribute request: GeneralRequiredCourseRequest): ResponseEntity<Response<List<CourseResponse>>> {
val response = courseService.findByDepartmentNameInGeneralRequired(request.department)
return ResponseEntity.ok().body(Response(result = response))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.yourssu.soongpt.domain.course.application.dto

import jakarta.validation.constraints.NotBlank
import org.hibernate.validator.constraints.Range

data class GeneralRequiredCourseRequest(
@Range(min = 15, max = 25, message = "학번은 15부터 25까지 가능합니다.")
val schoolId: Long,

@NotBlank
val department: String,

@Range(min = 1, max = 5, message = "학년은 1부터 5까지 가능합니다.")
val grade: Int,
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ class CourseService(
CourseResponse.from(course = it, target = targets, courseTimes = courseTimes)
}
}

fun findByDepartmentNameInGeneralRequired(departmentName: String): List<CourseResponse> {
val department = departmentReader.getByName(departmentName)
val courses = courseReader.findAllByDepartmentIdInGeneralRequired(department.id!!)
return courses.map {
val targets = targetReader.findAllBy(courseId = it.id!!, department = department)
val courseTimes = courseTimeReader.findAllByCourseId(it.id)
CourseResponse.from(course = it, target = targets, courseTimes = courseTimes)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ class CourseReader(
fun findAllByDepartmentIdInMajorElective(departmentId: Long): List<Course> {
return courseRepository.findAllByDepartmentId(departmentId, Classification.MAJOR_ELECTIVE)
}

fun findAllByDepartmentIdInGeneralRequired(departmentId: Long): List<Course> {
return courseRepository.findAllByDepartmentId(departmentId, Classification.GENERAL_REQUIRED)
}
}
6 changes: 6 additions & 0 deletions src/main/resources/http/course.http
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ Content-Type: application/x-www-form-urlencoded
###
GET localhost:8080/api/courses/major/elective?schoolId={{schoolId}}&department={{department}}&grade={{grade}}
Content-Type: application/x-www-form-urlencoded
###

// 교양 핈 과목 조회
###
GET localhost:8080/api/courses/general/required?schoolId={{schoolId}}&department={{department}}&grade={{grade}}
Content-Type: application/x-www-form-urlencoded
###
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ enum class CourseFixture(
classification = Classification.MAJOR_ELECTIVE,
courseCode = 2,
credit = 3,
);
),
GENERAL_REQUIRED(
courseName = "교양필수",
professorName = "교수명",
classification = Classification.GENERAL_REQUIRED,
courseCode = 3,
credit = 3,
)
;

fun toDomain(courseCode: Int = this.courseCode): Course {
return Course(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,36 @@ class CourseServiceTest {
}
}
}

@Nested
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores::class)
inner class findByDepartmentNameInGeneralRequired_메서드는 {
@Nested
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores::class)
inner class 학과를_받으면 {
val departmentName = "소프트웨어학부"
@BeforeEach
fun setUp() {
initializer.run()
val course = courseRepository.save(CourseFixture.GENERAL_REQUIRED.toDomainRandomCourseCode())
val departmentGrade = jpaQueryFactory.selectFrom(departmentGradeEntity)
.innerJoin(departmentEntity)
.on(departmentGradeEntity.departmentId.eq(departmentEntity.id))
.where(departmentEntity.name.eq(departmentName), departmentGradeEntity.grade.eq(4))
.fetchOne()
?.toDomain()
?: throw IllegalArgumentException("소프트웨어학부 4학년이 존재하지 않습니다.")
targetRepository.save(Target(departmentGradeId = departmentGrade.id!!, courseId = course.id!!))
courseTimeRepository.save(CourseTimeFixture.MONDAY_17_19.toDomain(course.id!!))
}

@Test
@DisplayName("해당 학과가 수강대상인 과목 정보를 반환한다.")
fun success() {
val response = courseService.findByDepartmentNameInGeneralRequired(departmentName)

assertEquals(1, response.size)
}
}
}
}

0 comments on commit c3db219

Please sign in to comment.