Skip to content

Commit

Permalink
merge: (#786) 수락된 신청자 수 표시 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
zios0707 authored Oct 15, 2024
2 parents 67e65a7 + 5505d67 commit 7de8ed1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ class GetVolunteerServiceImpl(
?: throw VolunteerNotFoundException

override fun getAllVolunteersWithCurrentApplicantsByStudent(student: Student): List<VolunteerWithCurrentApplicantVO> {
val volunteers = queryVolunteerPort.queryAllVolunteersWithCurrentApplicantsBySchoolId(student.schoolId)
val volunteers = queryVolunteerPort.queryAllVolunteersWithCurrentApplicantsBySchoolIdAndStudentId(
schoolId = student.schoolId,
studentId = student.id
)

return volunteers.filter { volunteer ->
volunteer.toVolunteer().isAvailable(student)
}
}

override fun getAllVolunteersWithCurrentApplicantsBySchoolId(schoolId: UUID): List<VolunteerWithCurrentApplicantVO> =
queryVolunteerPort.queryAllVolunteersWithCurrentApplicantsBySchoolId(schoolId)
queryVolunteerPort.queryAllVolunteersWithCurrentApplicantsBySchoolIdAndStudentId(
schoolId = schoolId,
studentId = null
)

override fun getAllApplicantsByVolunteerId(volunteerId: UUID): List<VolunteerApplicantVO> =
queryVolunteerApplicationPort.queryAllApplicantsByVolunteerId(volunteerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface QueryVolunteerPort {

fun queryAllVolunteersBySchoolId(schoolId: UUID): List<Volunteer>

fun queryAllVolunteersWithCurrentApplicantsBySchoolId(schoolId: UUID): List<VolunteerWithCurrentApplicantVO>
fun queryAllVolunteersWithCurrentApplicantsBySchoolIdAndStudentId(schoolId: UUID, studentId: UUID?): List<VolunteerWithCurrentApplicantVO>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package team.aliens.dms.persistence.volunteer

import com.querydsl.core.group.GroupBy.groupBy
import com.querydsl.core.group.GroupBy.list
import com.querydsl.core.group.GroupBy.set
import com.querydsl.core.types.dsl.Expressions
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Component
Expand Down Expand Up @@ -44,7 +45,7 @@ class VolunteerPersistenceAdapter(
.map { volunteerMapper.toDomain(it)!! }
}

override fun queryAllVolunteersWithCurrentApplicantsBySchoolId(schoolId: UUID): List<VolunteerWithCurrentApplicantVO> {
override fun queryAllVolunteersWithCurrentApplicantsBySchoolIdAndStudentId(schoolId: UUID, studentId: UUID?): List<VolunteerWithCurrentApplicantVO> {
val myApplication = QVolunteerApplicationJpaEntity("myApplication")

return queryFactory.selectFrom(volunteerJpaEntity)
Expand All @@ -54,7 +55,12 @@ class VolunteerPersistenceAdapter(
volunteerApplicationJpaEntity.approved.isTrue
)
.leftJoin(myApplication)
.on(myApplication.volunteer.id.eq(volunteerJpaEntity.id))
.on(
myApplication.volunteer.id.eq(volunteerJpaEntity.id),
studentId?.let { myApplication.student.id.eq(it) }
?: Expressions.asBoolean(true).isTrue
)
.where(volunteerJpaEntity.school.id.eq(schoolId))
.transform(
groupBy(volunteerJpaEntity.id)
.list(
Expand All @@ -63,7 +69,7 @@ class VolunteerPersistenceAdapter(
volunteerJpaEntity.name,
volunteerJpaEntity.score,
volunteerJpaEntity.optionalScore,
list(volunteerApplicationJpaEntity.id),
set(volunteerApplicationJpaEntity.id),
volunteerJpaEntity.maxApplicants,
volunteerJpaEntity.availableSex,
volunteerJpaEntity.availableGrade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class QueryVolunteerWithCurrentApplicantVO @QueryProjection constructor(
name: String,
score: Int,
optionalScore: Int,
currentApplicants: List<UUID>,
currentApplicants: Set<UUID>,
maxApplicants: Int,
availableSex: Sex,
availableGrade: AvailableGrade,
Expand Down

0 comments on commit 7de8ed1

Please sign in to comment.