diff --git a/src/main/java/com/example/sinitto/common/dummy/InitialData.java b/src/main/java/com/example/sinitto/common/dummy/InitialData.java index 57131d9d..3a19edff 100644 --- a/src/main/java/com/example/sinitto/common/dummy/InitialData.java +++ b/src/main/java/com/example/sinitto/common/dummy/InitialData.java @@ -12,9 +12,9 @@ import com.example.sinitto.helloCall.repository.HelloCallRepository; import com.example.sinitto.helloCall.repository.HelloCallTimeLogRepository; import com.example.sinitto.helloCall.repository.TimeSlotRepository; +import com.example.sinitto.helloCall.service.HelloCallService; import com.example.sinitto.member.entity.Member; import com.example.sinitto.member.entity.Senior; -import com.example.sinitto.member.entity.Sinitto; import com.example.sinitto.member.repository.MemberRepository; import com.example.sinitto.point.entity.Point; import com.example.sinitto.point.entity.PointLog; @@ -22,7 +22,8 @@ import com.example.sinitto.point.repository.PointRepository; import com.example.sinitto.review.entity.Review; import com.example.sinitto.review.repository.ReviewRepository; -import com.example.sinitto.sinitto.repository.SinittoRepository; +import com.example.sinitto.sinitto.entity.SinittoBankInfo; +import com.example.sinitto.sinitto.repository.SinittoBankInfoRepository; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @@ -37,7 +38,7 @@ public class InitialData implements CommandLineRunner { private final SeniorRepository seniorRepository; private final PointRepository pointRepository; private final CallbackRepository callbackRepository; - private final SinittoRepository sinittoRepository; + private final SinittoBankInfoRepository sinittoBankInfoRepository; private final PointLogRepository pointLogRepository; private final ReviewRepository reviewRepository; private final GuardGuidelineRepository guardGuidelineRepository; @@ -45,19 +46,20 @@ public class InitialData implements CommandLineRunner { private final TimeSlotRepository timeSlotRepository; private final HelloCallTimeLogRepository helloCallTimeLogRepository; private final TokenService tokenService; + private final HelloCallService helloCallService; public InitialData(MemberRepository memberRepository, SeniorRepository seniorRepository, PointRepository pointRepository, CallbackRepository callbackRepository, - SinittoRepository sinittoRepository, PointLogRepository pointLogRepository, + SinittoBankInfoRepository sinittoBankInfoRepository, PointLogRepository pointLogRepository, ReviewRepository reviewRepository, GuardGuidelineRepository guardGuidelineRepository, HelloCallRepository helloCallRepository, TimeSlotRepository timeSlotRepository, - HelloCallTimeLogRepository helloCallTimeLogRepository, TokenService tokenService) { + HelloCallTimeLogRepository helloCallTimeLogRepository, TokenService tokenService, HelloCallService helloCallService) { this.memberRepository = memberRepository; this.seniorRepository = seniorRepository; this.pointRepository = pointRepository; this.callbackRepository = callbackRepository; - this.sinittoRepository = sinittoRepository; + this.sinittoBankInfoRepository = sinittoBankInfoRepository; this.pointLogRepository = pointLogRepository; this.reviewRepository = reviewRepository; this.guardGuidelineRepository = guardGuidelineRepository; @@ -65,6 +67,7 @@ public InitialData(MemberRepository memberRepository, SeniorRepository seniorRep this.timeSlotRepository = timeSlotRepository; this.helloCallTimeLogRepository = helloCallTimeLogRepository; this.tokenService = tokenService; + this.helloCallService = helloCallService; } @Override @@ -90,16 +93,16 @@ private void saveRefreshTokenToRedis() { private void initial() { //시니또 - Member MemberSinitto1 = memberRepository.save(new Member("김철수", "01012345678", "1chulsoo@example.com", true)); - Sinitto sinitto1 = sinittoRepository.save(new Sinitto("신한은행", "123-23-444-422", MemberSinitto1)); - Member MemberSinitto2 = memberRepository.save(new Member("김유진", "01023456789", "2kim@example.com", true)); - Sinitto sinitto2 = sinittoRepository.save(new Sinitto("대구은행", "446-5-11-2", MemberSinitto2)); - Member MemberSinitto3 = memberRepository.save(new Member("이민호", "01034567890", "3lee@example.com", true)); - Sinitto sinitto3 = sinittoRepository.save(new Sinitto("IBK은행", "7-66-8-422", MemberSinitto3)); - Member MemberSinitto4 = memberRepository.save(new Member("박소연", "01045678901", "4park@example.com", true)); - Sinitto sinitto4 = sinittoRepository.save(new Sinitto("토스뱅크", "777-1-2-3", MemberSinitto4)); - Member MemberSinitto5 = memberRepository.save(new Member("최진우", "01056789012", "5choi@example.com", true)); - Sinitto sinitto5 = sinittoRepository.save(new Sinitto("기업은행", "96-6-99-45", MemberSinitto5)); + Member memberSinitto1 = memberRepository.save(new Member("김철수", "01012345678", "1chulsoo@example.com", true)); + sinittoBankInfoRepository.save(new SinittoBankInfo("신한은행", "123-23-444-422", memberSinitto1)); + Member memberSinitto2 = memberRepository.save(new Member("김유진", "01023456789", "2kim@example.com", true)); + sinittoBankInfoRepository.save(new SinittoBankInfo("대구은행", "446-5-11-2", memberSinitto2)); + Member memberSinitto3 = memberRepository.save(new Member("이민호", "01034567890", "3lee@example.com", true)); + sinittoBankInfoRepository.save(new SinittoBankInfo("IBK은행", "7-66-8-422", memberSinitto3)); + Member memberSinitto4 = memberRepository.save(new Member("박소연", "01045678901", "4park@example.com", true)); + sinittoBankInfoRepository.save(new SinittoBankInfo("토스뱅크", "777-1-2-3", memberSinitto4)); + Member memberSinitto5 = memberRepository.save(new Member("최진우", "01056789012", "5choi@example.com", true)); + sinittoBankInfoRepository.save(new SinittoBankInfo("기업은행", "96-6-99-45", memberSinitto5)); //보호자 Member guard1 = memberRepository.save(new Member("정예린", "01067890123", "6jeong@example.com", false)); @@ -141,81 +144,81 @@ private void initial() { Senior senior30 = seniorRepository.save(new Senior("오예림", "01091268437", guard5)); //포인트와 포인트로그 - pointRepository.save(new Point(50000, MemberSinitto1)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.CHARGE_FAIL)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.CHARGE_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.CHARGE_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.CHARGE_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), MemberSinitto1, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), MemberSinitto1, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), MemberSinitto1, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), MemberSinitto1, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), MemberSinitto1, 50000, PointLog.Status.SPEND_CANCEL)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.WITHDRAW_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.WITHDRAW_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.WITHDRAW_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto1, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); - - pointRepository.save(new Point(50000, MemberSinitto2)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.CHARGE_FAIL)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.CHARGE_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.CHARGE_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.CHARGE_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), MemberSinitto2, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), MemberSinitto2, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), MemberSinitto2, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), MemberSinitto2, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), MemberSinitto2, 50000, PointLog.Status.SPEND_CANCEL)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.WITHDRAW_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.WITHDRAW_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.WITHDRAW_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto2, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); - - pointRepository.save(new Point(50000, MemberSinitto3)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.CHARGE_FAIL)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.CHARGE_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.CHARGE_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.CHARGE_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), MemberSinitto3, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), MemberSinitto3, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), MemberSinitto3, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), MemberSinitto3, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), MemberSinitto3, 50000, PointLog.Status.SPEND_CANCEL)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.WITHDRAW_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.WITHDRAW_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.WITHDRAW_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto3, 50000, PointLog.Status.CHARGE_COMPLETE)); - - pointRepository.save(new Point(50000, MemberSinitto4)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.CHARGE_FAIL)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.CHARGE_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.CHARGE_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.CHARGE_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), MemberSinitto4, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), MemberSinitto4, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), MemberSinitto4, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), MemberSinitto4, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), MemberSinitto4, 50000, PointLog.Status.SPEND_CANCEL)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.WITHDRAW_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.WITHDRAW_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.WITHDRAW_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto4, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); - - pointRepository.save(new Point(50000, MemberSinitto5)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.CHARGE_FAIL)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.CHARGE_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.CHARGE_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.CHARGE_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), MemberSinitto5, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), MemberSinitto5, 50000, PointLog.Status.EARN)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), MemberSinitto5, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), MemberSinitto5, 50000, PointLog.Status.SPEND_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), MemberSinitto5, 50000, PointLog.Status.SPEND_CANCEL)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.WITHDRAW_REQUEST)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.WITHDRAW_WAITING)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.WITHDRAW_COMPLETE)); - pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), MemberSinitto5, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); + pointRepository.save(new Point(50000, memberSinitto1)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.CHARGE_FAIL)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.CHARGE_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.CHARGE_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.CHARGE_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), memberSinitto1, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), memberSinitto1, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), memberSinitto1, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), memberSinitto1, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), memberSinitto1, 50000, PointLog.Status.SPEND_CANCEL)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.WITHDRAW_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.WITHDRAW_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.WITHDRAW_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto1, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); + + pointRepository.save(new Point(50000, memberSinitto2)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.CHARGE_FAIL)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.CHARGE_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.CHARGE_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.CHARGE_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), memberSinitto2, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), memberSinitto2, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), memberSinitto2, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), memberSinitto2, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), memberSinitto2, 50000, PointLog.Status.SPEND_CANCEL)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.WITHDRAW_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.WITHDRAW_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.WITHDRAW_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto2, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); + + pointRepository.save(new Point(50000, memberSinitto3)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.CHARGE_FAIL)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.CHARGE_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.CHARGE_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.CHARGE_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), memberSinitto3, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), memberSinitto3, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), memberSinitto3, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), memberSinitto3, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), memberSinitto3, 50000, PointLog.Status.SPEND_CANCEL)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.WITHDRAW_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.WITHDRAW_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.WITHDRAW_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto3, 50000, PointLog.Status.CHARGE_COMPLETE)); + + pointRepository.save(new Point(50000, memberSinitto4)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.CHARGE_FAIL)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.CHARGE_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.CHARGE_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.CHARGE_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), memberSinitto4, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), memberSinitto4, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), memberSinitto4, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), memberSinitto4, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), memberSinitto4, 50000, PointLog.Status.SPEND_CANCEL)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.WITHDRAW_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.WITHDRAW_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.WITHDRAW_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto4, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); + + pointRepository.save(new Point(50000, memberSinitto5)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.CHARGE_FAIL)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.CHARGE_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.CHARGE_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.CHARGE_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_CALLBACK_AND_EARN.getMessage(), memberSinitto5, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.COMPLETE_HELLO_CALL_AND_EARN.getMessage(), memberSinitto5, 50000, PointLog.Status.EARN)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_HELLO_CALL.getMessage(), memberSinitto5, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_COMPLETE_CALLBACK.getMessage(), memberSinitto5, 50000, PointLog.Status.SPEND_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.SPEND_CANCEL_HELLO_CALL.getMessage(), memberSinitto5, 50000, PointLog.Status.SPEND_CANCEL)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.WITHDRAW_REQUEST)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.WITHDRAW_WAITING)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.WITHDRAW_COMPLETE)); + pointLogRepository.save(new PointLog(PointLog.Content.WITHDRAW_REQUEST.getMessage(), memberSinitto5, 50000, PointLog.Status.WITHDRAW_FAIL_AND_RESTORE_POINT)); pointRepository.save(new Point(50000, guard1)); pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), guard1, 50000, PointLog.Status.CHARGE_FAIL)); @@ -501,42 +504,55 @@ private void initial() { timeSlotRepository.save(new TimeSlot("토", LocalTime.of(18, 30), LocalTime.of(20, 30), helloCall26)); timeSlotRepository.save(new TimeSlot("일", LocalTime.of(18, 0), LocalTime.of(20, 0), helloCall26)); + //시니또 안부전화 할당 + helloCallService.acceptHelloCallBySinitto(memberSinitto1.getId(), helloCall1.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto1.getId(), helloCall2.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto2.getId(), helloCall3.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto2.getId(), helloCall4.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto3.getId(), helloCall5.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto4.getId(), helloCall6.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto4.getId(), helloCall7.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto5.getId(), helloCall8.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto5.getId(), helloCall9.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto2.getId(), helloCall10.getId()); + helloCallService.acceptHelloCallBySinitto(memberSinitto3.getId(), helloCall11.getId()); + //안부전화 실시 타임로그 - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, sinitto1, LocalDateTime.of(2024, 8, 5, 18, 30), LocalDateTime.of(2024, 8, 5, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, sinitto1, LocalDateTime.of(2024, 8, 7, 18, 30), LocalDateTime.of(2024, 8, 7, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, sinitto1, LocalDateTime.of(2024, 8, 9, 18, 30), LocalDateTime.of(2024, 8, 9, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, sinitto1, LocalDateTime.of(2024, 8, 11, 18, 30), LocalDateTime.of(2024, 8, 11, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, sinitto1, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, memberSinitto3, LocalDateTime.of(2024, 8, 5, 18, 30), LocalDateTime.of(2024, 8, 5, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, memberSinitto3, LocalDateTime.of(2024, 8, 7, 18, 30), LocalDateTime.of(2024, 8, 7, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, memberSinitto1, LocalDateTime.of(2024, 8, 9, 18, 30), LocalDateTime.of(2024, 8, 9, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, memberSinitto1, LocalDateTime.of(2024, 8, 11, 18, 30), LocalDateTime.of(2024, 8, 11, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall1, memberSinitto1, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall2, sinitto1, LocalDateTime.of(2024, 8, 2, 10, 30), LocalDateTime.of(2024, 8, 2, 10, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall2, sinitto2, LocalDateTime.of(2024, 8, 5, 11, 30), LocalDateTime.of(2024, 8, 5, 11, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall2, memberSinitto1, LocalDateTime.of(2024, 8, 2, 10, 30), LocalDateTime.of(2024, 8, 2, 10, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall2, memberSinitto1, LocalDateTime.of(2024, 8, 5, 11, 30), LocalDateTime.of(2024, 8, 5, 11, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall3, sinitto2, LocalDateTime.of(2024, 10, 8, 18, 30), LocalDateTime.of(2024, 10, 8, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall3, sinitto2, LocalDateTime.of(2024, 10, 10, 18, 30), LocalDateTime.of(2024, 10, 10, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall3, memberSinitto2, LocalDateTime.of(2024, 10, 8, 18, 30), LocalDateTime.of(2024, 10, 8, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall3, memberSinitto2, LocalDateTime.of(2024, 10, 10, 18, 30), LocalDateTime.of(2024, 10, 10, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall4, sinitto2, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall4, sinitto2, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall4, memberSinitto2, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall4, memberSinitto2, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall5, sinitto3, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall5, sinitto5, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall5, memberSinitto3, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall5, memberSinitto3, LocalDateTime.of(2024, 10, 13, 18, 30), LocalDateTime.of(2024, 10, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall6, sinitto4, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall6, sinitto4, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall6, memberSinitto3, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall6, memberSinitto4, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall7, sinitto4, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall7, sinitto4, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall7, memberSinitto4, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall7, memberSinitto4, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall8, sinitto5, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall8, sinitto5, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall8, memberSinitto5, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall8, memberSinitto5, LocalDateTime.of(2024, 8, 13, 18, 30), LocalDateTime.of(2024, 8, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall9, sinitto5, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall9, sinitto5, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall9, memberSinitto5, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall9, memberSinitto5, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall10, sinitto2, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall10, sinitto2, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall10, memberSinitto2, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall10, memberSinitto2, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall11, sinitto3, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); - helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall11, sinitto5, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall11, memberSinitto3, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); + helloCallTimeLogRepository.save(new HelloCallTimeLog(helloCall11, memberSinitto3, LocalDateTime.of(2024, 6, 13, 18, 30), LocalDateTime.of(2024, 6, 13, 18, 40))); } diff --git a/src/main/java/com/example/sinitto/helloCall/controller/HelloCallController.java b/src/main/java/com/example/sinitto/helloCall/controller/HelloCallController.java index fcf673f8..fd8ba62c 100644 --- a/src/main/java/com/example/sinitto/helloCall/controller/HelloCallController.java +++ b/src/main/java/com/example/sinitto/helloCall/controller/HelloCallController.java @@ -132,7 +132,7 @@ public ResponseEntity writeHelloCallEndTimeBySinitto(@Mem @PostMapping("/reports") public ResponseEntity createHelloCallReport(@MemberId Long memberId, @RequestBody HelloCallReportRequest request) { - helloCallService.SendReportBySinitto(memberId, request); + helloCallService.sendReportBySinitto(memberId, request); return ResponseEntity.status(HttpStatus.CREATED).body(new StringMessageResponse("소통 보고서가 작성되었습니다.")); } diff --git a/src/main/java/com/example/sinitto/helloCall/dto/HelloCallTimeResponse.java b/src/main/java/com/example/sinitto/helloCall/dto/HelloCallTimeResponse.java deleted file mode 100644 index 62c78f27..00000000 --- a/src/main/java/com/example/sinitto/helloCall/dto/HelloCallTimeResponse.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.example.sinitto.helloCall.dto; - -import java.time.LocalDateTime; - -public record HelloCallTimeResponse( - LocalDateTime DateAndTime -) { -} diff --git a/src/main/java/com/example/sinitto/helloCall/entity/HelloCall.java b/src/main/java/com/example/sinitto/helloCall/entity/HelloCall.java index 7cb1a1b9..47877d29 100644 --- a/src/main/java/com/example/sinitto/helloCall/entity/HelloCall.java +++ b/src/main/java/com/example/sinitto/helloCall/entity/HelloCall.java @@ -5,7 +5,6 @@ import com.example.sinitto.helloCall.exception.TimeRuleException; import com.example.sinitto.member.entity.Member; import com.example.sinitto.member.entity.Senior; -import com.example.sinitto.member.entity.Sinitto; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import org.hibernate.annotations.OnDelete; @@ -44,8 +43,8 @@ public class HelloCall { @OneToMany(mappedBy = "helloCall", cascade = CascadeType.REMOVE) private List timeSlots = new ArrayList<>(); @ManyToOne - @JoinColumn(name = "sinitto_id") - private Sinitto sinitto; + @JoinColumn(name = "member_id") + private Member member; @OneToMany(mappedBy = "helloCall", cascade = CascadeType.REMOVE) private List helloCallTimeLogs = new ArrayList<>(); @@ -102,12 +101,12 @@ public int getServiceTime() { return serviceTime; } - public Sinitto getSinitto() { - return sinitto; + public Member getMember() { + return member; } - public void setSinitto(Sinitto sinitto) { - this.sinitto = sinitto; + public void setMember(Member member) { + this.member = member; } public String getReport() { @@ -118,12 +117,8 @@ public void setReport(String report) { this.report = report; } - public String getSinittoName() { - return this.sinitto.getMember().getName(); - } - - public List getHelloCallTimeLogs() { - return helloCallTimeLogs; + public String getMemberName() { + return this.member.getName(); } public void checkStatusIsWaiting() { @@ -132,12 +127,6 @@ public void checkStatusIsWaiting() { } } - public void checkSiniitoIsSame(Sinitto sinitto) { - if (!this.sinitto.equals(sinitto)) { - throw new UnauthorizedException("안부전화 서비스 리포트를 작성할 권한이 없습니다."); - } - } - public void checkGuardIsCorrect(Member member) { if (!this.senior.getMember().equals(member)) { throw new UnauthorizedException("해당 시니어의 안부전화를 신청한 보호자가 아닙니다. 권한이 없습니다."); @@ -152,6 +141,12 @@ public boolean checkReportIsNotNull() { return this.report != null; } + public void checkMemberIsRightSinitto(Member member) { + if (this.member == null || !this.member.equals(member)) { + throw new UnauthorizedException("해당 안부전화를 수행하는 시니또가 아닙니다."); + } + } + public void changeStatusToInProgress() { if (status.canNotProgressStatus(Status.IN_PROGRESS)) { throw new InvalidStatusException("안부전화 서비스가 수행 대기중일 때만 진행중 상태로 나아갈 수 있습니다. 현재 상태 : " + this.status); diff --git a/src/main/java/com/example/sinitto/helloCall/entity/HelloCallTimeLog.java b/src/main/java/com/example/sinitto/helloCall/entity/HelloCallTimeLog.java index fd38b036..4b1a3bdc 100644 --- a/src/main/java/com/example/sinitto/helloCall/entity/HelloCallTimeLog.java +++ b/src/main/java/com/example/sinitto/helloCall/entity/HelloCallTimeLog.java @@ -1,6 +1,6 @@ package com.example.sinitto.helloCall.entity; -import com.example.sinitto.member.entity.Sinitto; +import com.example.sinitto.member.entity.Member; import jakarta.persistence.*; import java.time.LocalDateTime; @@ -18,18 +18,18 @@ public class HelloCallTimeLog { private HelloCall helloCall; @ManyToOne @JoinColumn(name = "sinitto_id") - private Sinitto sinitto; + private Member member; - public HelloCallTimeLog(HelloCall helloCall, Sinitto sinitto) { + public HelloCallTimeLog(HelloCall helloCall, Member member) { this.helloCall = helloCall; - this.sinitto = sinitto; + this.member = member; } - public HelloCallTimeLog(HelloCall helloCall, Sinitto sinitto, LocalDateTime startDateAndTime, LocalDateTime endDateAndTime) { + public HelloCallTimeLog(HelloCall helloCall, Member member, LocalDateTime startDateAndTime, LocalDateTime endDateAndTime) { this.helloCall = helloCall; this.startDateAndTime = startDateAndTime; this.endDateAndTime = endDateAndTime; - this.sinitto = sinitto; + this.member = member; } protected HelloCallTimeLog() { @@ -52,14 +52,14 @@ public void setEndDateAndTime(LocalDateTime endDateAndTime) { } public String getSinittoName() { - return this.sinitto.getMember().getName(); + return this.member.getName(); } public HelloCall getHelloCall() { return helloCall; } - public Sinitto getSinitto() { - return sinitto; + public Member getSinitto() { + return member; } } diff --git a/src/main/java/com/example/sinitto/helloCall/repository/HelloCallRepository.java b/src/main/java/com/example/sinitto/helloCall/repository/HelloCallRepository.java index f166ab30..f6b68832 100644 --- a/src/main/java/com/example/sinitto/helloCall/repository/HelloCallRepository.java +++ b/src/main/java/com/example/sinitto/helloCall/repository/HelloCallRepository.java @@ -1,8 +1,8 @@ package com.example.sinitto.helloCall.repository; import com.example.sinitto.helloCall.entity.HelloCall; +import com.example.sinitto.member.entity.Member; import com.example.sinitto.member.entity.Senior; -import com.example.sinitto.member.entity.Sinitto; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -14,7 +14,7 @@ public interface HelloCallRepository extends JpaRepository { Optional findBySenior(Senior senior); - List findAllBySinitto(Sinitto sinitto); + List findAllByMember(Member member); List findAllBySeniorIn(List seniors); diff --git a/src/main/java/com/example/sinitto/helloCall/repository/HelloCallTimeLogRepository.java b/src/main/java/com/example/sinitto/helloCall/repository/HelloCallTimeLogRepository.java index a62dca5b..af647940 100644 --- a/src/main/java/com/example/sinitto/helloCall/repository/HelloCallTimeLogRepository.java +++ b/src/main/java/com/example/sinitto/helloCall/repository/HelloCallTimeLogRepository.java @@ -2,16 +2,16 @@ import com.example.sinitto.helloCall.entity.HelloCall; import com.example.sinitto.helloCall.entity.HelloCallTimeLog; -import com.example.sinitto.member.entity.Sinitto; +import com.example.sinitto.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; import java.util.Optional; public interface HelloCallTimeLogRepository extends JpaRepository { - Optional findBySinittoAndHelloCallId(Sinitto sinitto, Long helloCallId); - List findAllByHelloCallId(Long helloCallId); - Optional findTopBySinittoAndHelloCallOrderByStartDateAndTimeDesc(Sinitto sinitto, HelloCall helloCall); + Optional findByMemberAndHelloCallId(Member member, Long helloCallId); + + Optional findTopByMemberAndHelloCallOrderByStartDateAndTimeDesc(Member member, HelloCall helloCall); } diff --git a/src/main/java/com/example/sinitto/helloCall/service/HelloCallService.java b/src/main/java/com/example/sinitto/helloCall/service/HelloCallService.java index 8c5e43ae..7eed19b3 100644 --- a/src/main/java/com/example/sinitto/helloCall/service/HelloCallService.java +++ b/src/main/java/com/example/sinitto/helloCall/service/HelloCallService.java @@ -16,7 +16,6 @@ import com.example.sinitto.helloCall.repository.TimeSlotRepository; import com.example.sinitto.member.entity.Member; import com.example.sinitto.member.entity.Senior; -import com.example.sinitto.member.entity.Sinitto; import com.example.sinitto.member.exception.MemberNotFoundException; import com.example.sinitto.member.repository.MemberRepository; import com.example.sinitto.point.entity.Point; @@ -25,8 +24,6 @@ import com.example.sinitto.point.exception.PointNotFoundException; import com.example.sinitto.point.repository.PointLogRepository; import com.example.sinitto.point.repository.PointRepository; -import com.example.sinitto.sinitto.exception.SinittoNotFoundException; -import com.example.sinitto.sinitto.repository.SinittoRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -45,20 +42,18 @@ public class HelloCallService { private final TimeSlotRepository timeSlotRepository; private final SeniorRepository seniorRepository; private final MemberRepository memberRepository; - private final SinittoRepository sinittoRepository; private final HelloCallTimeLogRepository helloCallTimeLogRepository; private final PointRepository pointRepository; private final PointLogRepository pointLogRepository; public HelloCallService(HelloCallRepository helloCallRepository, TimeSlotRepository timeSlotRepository, - SeniorRepository seniorRepository, MemberRepository memberRepository, SinittoRepository sinittoRepository, - HelloCallTimeLogRepository helloCallTimeLogRepository, PointRepository pointRepository, PointLogRepository pointLogRepository) { + SeniorRepository seniorRepository, MemberRepository memberRepository, HelloCallTimeLogRepository helloCallTimeLogRepository, + PointRepository pointRepository, PointLogRepository pointLogRepository) { this.helloCallRepository = helloCallRepository; this.timeSlotRepository = timeSlotRepository; this.seniorRepository = seniorRepository; this.memberRepository = memberRepository; - this.sinittoRepository = sinittoRepository; this.helloCallTimeLogRepository = helloCallTimeLogRepository; this.pointRepository = pointRepository; this.pointLogRepository = pointLogRepository; @@ -243,7 +238,7 @@ public HelloCallReportResponse readHelloCallReportByGuard(Long memberId, Long he } return new HelloCallReportResponse(helloCall.getStartDate(), - helloCall.getEndDate(), helloCall.getSinittoName(), helloCall.getReport()); + helloCall.getEndDate(), helloCall.getMemberName(), helloCall.getReport()); } @Transactional @@ -258,7 +253,7 @@ public void makeCompleteHelloCallByGuard(Long memberId, Long helloCallId) { helloCall.changeStatusToComplete(); - Point sinittoPoint = pointRepository.findByMember(helloCall.getSinitto().getMember()) + Point sinittoPoint = pointRepository.findByMember(helloCall.getMember()) .orElseThrow(() -> new PointNotFoundException("포인트 적립 받을 시니또와 연관된 포인트가 없습니다")); sinittoPoint.earn(helloCall.getPrice()); @@ -281,7 +276,7 @@ public List readAllHelloCallReportByAdmin() { for (HelloCall helloCall : helloCalls) { if (helloCall.checkReportIsNotNull()) { HelloCallReportResponse response = new HelloCallReportResponse(helloCall.getStartDate(), - helloCall.getEndDate(), helloCall.getSinittoName(), helloCall.getReport()); + helloCall.getEndDate(), helloCall.getMemberName(), helloCall.getReport()); helloCallReportResponses.add(response); } } @@ -293,45 +288,52 @@ public void acceptHelloCallBySinitto(Long memberId, Long helloCallId) { HelloCall helloCall = helloCallRepository.findById(helloCallId) .orElseThrow(() -> new HelloCallNotFoundException("id에 해당하는 안부전화 정보를 찾을 수 없습니다.")); - Sinitto sinitto = sinittoRepository.findByMemberId(memberId) - .orElseThrow(() -> new SinittoNotFoundException("id에 해당하는 시니또를 찾을 수 없습니다.")); + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberNotFoundException("id에 해당하는 멤버가 없습니다.")); + + if (!member.isSinitto()) { + throw new UnauthorizedException("시니또가 아닙니다."); + } helloCall.changeStatusToInProgress(); - helloCall.setSinitto(sinitto); + helloCall.setMember(member); } @Transactional - public HelloCallTimeResponse writeHelloCallStartTimeBySinitto(Long memberId, Long helloCallId) { + public void writeHelloCallStartTimeBySinitto(Long memberId, Long helloCallId) { HelloCall helloCall = helloCallRepository.findById(helloCallId) .orElseThrow(() -> new HelloCallNotFoundException("id에 해당하는 안부전화 정보를 찾을 수 없습니다.")); - Sinitto sinitto = sinittoRepository.findByMemberId(memberId) - .orElseThrow(() -> new SinittoNotFoundException("id에 해당하는 시니또를 찾을 수 없습니다.")); + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberNotFoundException("id에 해당하는 멤버를 찾을 수 없습니다.")); + + helloCall.checkMemberIsRightSinitto(member); Optional recentLog = helloCallTimeLogRepository - .findTopBySinittoAndHelloCallOrderByStartDateAndTimeDesc(sinitto, helloCall); + .findTopByMemberAndHelloCallOrderByStartDateAndTimeDesc(member, helloCall); if (recentLog.isPresent() && recentLog.get().getEndDateAndTime() == null) { throw new TimeLogSequenceException("이미 시작된 안부전화가 있습니다. 종료를 먼저 완료해주세요."); } - HelloCallTimeLog helloCallTimeLog = new HelloCallTimeLog(helloCall, sinitto); + HelloCallTimeLog helloCallTimeLog = new HelloCallTimeLog(helloCall, member); helloCallTimeLog.setStartDateAndTime(LocalDateTime.now()); - HelloCallTimeLog savedHelloCallTimeLog = helloCallTimeLogRepository.save(helloCallTimeLog); - return new HelloCallTimeResponse(savedHelloCallTimeLog.getStartDateAndTime()); + helloCallTimeLogRepository.save(helloCallTimeLog); } @Transactional - public HelloCallTimeResponse writeHelloCallEndTimeBySinitto(Long memberId, Long helloCallId) { + public void writeHelloCallEndTimeBySinitto(Long memberId, Long helloCallId) { HelloCall helloCall = helloCallRepository.findById(helloCallId) .orElseThrow(() -> new HelloCallNotFoundException("id에 해당하는 안부전화 정보를 찾을 수 없습니다.")); - Sinitto sinitto = sinittoRepository.findByMemberId(memberId) - .orElseThrow(() -> new SinittoNotFoundException("id에 해당하는 시니또를 찾을 수 없습니다.")); + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberNotFoundException("id에 해당하는 멤버를 찾을 수 없습니다.")); + + helloCall.checkMemberIsRightSinitto(member); HelloCallTimeLog helloCallTimeLog = helloCallTimeLogRepository - .findTopBySinittoAndHelloCallOrderByStartDateAndTimeDesc(sinitto, helloCall) + .findTopByMemberAndHelloCallOrderByStartDateAndTimeDesc(member, helloCall) .orElseThrow(() -> new HelloCallNotFoundException("안부전화 로그를 찾을 수 없습니다.")); if (helloCallTimeLog.getEndDateAndTime() != null) { @@ -339,8 +341,6 @@ public HelloCallTimeResponse writeHelloCallEndTimeBySinitto(Long memberId, Long } helloCallTimeLog.setEndDateAndTime(LocalDateTime.now()); - - return new HelloCallTimeResponse(helloCallTimeLog.getEndDateAndTime()); } @Transactional @@ -348,23 +348,25 @@ public void cancelHelloCallBySinitto(Long memberId, Long helloCallId) { HelloCall helloCall = helloCallRepository.findById(helloCallId) .orElseThrow(() -> new HelloCallNotFoundException("id에 해당하는 안부전화 정보를 찾을 수 없습니다.")); - if (!sinittoRepository.existsByMemberId(memberId)) { - throw new SinittoNotFoundException("id에 해당하는 시니또를 찾을 수 없습니다."); - } + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberNotFoundException("id에 해당하는 멤버를 찾을 수 없습니다.")); + + helloCall.checkMemberIsRightSinitto(member); helloCall.changeStatusToWaiting(); - helloCall.setSinitto(null); + helloCall.setMember(null); } @Transactional - public void SendReportBySinitto(Long memberId, HelloCallReportRequest helloCallReportRequest) { + public void sendReportBySinitto(Long memberId, HelloCallReportRequest helloCallReportRequest) { HelloCall helloCall = helloCallRepository.findById(helloCallReportRequest.helloCallId()) .orElseThrow(() -> new HelloCallNotFoundException("id에 해당하는 안부전화 정보를 찾을 수 없습니다.")); - Sinitto sinitto = sinittoRepository.findByMemberId(memberId) - .orElseThrow(() -> new SinittoNotFoundException("id에 해당하는 시니또를 찾을 수 없습니다.")); + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberNotFoundException("id에 해당하는 멤버를 찾을 수 없습니다.")); + + helloCall.checkMemberIsRightSinitto(member); - helloCall.checkSiniitoIsSame(sinitto); if (helloCall.checkIsNotAfterEndDate()) { throw new CompletionConditionNotFulfilledException("서비스 종료 날짜보다 이른 날짜에 종료할 수 없습니다."); } @@ -375,10 +377,10 @@ public void SendReportBySinitto(Long memberId, HelloCallReportRequest helloCallR @Transactional(readOnly = true) public List readOwnHelloCallBySinitto(Long memberId) { - Sinitto sinitto = sinittoRepository.findByMemberId(memberId) - .orElseThrow(() -> new SinittoNotFoundException("id에 해당하는 시니또를 찾을 수 없습니다.")); + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberNotFoundException("id에 해당하는 멤버를 찾을 수 없습니다.")); - List helloCalls = helloCallRepository.findAllBySinitto(sinitto); + List helloCalls = helloCallRepository.findAllByMember(member); List helloCallResponses = new ArrayList<>(); @@ -391,5 +393,4 @@ public List readOwnHelloCallBySinitto(Long memberId) { return helloCallResponses; } - } diff --git a/src/main/java/com/example/sinitto/point/service/PointAdminService.java b/src/main/java/com/example/sinitto/point/service/PointAdminService.java index cc85b11a..940dccf3 100644 --- a/src/main/java/com/example/sinitto/point/service/PointAdminService.java +++ b/src/main/java/com/example/sinitto/point/service/PointAdminService.java @@ -1,13 +1,13 @@ package com.example.sinitto.point.service; -import com.example.sinitto.member.entity.Sinitto; +import com.example.sinitto.sinitto.entity.SinittoBankInfo; import com.example.sinitto.point.dto.PointLogWithBankInfo; import com.example.sinitto.point.entity.Point; import com.example.sinitto.point.entity.PointLog; import com.example.sinitto.point.exception.PointLogNotFoundException; import com.example.sinitto.point.repository.PointLogRepository; import com.example.sinitto.point.repository.PointRepository; -import com.example.sinitto.sinitto.repository.SinittoRepository; +import com.example.sinitto.sinitto.repository.SinittoBankInfoRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,12 +19,12 @@ public class PointAdminService { private final PointLogRepository pointLogRepository; private final PointRepository pointRepository; - private final SinittoRepository sinittoRepository; + private final SinittoBankInfoRepository sinittoBankInfoRepository; - public PointAdminService(PointLogRepository pointLogRepository, PointRepository pointRepository, SinittoRepository sinittoRepository) { + public PointAdminService(PointLogRepository pointLogRepository, PointRepository pointRepository, SinittoBankInfoRepository sinittoBankInfoRepository) { this.pointLogRepository = pointLogRepository; this.pointRepository = pointRepository; - this.sinittoRepository = sinittoRepository; + this.sinittoBankInfoRepository = sinittoBankInfoRepository; } public List readAllNotCompletedPointChargeRequest() { @@ -103,16 +103,16 @@ public List getPointLogWithBankInfo() { List logWithBankInfos = new ArrayList<>(); for (PointLog pointLog : withdrawPointLogs) { - Sinitto sinitto = sinittoRepository.findByMemberId(pointLog.getMember().getId()) - .orElse(new Sinitto("등록된 계좌 없음", "등록된 계좌 없음", null)); + SinittoBankInfo sinittoBankInfo = sinittoBankInfoRepository.findByMemberId(pointLog.getMember().getId()) + .orElse(new SinittoBankInfo("등록된 계좌 없음", "등록된 계좌 없음", null)); PointLogWithBankInfo pointLogWithBankInfo = new PointLogWithBankInfo( pointLog.getId(), pointLog.getPrice(), pointLog.getPostTime(), pointLog.getStatus(), - sinitto.getBankName(), - sinitto.getAccountNumber() + sinittoBankInfo.getBankName(), + sinittoBankInfo.getAccountNumber() ); logWithBankInfos.add(pointLogWithBankInfo); } diff --git a/src/main/java/com/example/sinitto/point/service/PointService.java b/src/main/java/com/example/sinitto/point/service/PointService.java index 7379357d..0348aeda 100644 --- a/src/main/java/com/example/sinitto/point/service/PointService.java +++ b/src/main/java/com/example/sinitto/point/service/PointService.java @@ -13,6 +13,8 @@ import com.example.sinitto.point.exception.PointNotFoundException; import com.example.sinitto.point.repository.PointLogRepository; import com.example.sinitto.point.repository.PointRepository; +import com.example.sinitto.sinitto.exception.SinittoBankInfoNotFoundException; +import com.example.sinitto.sinitto.repository.SinittoBankInfoRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -25,11 +27,13 @@ public class PointService { private final MemberRepository memberRepository; private final PointRepository pointRepository; private final PointLogRepository pointLogRepository; + private final SinittoBankInfoRepository sinittoBankInfoRepository; - public PointService(MemberRepository memberRepository, PointRepository pointRepository, PointLogRepository pointLogRepository) { + public PointService(MemberRepository memberRepository, PointRepository pointRepository, PointLogRepository pointLogRepository, SinittoBankInfoRepository sinittoBankInfoRepository) { this.memberRepository = memberRepository; this.pointRepository = pointRepository; this.pointLogRepository = pointLogRepository; + this.sinittoBankInfoRepository = sinittoBankInfoRepository; } public PointResponse getPoint(Long memberId) { @@ -74,10 +78,14 @@ public void savePointWithdrawRequest(Long memberId, int price) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new MemberNotFoundException("요청한 멤버를 찾을 수 없습니다")); - if(!member.isSinitto()){ + if (!member.isSinitto()) { throw new NotSinittoException("출금 요청은 시니또만 가능합니다. 지금 요청은 시니또가 요청하지 않았습니다."); } + if (!sinittoBankInfoRepository.existsByMemberId(memberId)) { + throw new SinittoBankInfoNotFoundException("시니또의 은행 계좌 정보가 없습니다. 계좌를 등록해야 합니다."); + } + Point point = pointRepository.findByMember(member) .orElseThrow(() -> new PointNotFoundException("요청한 멤버의 포인트를 찾을 수 없습니다")); diff --git a/src/main/java/com/example/sinitto/sinitto/controller/SinittoControllerAdvice.java b/src/main/java/com/example/sinitto/sinitto/controller/SinittoControllerAdvice.java index 6fee49bb..da30208d 100644 --- a/src/main/java/com/example/sinitto/sinitto/controller/SinittoControllerAdvice.java +++ b/src/main/java/com/example/sinitto/sinitto/controller/SinittoControllerAdvice.java @@ -1,6 +1,6 @@ package com.example.sinitto.sinitto.controller; -import com.example.sinitto.sinitto.exception.SinittoNotFoundException; +import com.example.sinitto.sinitto.exception.SinittoBankInfoNotFoundException; import org.springframework.http.HttpStatus; import org.springframework.http.ProblemDetail; import org.springframework.http.ResponseEntity; @@ -11,11 +11,11 @@ @RestControllerAdvice(basePackages = "com.example.sinitto.sinitto") public class SinittoControllerAdvice { - @ExceptionHandler(SinittoNotFoundException.class) - public ResponseEntity handleSinittoNotFoundException(SinittoNotFoundException e) { + @ExceptionHandler(SinittoBankInfoNotFoundException.class) + public ResponseEntity handleSinittoNotFoundException(SinittoBankInfoNotFoundException e) { ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage()); problemDetail.setType(URI.create("/error/sinitto-not-found")); - problemDetail.setTitle("Sinitto Not Found"); + problemDetail.setTitle("SinittoBankInfo Not Found"); return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetail); } diff --git a/src/main/java/com/example/sinitto/member/entity/Sinitto.java b/src/main/java/com/example/sinitto/sinitto/entity/SinittoBankInfo.java similarity index 80% rename from src/main/java/com/example/sinitto/member/entity/Sinitto.java rename to src/main/java/com/example/sinitto/sinitto/entity/SinittoBankInfo.java index 50e47950..71ceaf2a 100644 --- a/src/main/java/com/example/sinitto/member/entity/Sinitto.java +++ b/src/main/java/com/example/sinitto/sinitto/entity/SinittoBankInfo.java @@ -1,12 +1,13 @@ -package com.example.sinitto.member.entity; +package com.example.sinitto.sinitto.entity; +import com.example.sinitto.member.entity.Member; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @Entity -public class Sinitto { +public class SinittoBankInfo { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -21,10 +22,10 @@ public class Sinitto { @OnDelete(action = OnDeleteAction.CASCADE) private Member member; - public Sinitto() { + protected SinittoBankInfo() { } - public Sinitto(String bankName, String accountNumber, Member member) { + public SinittoBankInfo(String bankName, String accountNumber, Member member) { this.bankName = bankName; this.accountNumber = accountNumber; this.member = member; diff --git a/src/main/java/com/example/sinitto/sinitto/exception/SinittoBankInfoNotFoundException.java b/src/main/java/com/example/sinitto/sinitto/exception/SinittoBankInfoNotFoundException.java new file mode 100644 index 00000000..b7be2b58 --- /dev/null +++ b/src/main/java/com/example/sinitto/sinitto/exception/SinittoBankInfoNotFoundException.java @@ -0,0 +1,7 @@ +package com.example.sinitto.sinitto.exception; + +public class SinittoBankInfoNotFoundException extends RuntimeException { + public SinittoBankInfoNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/com/example/sinitto/sinitto/exception/SinittoNotFoundException.java b/src/main/java/com/example/sinitto/sinitto/exception/SinittoNotFoundException.java deleted file mode 100644 index 50923b49..00000000 --- a/src/main/java/com/example/sinitto/sinitto/exception/SinittoNotFoundException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.sinitto.sinitto.exception; - -public class SinittoNotFoundException extends RuntimeException { - public SinittoNotFoundException(String message) { - super(message); - } -} diff --git a/src/main/java/com/example/sinitto/sinitto/repository/SinittoRepository.java b/src/main/java/com/example/sinitto/sinitto/repository/SinittoBankInfoRepository.java similarity index 54% rename from src/main/java/com/example/sinitto/sinitto/repository/SinittoRepository.java rename to src/main/java/com/example/sinitto/sinitto/repository/SinittoBankInfoRepository.java index 1c211fcd..2068c443 100644 --- a/src/main/java/com/example/sinitto/sinitto/repository/SinittoRepository.java +++ b/src/main/java/com/example/sinitto/sinitto/repository/SinittoBankInfoRepository.java @@ -1,6 +1,6 @@ package com.example.sinitto.sinitto.repository; -import com.example.sinitto.member.entity.Sinitto; +import com.example.sinitto.sinitto.entity.SinittoBankInfo; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -8,8 +8,8 @@ @Repository -public interface SinittoRepository extends JpaRepository { - Optional findByMemberId(Long memberId); +public interface SinittoBankInfoRepository extends JpaRepository { + Optional findByMemberId(Long memberId); boolean existsByMemberId(Long memberId); diff --git a/src/main/java/com/example/sinitto/sinitto/service/SinittoService.java b/src/main/java/com/example/sinitto/sinitto/service/SinittoService.java index c423177f..76d48698 100644 --- a/src/main/java/com/example/sinitto/sinitto/service/SinittoService.java +++ b/src/main/java/com/example/sinitto/sinitto/service/SinittoService.java @@ -1,14 +1,14 @@ package com.example.sinitto.sinitto.service; import com.example.sinitto.member.entity.Member; -import com.example.sinitto.member.entity.Sinitto; import com.example.sinitto.member.exception.MemberNotFoundException; import com.example.sinitto.member.repository.MemberRepository; import com.example.sinitto.sinitto.dto.SinittoBankRequest; import com.example.sinitto.sinitto.dto.SinittoRequest; import com.example.sinitto.sinitto.dto.SinittoResponse; -import com.example.sinitto.sinitto.exception.SinittoNotFoundException; -import com.example.sinitto.sinitto.repository.SinittoRepository; +import com.example.sinitto.sinitto.entity.SinittoBankInfo; +import com.example.sinitto.sinitto.exception.SinittoBankInfoNotFoundException; +import com.example.sinitto.sinitto.repository.SinittoBankInfoRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,11 +18,11 @@ public class SinittoService { private final MemberRepository memberRepository; - private final SinittoRepository sinittoRepository; + private final SinittoBankInfoRepository sinittoBankInfoRepository; - public SinittoService(MemberRepository memberRepository, SinittoRepository sinittoRepository) { + public SinittoService(MemberRepository memberRepository, SinittoBankInfoRepository sinittoBankInfoRepository) { this.memberRepository = memberRepository; - this.sinittoRepository = sinittoRepository; + this.sinittoBankInfoRepository = sinittoBankInfoRepository; } @@ -31,8 +31,8 @@ public void createSinittoBankInfo(Long memberId, SinittoBankRequest sinittoBankR Member member = memberRepository.findById(memberId).orElseThrow( () -> new MemberNotFoundException("이메일에 해당하는 멤버를 찾을 수 없습니다.") ); - Sinitto sinitto = new Sinitto(sinittoBankRequest.bankName(), sinittoBankRequest.accountNumber(), member); - sinittoRepository.save(sinitto); + SinittoBankInfo sinittoBankInfo = new SinittoBankInfo(sinittoBankRequest.bankName(), sinittoBankRequest.accountNumber(), member); + sinittoBankInfoRepository.save(sinittoBankInfo); } @Transactional(readOnly = true) @@ -40,10 +40,10 @@ public SinittoResponse readSinitto(Long memberId) { Member member = memberRepository.findById(memberId).orElseThrow( () -> new MemberNotFoundException("이메일에 해당하는 멤버를 찾을 수 없습니다.") ); - Sinitto sinitto = sinittoRepository.findByMemberId(memberId).orElseThrow( - () -> new SinittoNotFoundException("이메일에 해당하는 멤버의 계좌정보를 찾을 수 없습니다.") + SinittoBankInfo sinittoBankInfo = sinittoBankInfoRepository.findByMemberId(memberId).orElseThrow( + () -> new SinittoBankInfoNotFoundException("이메일에 해당하는 멤버의 계좌정보를 찾을 수 없습니다.") ); - return new SinittoResponse(member.getName(), member.getPhoneNumber(), member.getEmail(), sinitto.getAccountNumber(), sinitto.getBankName()); + return new SinittoResponse(member.getName(), member.getPhoneNumber(), member.getEmail(), sinittoBankInfo.getAccountNumber(), sinittoBankInfo.getBankName()); } @Transactional @@ -56,10 +56,10 @@ public void updateSinitto(Long memberId, SinittoRequest sinittoRequest) { @Transactional public void updateSinittoBankInfo(Long memberId, SinittoBankRequest sinittoBankRequest) { - Sinitto sinitto = sinittoRepository.findByMemberId(memberId).orElseThrow( - () -> new SinittoNotFoundException("이메일에 해당하는 멤버의 계좌정보를 찾을 수 없습니다.") + SinittoBankInfo sinittoBankInfo = sinittoBankInfoRepository.findByMemberId(memberId).orElseThrow( + () -> new SinittoBankInfoNotFoundException("이메일에 해당하는 멤버의 계좌정보를 찾을 수 없습니다.") ); - sinitto.updateSinitto(sinittoBankRequest.bankName(), sinittoBankRequest.accountNumber()); + sinittoBankInfo.updateSinitto(sinittoBankRequest.bankName(), sinittoBankRequest.accountNumber()); } @Transactional @@ -72,17 +72,17 @@ public void deleteSinitto(Long memberId) { @Transactional public void deleteSinittoBankInfo(Long memberId) { - Sinitto sinitto = sinittoRepository.findByMemberId(memberId).orElseThrow( - () -> new SinittoNotFoundException("이메일에 해당하는 멤버의 계좌정보를 찾을 수 없습니다.") + SinittoBankInfo sinittoBankInfo = sinittoBankInfoRepository.findByMemberId(memberId).orElseThrow( + () -> new SinittoBankInfoNotFoundException("이메일에 해당하는 멤버의 계좌정보를 찾을 수 없습니다.") ); - sinittoRepository.delete(sinitto); + sinittoBankInfoRepository.delete(sinittoBankInfo); } @Transactional public List readAllSinitto() { - List sinittos = sinittoRepository.findAll(); + List sinittoBankInfos = sinittoBankInfoRepository.findAll(); - return sinittos.stream() + return sinittoBankInfos.stream() .map(m -> new SinittoResponse(m.getMember().getName(), m.getMember().getPhoneNumber(), m.getMember().getEmail(), m.getAccountNumber(), m.getBankName())) .toList(); } diff --git a/src/test/java/com/example/sinitto/hellocall/entity/HelloCallTimeLogTest.java b/src/test/java/com/example/sinitto/hellocall/entity/HelloCallTimeLogTest.java index ebbfa9f4..1a2024c7 100644 --- a/src/test/java/com/example/sinitto/hellocall/entity/HelloCallTimeLogTest.java +++ b/src/test/java/com/example/sinitto/hellocall/entity/HelloCallTimeLogTest.java @@ -3,7 +3,6 @@ import com.example.sinitto.helloCall.entity.HelloCall; import com.example.sinitto.helloCall.entity.HelloCallTimeLog; import com.example.sinitto.member.entity.Member; -import com.example.sinitto.member.entity.Sinitto; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -15,16 +14,15 @@ class HelloCallTimeLogTest { private HelloCall helloCall; - private Sinitto sinitto; + private Member member; private HelloCallTimeLog helloCallTimeLog; @BeforeEach void setup() { helloCall = new HelloCall(LocalDateTime.now().toLocalDate(), LocalDateTime.now().toLocalDate(), 10000, 30, "Test Requirement", null); - Member member = new Member("Sinitto Test", "01012345678", "sinitto@test.com", true); - sinitto = new Sinitto("테스트은행", "1111222233334444", member); + member = new Member("SinittoBankInfo Test", "01012345678", "sinittoBankInfo@test.com", true); - helloCallTimeLog = new HelloCallTimeLog(helloCall, sinitto); + helloCallTimeLog = new HelloCallTimeLog(helloCall, member); } @Test @@ -32,7 +30,7 @@ void setup() { void constructorTest() { assertThat(helloCallTimeLog).isNotNull(); assertThat(helloCallTimeLog.getHelloCall()).isEqualTo(helloCall); - assertThat(helloCallTimeLog.getSinitto()).isEqualTo(sinitto); + assertThat(helloCallTimeLog.getSinitto()).isEqualTo(member); } @Test @@ -49,9 +47,9 @@ void setStartAndEndDateTimeTest() { } @Test - @DisplayName("Sinitto 이름 가져오기 테스트") + @DisplayName("member 이름 가져오기 테스트") void getSinittoNameTest() { - String expectedName = sinitto.getMember().getName(); + String expectedName = member.getName(); assertThat(helloCallTimeLog.getSinittoName()).isEqualTo(expectedName); } } diff --git a/src/test/java/com/example/sinitto/hellocall/repository/HelloCallRepositoryTest.java b/src/test/java/com/example/sinitto/hellocall/repository/HelloCallRepositoryTest.java index 8fc626a2..9beac7d4 100644 --- a/src/test/java/com/example/sinitto/hellocall/repository/HelloCallRepositoryTest.java +++ b/src/test/java/com/example/sinitto/hellocall/repository/HelloCallRepositoryTest.java @@ -5,9 +5,9 @@ import com.example.sinitto.helloCall.repository.HelloCallRepository; import com.example.sinitto.member.entity.Member; import com.example.sinitto.member.entity.Senior; -import com.example.sinitto.member.entity.Sinitto; import com.example.sinitto.member.repository.MemberRepository; -import com.example.sinitto.sinitto.repository.SinittoRepository; +import com.example.sinitto.sinitto.entity.SinittoBankInfo; +import com.example.sinitto.sinitto.repository.SinittoBankInfoRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -33,13 +33,13 @@ class HelloCallRepositoryTest { private MemberRepository memberRepository; @Autowired - private SinittoRepository sinittoRepository; + private SinittoBankInfoRepository sinittoBankInfoRepository; private Member sinittoMember1; private Member sinittoMember2; private Member seniorMember; - private Sinitto sinitto1; - private Sinitto sinitto2; + private SinittoBankInfo sinittoBankInfo1; + private SinittoBankInfo sinittoBankInfo2; private Senior senior; @BeforeEach @@ -47,14 +47,14 @@ void setUp() { sinittoMember1 = new Member("test1", "01011111111", "test1@test.com", true); memberRepository.save(sinittoMember1); - sinitto1 = new Sinitto("sinittoBank1", "BankAccount1", sinittoMember1); - sinittoRepository.save(sinitto1); + sinittoBankInfo1 = new SinittoBankInfo("sinittoBank1", "BankAccount1", sinittoMember1); + sinittoBankInfoRepository.save(sinittoBankInfo1); sinittoMember2 = new Member("test2", "01022222222", "test2@test.com", true); memberRepository.save(sinittoMember2); - sinitto2 = new Sinitto("SinittoBank2", "BankAccount2", sinittoMember2); - sinittoRepository.save(sinitto2); + sinittoBankInfo2 = new SinittoBankInfo("SinittoBank2", "BankAccount2", sinittoMember2); + sinittoBankInfoRepository.save(sinittoBankInfo2); seniorMember = new Member("test3", "01033333333", "test3@test.com", false); memberRepository.save(seniorMember); @@ -78,8 +78,8 @@ void findBySeniorTest() { } @Test - @DisplayName("Sinitto 기반으로 HelloCall 리스트 찾기 테스트") - void findAllBySinittoTest() { + @DisplayName("member 기반으로 HelloCall 리스트 찾기 테스트") + void findAllByMemberTest() { Senior senior1 = new Senior("Senior1", "01012345678", sinittoMember2); seniorRepository.save(senior1); Senior senior2 = new Senior("Senior2", "01098765432", sinittoMember2); @@ -92,17 +92,17 @@ void findAllBySinittoTest() { LocalDate.of(2024, 1, 4), 15000, 90, "요구사항2", senior2); - helloCall1.setSinitto(sinitto1); - helloCall2.setSinitto(sinitto1); + helloCall1.setMember(sinittoMember1); + helloCall2.setMember(sinittoMember1); helloCallRepository.save(helloCall1); helloCallRepository.save(helloCall2); - List helloCalls = helloCallRepository.findAllBySinitto(sinitto1); + List helloCalls = helloCallRepository.findAllByMember(sinittoMember1); assertThat(helloCalls).hasSize(2); - assertThat(helloCalls.get(0).getSinitto()).isEqualTo(sinitto1); - assertThat(helloCalls.get(1).getSinitto()).isEqualTo(sinitto1); + assertThat(helloCalls.get(0).getMember()).isEqualTo(sinittoMember1); + assertThat(helloCalls.get(1).getMember()).isEqualTo(sinittoMember1); } @Test @@ -136,19 +136,19 @@ void testChangeSinittoInHelloCall() { LocalDate.of(2024, 1, 2), 10000, 60, "요구사항", senior); - helloCall.setSinitto(sinitto1); + helloCall.setMember(sinittoMember1); helloCallRepository.save(helloCall); Optional savedHelloCall = helloCallRepository.findById(helloCall.getId()); assertThat(savedHelloCall).isPresent(); - assertThat(savedHelloCall.get().getSinitto()).isEqualTo(sinitto1); + assertThat(savedHelloCall.get().getMember()).isEqualTo(sinittoMember1); - savedHelloCall.get().setSinitto(sinitto2); + savedHelloCall.get().setMember(sinittoMember2); helloCallRepository.save(savedHelloCall.get()); Optional updatedHelloCall = helloCallRepository.findById(helloCall.getId()); assertThat(updatedHelloCall).isPresent(); - assertThat(updatedHelloCall.get().getSinitto()).isEqualTo(sinitto2); + assertThat(updatedHelloCall.get().getMember()).isEqualTo(sinittoMember2); } @Test diff --git a/src/test/java/com/example/sinitto/hellocall/repository/HelloCallTimeLogRepositoryTest.java b/src/test/java/com/example/sinitto/hellocall/repository/HelloCallTimeLogRepositoryTest.java index 743449cd..5f01be82 100644 --- a/src/test/java/com/example/sinitto/hellocall/repository/HelloCallTimeLogRepositoryTest.java +++ b/src/test/java/com/example/sinitto/hellocall/repository/HelloCallTimeLogRepositoryTest.java @@ -7,9 +7,9 @@ import com.example.sinitto.helloCall.repository.HelloCallTimeLogRepository; import com.example.sinitto.member.entity.Member; import com.example.sinitto.member.entity.Senior; -import com.example.sinitto.member.entity.Sinitto; import com.example.sinitto.member.repository.MemberRepository; -import com.example.sinitto.sinitto.repository.SinittoRepository; +import com.example.sinitto.sinitto.entity.SinittoBankInfo; +import com.example.sinitto.sinitto.repository.SinittoBankInfoRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -33,7 +33,7 @@ class HelloCallTimeLogRepositoryTest { private HelloCallRepository helloCallRepository; @Autowired - private SinittoRepository sinittoRepository; + private SinittoBankInfoRepository sinittoBankInfoRepository; @Autowired private SeniorRepository seniorRepository; @@ -43,17 +43,17 @@ class HelloCallTimeLogRepositoryTest { private Member sinittoMember; private Member seniorMember; - private Sinitto sinitto; + private SinittoBankInfo sinittoBankInfo; private Senior senior; private HelloCall helloCall; @BeforeEach void setUp() { - sinittoMember = new Member("testSinitto", "01011112222", "sinitto@test.com", true); + sinittoMember = new Member("testSinitto", "01011112222", "sinittoBankInfo@test.com", true); memberRepository.save(sinittoMember); - sinitto = new Sinitto("sinittoBank", "sinittoAccount", sinittoMember); - sinittoRepository.save(sinitto); + sinittoBankInfo = new SinittoBankInfo("sinittoBank", "sinittoAccount", sinittoMember); + sinittoBankInfoRepository.save(sinittoBankInfo); seniorMember = new Member("testSenior", "01033334444", "senior@test.com", false); memberRepository.save(seniorMember); @@ -66,16 +66,16 @@ void setUp() { } @Test - @DisplayName("로그 저장 및 Sinitto와 HelloCall ID 기반으로 특정 HelloCallTimeLog 찾기 테스트") + @DisplayName("로그 저장 및 member와 HelloCall ID 기반으로 특정 HelloCallTimeLog 찾기 테스트") void findBySinittoAndHelloCallIdTest() { - HelloCallTimeLog timeLog = new HelloCallTimeLog(helloCall, sinitto, LocalDateTime.of(2024, 1, 1, 10, 0), LocalDateTime.of(2024, 1, 1, 11, 0)); + HelloCallTimeLog timeLog = new HelloCallTimeLog(helloCall, sinittoMember, LocalDateTime.of(2024, 1, 1, 10, 0), LocalDateTime.of(2024, 1, 1, 11, 0)); helloCallTimeLogRepository.save(timeLog); - Optional foundTimeLog = helloCallTimeLogRepository.findBySinittoAndHelloCallId(sinitto, helloCall.getId()); + Optional foundTimeLog = helloCallTimeLogRepository.findByMemberAndHelloCallId(sinittoMember, helloCall.getId()); assertThat(foundTimeLog).isPresent(); assertThat(foundTimeLog.get().getHelloCall()).isEqualTo(helloCall); - assertThat(foundTimeLog.get().getSinitto()).isEqualTo(sinitto); + assertThat(foundTimeLog.get().getSinitto()).isEqualTo(sinittoMember); assertThat(foundTimeLog.get().getStartDateAndTime()).isEqualTo(LocalDateTime.of(2024, 1, 1, 10, 0)); assertThat(foundTimeLog.get().getEndDateAndTime()).isEqualTo(LocalDateTime.of(2024, 1, 1, 11, 0)); } @@ -83,8 +83,8 @@ void findBySinittoAndHelloCallIdTest() { @Test @DisplayName("HelloCall ID 기반으로 모든 HelloCallTimeLog 리스트 찾기 테스트") void findAllByHelloCallIdTest() { - HelloCallTimeLog timeLog1 = new HelloCallTimeLog(helloCall, sinitto, LocalDateTime.of(2024, 1, 1, 10, 0), LocalDateTime.of(2024, 1, 1, 11, 0)); - HelloCallTimeLog timeLog2 = new HelloCallTimeLog(helloCall, sinitto, LocalDateTime.of(2024, 1, 1, 12, 0), LocalDateTime.of(2024, 1, 1, 13, 0)); + HelloCallTimeLog timeLog1 = new HelloCallTimeLog(helloCall, sinittoMember, LocalDateTime.of(2024, 1, 1, 10, 0), LocalDateTime.of(2024, 1, 1, 11, 0)); + HelloCallTimeLog timeLog2 = new HelloCallTimeLog(helloCall, sinittoMember, LocalDateTime.of(2024, 1, 1, 12, 0), LocalDateTime.of(2024, 1, 1, 13, 0)); helloCallTimeLogRepository.save(timeLog1); helloCallTimeLogRepository.save(timeLog2); @@ -99,20 +99,20 @@ void findAllByHelloCallIdTest() { } @Test - @DisplayName("Sinitto와 HelloCall 기반으로 가장 최근의 HelloCallTimeLog 찾기 테스트") + @DisplayName("Member와 HelloCall 기반으로 가장 최근의 HelloCallTimeLog 찾기 테스트") void findTopBySinittoAndHelloCallOrderByStartDateAndTimeDescTest() { - HelloCallTimeLog timeLog1 = new HelloCallTimeLog(helloCall, sinitto, LocalDateTime.of(2024, 1, 1, 10, 0), LocalDateTime.of(2024, 1, 1, 11, 0)); - HelloCallTimeLog timeLog2 = new HelloCallTimeLog(helloCall, sinitto, LocalDateTime.of(2024, 1, 1, 12, 0), LocalDateTime.of(2024, 1, 1, 13, 0)); + HelloCallTimeLog timeLog1 = new HelloCallTimeLog(helloCall, sinittoMember, LocalDateTime.of(2024, 1, 1, 10, 0), LocalDateTime.of(2024, 1, 1, 11, 0)); + HelloCallTimeLog timeLog2 = new HelloCallTimeLog(helloCall, sinittoMember, LocalDateTime.of(2024, 1, 1, 12, 0), LocalDateTime.of(2024, 1, 1, 13, 0)); helloCallTimeLogRepository.save(timeLog1); helloCallTimeLogRepository.save(timeLog2); Optional recentTimeLog = helloCallTimeLogRepository - .findTopBySinittoAndHelloCallOrderByStartDateAndTimeDesc(sinitto, helloCall); + .findTopByMemberAndHelloCallOrderByStartDateAndTimeDesc(sinittoMember, helloCall); assertThat(recentTimeLog).isPresent(); assertThat(recentTimeLog.get().getHelloCall()).isEqualTo(helloCall); - assertThat(recentTimeLog.get().getSinitto()).isEqualTo(sinitto); + assertThat(recentTimeLog.get().getSinitto()).isEqualTo(sinittoMember); assertThat(recentTimeLog.get().getStartDateAndTime()).isEqualTo(LocalDateTime.of(2024, 1, 1, 12, 0)); assertThat(recentTimeLog.get().getEndDateAndTime()).isEqualTo(LocalDateTime.of(2024, 1, 1, 13, 0)); } diff --git a/src/test/java/com/example/sinitto/member/entity/MemberTest.java b/src/test/java/com/example/sinitto/member/entity/MemberTest.java index b0894f60..8147fc39 100644 --- a/src/test/java/com/example/sinitto/member/entity/MemberTest.java +++ b/src/test/java/com/example/sinitto/member/entity/MemberTest.java @@ -31,7 +31,7 @@ void constructorTest() { } @Test - @DisplayName("Member Sinitto 여부 확인 테스트") + @DisplayName("Member SinittoBankInfo 여부 확인 테스트") void isSinittoTest() { assertThat(member.isSinitto()).isTrue(); diff --git a/src/test/java/com/example/sinitto/sinitto/entity/SinittoBankInfoTest.java b/src/test/java/com/example/sinitto/sinitto/entity/SinittoBankInfoTest.java new file mode 100644 index 00000000..e433e2ec --- /dev/null +++ b/src/test/java/com/example/sinitto/sinitto/entity/SinittoBankInfoTest.java @@ -0,0 +1,42 @@ +package com.example.sinitto.sinitto.entity; + +import com.example.sinitto.member.entity.Member; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class SinittoBankInfoTest { + + private SinittoBankInfo sinittoBankInfo; + private Member member; + + @BeforeEach + void setUp() { + member = new Member("John Doe", "123-4567", "johndoe@example.com", true); + sinittoBankInfo = new SinittoBankInfo("Bank A", "987654321", member); + } + + @Test + @DisplayName("SinittoBankInfo 생성자 테스트") + void testCreateSinittoBankInfo() { + SinittoBankInfo savedSinittoBankInfo = new SinittoBankInfo("new bank", "111-1111-1111", member); + + assertNotNull(savedSinittoBankInfo); + assertEquals("new bank", savedSinittoBankInfo.getBankName()); + assertEquals("111-1111-1111", savedSinittoBankInfo.getAccountNumber()); + assertEquals(member, savedSinittoBankInfo.getMember()); + } + + @Test + @DisplayName("SinittoBankInfo 업데이트 테스트") + void testUpdateSinittoBankInfo() { + sinittoBankInfo.updateSinitto("Bank B", "123456789"); + + assertNotNull(sinittoBankInfo); + assertEquals("Bank B", sinittoBankInfo.getBankName()); + assertEquals("123456789", sinittoBankInfo.getAccountNumber()); + } +} diff --git a/src/test/java/com/example/sinitto/sinitto/entity/SinittoTest.java b/src/test/java/com/example/sinitto/sinitto/entity/SinittoTest.java deleted file mode 100644 index 477dc24a..00000000 --- a/src/test/java/com/example/sinitto/sinitto/entity/SinittoTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.example.sinitto.sinitto.entity; - -import com.example.sinitto.member.entity.Member; -import com.example.sinitto.member.entity.Sinitto; -import com.example.sinitto.sinitto.repository.SinittoRepository; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@DataJpaTest -class SinittoTest { - - @Mock - private SinittoRepository sinittoRepository; - - private Sinitto sinitto; - private Member member; - - @BeforeEach - void setUp() { - MockitoAnnotations.openMocks(this); - member = new Member("John Doe", "123-4567", "johndoe@example.com", true); - sinitto = new Sinitto("Bank A", "987654321", member); - } - - @Test - void testCreateSinitto() { - when(sinittoRepository.save(sinitto)).thenReturn(sinitto); - - Sinitto savedSinitto = sinittoRepository.save(sinitto); - - assertNotNull(savedSinitto); - assertEquals("Bank A", savedSinitto.getBankName()); - assertEquals("987654321", savedSinitto.getAccountNumber()); - assertEquals(member, savedSinitto.getMember()); - - verify(sinittoRepository, times(1)).save(sinitto); - } - - @Test - void testUpdateSinitto() { - sinitto.updateSinitto("Bank B", "123456789"); - - when(sinittoRepository.save(sinitto)).thenReturn(sinitto); - - Sinitto updatedSinitto = sinittoRepository.save(sinitto); - - assertNotNull(updatedSinitto); - assertEquals("Bank B", updatedSinitto.getBankName()); - assertEquals("123456789", updatedSinitto.getAccountNumber()); - - verify(sinittoRepository, times(1)).save(sinitto); - } - - @Test - void testFindSinittoById() { - when(sinittoRepository.findById(1L)).thenReturn(Optional.of(sinitto)); - - Optional foundSinitto = sinittoRepository.findById(1L); - - assertTrue(foundSinitto.isPresent()); - assertEquals(sinitto.getId(), foundSinitto.get().getId()); - } - - @Test - void testDeleteSinitto() { - sinittoRepository.delete(sinitto); - verify(sinittoRepository, times(1)).delete(sinitto); - } -} diff --git a/src/test/java/com/example/sinitto/sinitto/repository/SinittoBankInfoRepositoryTest.java b/src/test/java/com/example/sinitto/sinitto/repository/SinittoBankInfoRepositoryTest.java new file mode 100644 index 00000000..58202c89 --- /dev/null +++ b/src/test/java/com/example/sinitto/sinitto/repository/SinittoBankInfoRepositoryTest.java @@ -0,0 +1,75 @@ +package com.example.sinitto.sinitto.repository; + +import com.example.sinitto.member.entity.Member; +import com.example.sinitto.member.repository.MemberRepository; +import com.example.sinitto.sinitto.entity.SinittoBankInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@DataJpaTest +class SinittoBankInfoRepositoryTest { + + @Autowired + private SinittoBankInfoRepository sinittoBankInfoRepository; + + @Autowired + private MemberRepository memberRepository; + + private Member member; + private SinittoBankInfo sinittoBankInfo; + + @BeforeEach + void setUp() { + member = new Member("John Doe", "123-4567", "johndoe@example.com", true); + memberRepository.save(member); + + sinittoBankInfo = new SinittoBankInfo("Bank A", "987654321", member); + sinittoBankInfoRepository.save(sinittoBankInfo); + } + + @Test + @DisplayName("멤버 아이디 기반 시니또 은행 정보 불러오기 테스트") + void testFindByMemberId() { + Optional foundSinitto = sinittoBankInfoRepository.findByMemberId(member.getId()); + assertTrue(foundSinitto.isPresent()); + assertEquals(sinittoBankInfo.getBankName(), foundSinitto.get().getBankName()); + } + + @Test + @DisplayName("시니또 은행 정보 저장 테스트") + void testSaveSinittoBankInfo() { + Member newMember = new Member("new Jane Doe", "111-1111", "newjanedoe@example.com", true); + memberRepository.save(newMember); + + SinittoBankInfo newSinittoBankInfo = new SinittoBankInfo("Bank B", "123456789", newMember); + SinittoBankInfo savedSinittoBankInfo = sinittoBankInfoRepository.save(newSinittoBankInfo); + + assertNotNull(savedSinittoBankInfo); + assertEquals("Bank B", savedSinittoBankInfo.getBankName()); + } + + @Test + @DisplayName("시니또 은행 정보 삭제 테스트") + void testDeleteSinittoBankInfo() { + sinittoBankInfoRepository.delete(sinittoBankInfo); + Optional deletedSinitto = sinittoBankInfoRepository.findById(sinittoBankInfo.getId()); + assertFalse(deletedSinitto.isPresent()); + } + + @Test + @DisplayName("멤버 아이디 기반 존재여부 검증 테스트") + void testExistByMemberId() { + boolean check1 = sinittoBankInfoRepository.existsByMemberId(member.getId()); + assertTrue(check1); + + boolean check2 = sinittoBankInfoRepository.existsByMemberId(2L); + assertFalse(check2); + } +} diff --git a/src/test/java/com/example/sinitto/sinitto/repository/SinittoRepositoryTest.java b/src/test/java/com/example/sinitto/sinitto/repository/SinittoRepositoryTest.java deleted file mode 100644 index d5eae90b..00000000 --- a/src/test/java/com/example/sinitto/sinitto/repository/SinittoRepositoryTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.example.sinitto.sinitto.repository; - -import com.example.sinitto.member.entity.Member; -import com.example.sinitto.member.entity.Sinitto; -import com.example.sinitto.member.repository.MemberRepository; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; - -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -@DataJpaTest -class SinittoRepositoryTest { - - @Autowired - private SinittoRepository sinittoRepository; - - @Autowired - private MemberRepository memberRepository; - - private Member member; - private Sinitto sinitto; - - @BeforeEach - void setUp() { - member = new Member("John Doe", "123-4567", "johndoe@example.com", true); - memberRepository.save(member); - - sinitto = new Sinitto("Bank A", "987654321", member); - sinittoRepository.save(sinitto); - } - - @Test - void testFindByMemberId() { - Optional foundSinitto = sinittoRepository.findByMemberId(member.getId()); - assertTrue(foundSinitto.isPresent()); - assertEquals(sinitto.getBankName(), foundSinitto.get().getBankName()); - } - - @Test - void testSaveSinitto() { - Member newMember = new Member("Jane Doe", "987-6543", "janedoe@example.com", true); - memberRepository.save(newMember); - - Sinitto newSinitto = new Sinitto("Bank B", "123456789", newMember); - Sinitto savedSinitto = sinittoRepository.save(newSinitto); - assertNotNull(savedSinitto); - assertEquals("Bank B", savedSinitto.getBankName()); - } - - - @Test - void testDeleteSinitto() { - sinittoRepository.delete(sinitto); - Optional deletedSinitto = sinittoRepository.findById(sinitto.getId()); - assertFalse(deletedSinitto.isPresent()); - } -}