parent
96f571e0c4
commit
7a395a9906
|
@ -11,7 +11,7 @@ import javax.persistence.ManyToOne
|
|||
data class AuditionApplicant(
|
||||
val phoneNumber: String,
|
||||
var voicePath: String? = null,
|
||||
val isActive: Boolean = true
|
||||
var isActive: Boolean = true
|
||||
) : BaseEntity() {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "role_id", nullable = false)
|
||||
|
|
|
@ -20,6 +20,8 @@ interface AuditionApplicantQueryRepository {
|
|||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetAuditionRoleApplicantItem>
|
||||
|
||||
fun findActiveApplicantByMemberIdAndRoleId(memberId: Long, roleId: Long): AuditionApplicant?
|
||||
}
|
||||
|
||||
class AuditionApplicantQueryRepositoryImpl(
|
||||
|
@ -90,4 +92,15 @@ class AuditionApplicantQueryRepositoryImpl(
|
|||
.orderBy(orderBy)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
override fun findActiveApplicantByMemberIdAndRoleId(memberId: Long, roleId: Long): AuditionApplicant? {
|
||||
return queryFactory
|
||||
.selectFrom(auditionApplicant)
|
||||
.where(
|
||||
auditionApplicant.isActive.isTrue
|
||||
.and(auditionApplicant.member.id.eq(memberId))
|
||||
.and(auditionApplicant.role.id.eq(roleId))
|
||||
)
|
||||
.fetchFirst()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,16 @@ class AuditionApplicantService(
|
|||
val auditionRole = roleRepository.findByIdOrNull(id = request.roleId)
|
||||
?: throw SodaException("잘못된 요청입니다.\n다시 시도해 주세요.")
|
||||
|
||||
val existingApplicant = repository.findActiveApplicantByMemberIdAndRoleId(
|
||||
memberId = member.id!!,
|
||||
roleId = auditionRole.id!!
|
||||
)
|
||||
|
||||
if (existingApplicant != null) {
|
||||
existingApplicant.isActive = false
|
||||
repository.save(existingApplicant)
|
||||
}
|
||||
|
||||
val applicant = AuditionApplicant(phoneNumber = request.phoneNumber)
|
||||
applicant.role = auditionRole
|
||||
applicant.member = member
|
||||
|
|
Loading…
Reference in New Issue