Skip to content

Commit a356980

Browse files
authored
Merge pull request #317 from mosu-dev/refactor/mosu-292
MOSU-292 refactor: 추천인 검증 시 결제 완료 검증
2 parents abdc8fc + c808f8a commit a356980

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/main/java/life/mosu/mosuserver/application/profile/RecommenderService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package life.mosu.mosuserver.application.profile;
22

3+
import life.mosu.mosuserver.domain.examapplication.repository.ExamApplicationJpaRepository;
34
import life.mosu.mosuserver.domain.profile.entity.ProfileJpaEntity;
45
import life.mosu.mosuserver.domain.profile.repository.ProfileJpaRepository;
56
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
@@ -17,23 +18,24 @@
1718
public class RecommenderService {
1819

1920
private final ProfileJpaRepository profileJpaRepository;
21+
private final ExamApplicationJpaRepository examApplicationJpaRepository;
2022

2123
@Transactional
2224
public void registerRecommender(Long userId, RecommenderRegistrationRequest request) {
2325
ProfileJpaEntity profile = profileJpaRepository.findByUserId(userId)
2426
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.PROFILE_NOT_FOUND));
25-
if (profile.getRecommenderPhoneNumber() != null) {
26-
throw new CustomRuntimeException(ErrorCode.ALREADY_REGISTERED_RECOMMENDER);
27-
}
28-
2927
profile.registerRecommenderPhoneNumber(request.phoneNumber());
3028
}
3129

3230
@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
3331
public Boolean verifyRecommender(Long userId) {
3432
ProfileJpaEntity profile = profileJpaRepository.findByUserId(userId)
3533
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.PROFILE_NOT_FOUND));
36-
return profile.getRecommenderPhoneNumber() != null;
34+
if (profile.getRecommenderPhoneNumber() == null) {
35+
return false;
36+
}
37+
38+
return examApplicationJpaRepository.existsPaymentDoneByUserId(userId);
3739
}
3840

3941
}

src/main/java/life/mosu/mosuserver/domain/examapplication/repository/ExamApplicationJpaRepository.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ Optional<ExamApplicationNotifyProjection> findExamAndPaymentByExamApplicationId(
143143
JOIN PaymentJpaEntity p ON p.examApplicationId = ea.id
144144
WHERE ea.id = :examApplicationId
145145
AND p.paymentStatus = 'DONE'
146-
AND p.deleted = false
147146
""")
148147
Optional<ExamInfoWithExamNumberProjection> findExamInfoWithExamNumber(
149148
@Param("examApplicationId") Long examApplicationId);
@@ -194,4 +193,17 @@ SELECT COUNT(ea)
194193
AND p.deleted = false
195194
""")
196195
long countAll();
196+
197+
@Query("""
198+
select exists (
199+
select 1
200+
from ExamApplicationJpaEntity ea
201+
join PaymentJpaEntity p on p.examApplicationId = ea.id
202+
where ea.userId = :userId
203+
and p.paymentStatus = 'DONE'
204+
and p.deleted = false
205+
and ea.deleted = false
206+
)
207+
""")
208+
boolean existsPaymentDoneByUserId(@Param("userId") Long userId);
197209
}

0 commit comments

Comments
 (0)