Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package life.mosu.mosuserver.application.profile;

import life.mosu.mosuserver.domain.examapplication.repository.ExamApplicationJpaRepository;
import life.mosu.mosuserver.domain.profile.entity.ProfileJpaEntity;
import life.mosu.mosuserver.domain.profile.repository.ProfileJpaRepository;
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
Expand All @@ -17,23 +18,24 @@
public class RecommenderService {

private final ProfileJpaRepository profileJpaRepository;
private final ExamApplicationJpaRepository examApplicationJpaRepository;

@Transactional
public void registerRecommender(Long userId, RecommenderRegistrationRequest request) {
ProfileJpaEntity profile = profileJpaRepository.findByUserId(userId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.PROFILE_NOT_FOUND));
if (profile.getRecommenderPhoneNumber() != null) {
throw new CustomRuntimeException(ErrorCode.ALREADY_REGISTERED_RECOMMENDER);
}

profile.registerRecommenderPhoneNumber(request.phoneNumber());
}

@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
public Boolean verifyRecommender(Long userId) {
ProfileJpaEntity profile = profileJpaRepository.findByUserId(userId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.PROFILE_NOT_FOUND));
return profile.getRecommenderPhoneNumber() != null;
if (profile.getRecommenderPhoneNumber() == null) {
return false;
}

return examApplicationJpaRepository.existsPaymentDoneByUserId(userId);
Comment on lines +34 to +38

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

verifyRecommender 메서드의 로직을 더 간결하게 개선할 수 있습니다. if 문을 사용하는 대신, 논리 AND(&&) 연산자를 사용하여 한 줄로 표현하면 가독성이 향상됩니다.

        return profile.getRecommenderPhoneNumber() != null && examApplicationJpaRepository.existsPaymentDoneByUserId(userId);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ Optional<ExamApplicationNotifyProjection> findExamAndPaymentByExamApplicationId(
JOIN PaymentJpaEntity p ON p.examApplicationId = ea.id
WHERE ea.id = :examApplicationId
AND p.paymentStatus = 'DONE'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

findExamInfoWithExamNumber 쿼리에서 p.deleted = false 조건이 누락되었습니다. 이 리포지토리의 다른 쿼리들(새로 추가된 existsPaymentDoneByUserId 포함)에서는 소프트 삭제된 데이터를 필터링하기 위해 deleted = false 조건을 명시적으로 사용하고 있습니다. 일관성을 유지하고 잠재적인 버그(삭제된 결제 정보가 조회되는 문제)를 방지하기 위해 이 조건을 추가하는 것을 권장합니다.

                AND p.paymentStatus = 'DONE'
                AND p.deleted = false

AND p.deleted = false
""")
Optional<ExamInfoWithExamNumberProjection> findExamInfoWithExamNumber(
@Param("examApplicationId") Long examApplicationId);
Expand Down Expand Up @@ -194,4 +193,17 @@ SELECT COUNT(ea)
AND p.deleted = false
""")
long countAll();

@Query("""
select exists (
select 1
from ExamApplicationJpaEntity ea
join PaymentJpaEntity p on p.examApplicationId = ea.id
where ea.userId = :userId
and p.paymentStatus = 'DONE'
and p.deleted = false
and ea.deleted = false
)
""")
boolean existsPaymentDoneByUserId(@Param("userId") Long userId);
}