Skip to content

Commit

Permalink
refactor: 초대코드 검증 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi committed Dec 10, 2024
1 parent d097181 commit 8f7c241
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.official.cufitapi.domain.api.dto.invitation

import com.official.cufitapi.domain.enums.MatchMakerCandidateRelation
import com.official.cufitapi.domain.enums.MatchMakerCandidateRelationType
import com.official.cufitapi.domain.enums.MemberType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ class InvitationService(
private const val BASE_62_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
}

@Transactional
fun validate(memberId: Long, request: InvitationCodeRequest) {
val member = memberJpaRepository.findByIdOrNull(memberId) ?: throw InvalidRequestException("존재하지 않는 사용자 id : $memberId")
if (MemberType.invitationCodePrefix(member.currentType) != request.invitationCode.substring(0,2)) {
throw InvalidRequestException("잘못된 사용자 초대코드")
}

if (!invitationJpaRepository.existsByMemberIdAndCode(memberId, request.invitationCode)) {
if (!invitationJpaRepository.existsByMemberIdAndCodeAndActivatedIsTrue(memberId, request.invitationCode)) {
throw InvalidRequestException("잘못된 사용자 초대코드")
}

// TODO : 초대코드 검증 성공하면, 초대코드 삭제
// 검증 성공하면, 초대코드 Soft Delete
val invitation = invitationJpaRepository.findByCode(request.invitationCode) ?: throw InvalidRequestException("유효하지 않은 초대 코드")
invitation.deactivate()

}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class Invitation(
/*
초대한 사용자 ID
*/
val memberId: Long
val memberId: Long,
/*
사용 여부
: 초대코드는 사용되면, 삭제 되어야하지만 이후에 추적을 위해서, Soft Delete
*/
var isActivated: Boolean = true

) : BaseTimeEntity() {

fun deactivate() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository

interface InvitationJpaRepository : JpaRepository<Invitation, Long> {

fun existsByMemberIdAndCode(memberId: Long, code: String) : Boolean
fun existsByMemberIdAndCodeAndActivatedIsTrue(memberId: Long, code: String) : Boolean
fun findByCode(code: String) : Invitation?
}

0 comments on commit 8f7c241

Please sign in to comment.