Skip to content

Commit

Permalink
feat: 전공 선택 조회 API 모든 학과 대상이 조회되도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
DWL21 committed Feb 7, 2025
1 parent de0f33f commit cc81ad3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.yourssu.soongpt.domain.course.implement.Classification
import com.yourssu.soongpt.domain.course.implement.Course
import com.yourssu.soongpt.domain.course.implement.CourseRepository
import com.yourssu.soongpt.domain.course.implement.Courses
import com.yourssu.soongpt.domain.departmentGrade.implement.DepartmentGrade
import com.yourssu.soongpt.domain.departmentGrade.storage.QDepartmentGradeEntity.departmentGradeEntity
import com.yourssu.soongpt.domain.target.storage.QTargetEntity.targetEntity
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -21,10 +22,30 @@ class CourseRepositoryImpl(
.toDomain()
}

override fun findAllByDepartmentId(
departmentId: Long,
classification: Classification
): List<Pair<Course, List<DepartmentGrade>>> {
return jpaQueryFactory.select(courseEntity, departmentGradeEntity)
.from(courseEntity)
.innerJoin(targetEntity)
.on(courseEntity.id.eq(targetEntity.courseId))
.innerJoin(departmentGradeEntity)
.on(targetEntity.departmentGradeId.eq(departmentGradeEntity.id))
.where(
courseEntity.classification.eq(classification),
departmentGradeEntity.departmentId.eq(departmentId)
)
.fetch()
.groupBy { it.get(courseEntity)!! }
.map { (course, departmentGrades) -> course.toDomain() to departmentGrades.map { it.get(departmentGradeEntity)!!.toDomain() } }
}

override fun findAllByDepartmentGradeId(departmentGradeId: Long, classification: Classification): List<Course> {
return jpaQueryFactory.selectFrom(courseEntity)
.innerJoin(targetEntity)
.on(courseEntity.id.eq(targetEntity.courseId), targetEntity.departmentGradeId.eq(departmentGradeId), courseEntity.classification.eq(classification))
.on(courseEntity.id.eq(targetEntity.courseId))
.where(targetEntity.departmentGradeId.eq(departmentGradeId), courseEntity.classification.eq(classification))
.fetch()
.map { it.toDomain() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ class CourseService(

fun findByDepartmentNameInMajorElective(command: FoundDepartmentCommand): List<CourseResponse> {
val department = departmentReader.getByName(command.departmentName)
val departmentGrade = departmentGradeReader.getByDepartmentIdAndGrade(department.id!!, command.grade)
val courses = courseReader.findAllByDepartmentGradeIdInMajorElective(departmentGrade.id!!)
return courses.map {
val courseTimes = courseTimeReader.findAllByCourseId(it.id!!)
CourseResponse.from(course = it, target = listOf(targetReader.formatTargetDisplayName(department, departmentGrade)), courseTimes = courseTimes)
val courses = courseReader.findAllByDepartmentIdInMajorElective(department.id!!)
return courses.map {(course, departmentGrades) ->
val courseTimes = courseTimeReader.findAllByCourseId(course.id!!)
CourseResponse.from(course = course, target = departmentGrades.map { targetReader.formatTargetDisplayName(department, it) } , courseTimes = courseTimes)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yourssu.soongpt.domain.course.implement

import com.yourssu.soongpt.domain.course.implement.exception.CourseNotFoundException
import com.yourssu.soongpt.domain.departmentGrade.implement.DepartmentGrade
import org.springframework.stereotype.Component

@Component
Expand All @@ -11,6 +12,10 @@ class CourseReader(
return courseRepository.findAllByDepartmentGradeId(departmentGradeId, Classification.MAJOR_REQUIRED)
}

fun findAllByDepartmentIdInMajorElective(departmentId: Long): List<Pair<Course, List<DepartmentGrade>>> {
return courseRepository.findAllByDepartmentId(departmentId, Classification.MAJOR_ELECTIVE)
}

fun findAllByDepartmentGradeIdInMajorElective(departmentGradeId: Long): List<Course> {
return courseRepository.findAllByDepartmentGradeId(departmentGradeId, Classification.MAJOR_ELECTIVE)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.yourssu.soongpt.domain.course.implement

import com.yourssu.soongpt.domain.departmentGrade.implement.DepartmentGrade

interface CourseRepository {
fun save(course: Course): Course
fun findAllByDepartmentId(departmentId: Long, classification: Classification): List<Pair<Course, List<DepartmentGrade>>>
fun findAllByDepartmentGradeId(departmentGradeId: Long, classification: Classification): List<Course>
fun getAll(ids: List<Long>): List<Course>
fun findByDepartmentIdAndCourseName(departmentId: Long, courseName: String, classification: Classification): Courses
Expand Down

0 comments on commit cc81ad3

Please sign in to comment.