앱 - 오디션 지원 API

- 기존에 지원한 내역이 있으면 false 처리 후 지원
This commit is contained in:
Klaus 2025-01-02 22:46:57 +09:00
parent 96f571e0c4
commit 7a395a9906
3 changed files with 24 additions and 1 deletions

View File

@ -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)

View File

@ -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()
}
}

View File

@ -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