diff --git a/src/main/java/com/example/sinitto/callback/controller/CallbackController.java b/src/main/java/com/example/sinitto/callback/controller/CallbackController.java index 13dc1ab5..5472dabe 100644 --- a/src/main/java/com/example/sinitto/callback/controller/CallbackController.java +++ b/src/main/java/com/example/sinitto/callback/controller/CallbackController.java @@ -1,5 +1,6 @@ package com.example.sinitto.callback.controller; +import com.example.sinitto.callback.dto.CallbackForSinittoResponse; import com.example.sinitto.callback.dto.CallbackResponse; import com.example.sinitto.callback.dto.CallbackUsageHistoryResponse; import com.example.sinitto.callback.service.CallbackService; @@ -89,11 +90,12 @@ public ResponseEntity> getAcceptedCallback(@M return ResponseEntity.ok(callbackService.getCallbackHistoryOfGuard(memberId, pageable)); } - @Operation(summary = "콜백 단건 조회", description = "콜백 id 로 콜백을 단건 조회합니다.") + @Operation(summary = "콜백 단건 조회 (시니또용)", description = "콜백 id 로 콜백을 단건 조회합니다.") @GetMapping("/{callbackId}") - public ResponseEntity getCallback(@PathVariable("callbackId") Long callbackId) { + public ResponseEntity getCallback(@MemberId Long memberId, + @PathVariable("callbackId") Long callbackId) { - return ResponseEntity.ok(callbackService.getCallback(callbackId)); + return ResponseEntity.ok(callbackService.getCallbackForSinitto(memberId, callbackId)); } } diff --git a/src/main/java/com/example/sinitto/callback/dto/CallbackForSinittoResponse.java b/src/main/java/com/example/sinitto/callback/dto/CallbackForSinittoResponse.java new file mode 100644 index 00000000..76600943 --- /dev/null +++ b/src/main/java/com/example/sinitto/callback/dto/CallbackForSinittoResponse.java @@ -0,0 +1,14 @@ +package com.example.sinitto.callback.dto; + +import java.time.LocalDateTime; + +public record CallbackForSinittoResponse( + Long callbackId, + String seniorName, + LocalDateTime postTime, + String status, + Long seniorId, + boolean isAssignedToSelf, + String seniorPhoneNumber +) { +} \ No newline at end of file diff --git a/src/main/java/com/example/sinitto/callback/service/CallbackService.java b/src/main/java/com/example/sinitto/callback/service/CallbackService.java index c43ace73..6fcb06da 100644 --- a/src/main/java/com/example/sinitto/callback/service/CallbackService.java +++ b/src/main/java/com/example/sinitto/callback/service/CallbackService.java @@ -1,5 +1,6 @@ package com.example.sinitto.callback.service; +import com.example.sinitto.callback.dto.CallbackForSinittoResponse; import com.example.sinitto.callback.dto.CallbackResponse; import com.example.sinitto.callback.dto.CallbackUsageHistoryResponse; import com.example.sinitto.callback.entity.Callback; @@ -228,12 +229,16 @@ public Page getCallbackHistoryOfGuard(Long memberI .map(callback -> new CallbackUsageHistoryResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus())); } - public CallbackResponse getCallback(Long callbackId) { + public CallbackForSinittoResponse getCallbackForSinitto(Long memberId, Long callbackId) { Callback callback = callbackRepository.findById(callbackId) .orElseThrow(() -> new NotFoundException("해당 콜백 id에 해당하는 콜백이 없습니다.")); - return new CallbackResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus(), callback.getSeniorId()); + if (callback.getAssignedMemberId().equals(memberId)) { + return new CallbackForSinittoResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus(), callback.getSeniorId(), true, callback.getSenior().getPhoneNumber()); + } + + return new CallbackForSinittoResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus(), callback.getSeniorId(), false, ""); } } 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 6f5997ff..4f828723 100644 --- a/src/main/java/com/example/sinitto/common/dummy/InitialData.java +++ b/src/main/java/com/example/sinitto/common/dummy/InitialData.java @@ -26,6 +26,7 @@ import com.example.sinitto.sinitto.repository.SinittoBankInfoRepository; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.LocalDateTime; @@ -71,6 +72,7 @@ public InitialData(MemberRepository memberRepository, SeniorRepository seniorRep } @Override + @Transactional public void run(String... args) { initial(); saveRefreshTokenToRedis(); @@ -298,20 +300,27 @@ private void initial() { //콜백 callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior1)); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior1)); - callbackRepository.save(new Callback(Callback.Status.WAITING, senior1)); + Callback callback1 = callbackRepository.save(new Callback(Callback.Status.WAITING, senior1)); + callback1.assignMember(1L); + callback1.changeStatusToInProgress(); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior2)); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior2)); - callbackRepository.save(new Callback(Callback.Status.WAITING, senior2)); + Callback callback2 = callbackRepository.save(new Callback(Callback.Status.WAITING, senior2)); + callback2.assignMember(2L); + callback2.changeStatusToInProgress(); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior3)); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior3)); - callbackRepository.save(new Callback(Callback.Status.WAITING, senior3)); + Callback callback3 = callbackRepository.save(new Callback(Callback.Status.WAITING, senior3)); + callback3.assignMember(3L); + callback3.changeStatusToInProgress(); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior4)); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior4)); callbackRepository.save(new Callback(Callback.Status.WAITING, senior4)); + callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior5)); callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior5)); callbackRepository.save(new Callback(Callback.Status.WAITING, senior5)); diff --git a/src/test/java/com/example/sinitto/callback/service/CallbackServiceTest.java b/src/test/java/com/example/sinitto/callback/service/CallbackServiceTest.java index 4fdf702b..7641c458 100644 --- a/src/test/java/com/example/sinitto/callback/service/CallbackServiceTest.java +++ b/src/test/java/com/example/sinitto/callback/service/CallbackServiceTest.java @@ -1,5 +1,6 @@ package com.example.sinitto.callback.service; +import com.example.sinitto.callback.dto.CallbackForSinittoResponse; import com.example.sinitto.callback.dto.CallbackResponse; import com.example.sinitto.callback.entity.Callback; import com.example.sinitto.callback.repository.CallbackRepository; @@ -403,4 +404,53 @@ void localDateTimeBeforeCalculateTest() { assertTrue(일월1일13시00분.isBefore(일월3일13시10분.minusDays(2))); assertTrue(일월1일13시01분.isBefore(일월3일13시10분.minusDays(2))); } + + @Test + @DisplayName("시니또용 콜백 단건 조회 - api 호출한 시니또 본인이 할당된 콜백일 경우") + void getCallbackForSinitto() { + //given + Long memberId = 1L; + Long callbackId = 1L; + Callback callback = mock(Callback.class); + Senior senior = mock(Senior.class); + + when(callbackRepository.findById(callbackId)).thenReturn(Optional.of(callback)); + when(callback.getAssignedMemberId()).thenReturn(1L); + when(callback.getId()).thenReturn(1L); + when(callback.getSeniorName()).thenReturn("SeniorName"); + when(callback.getPostTime()).thenReturn(LocalDateTime.now()); + when(callback.getStatus()).thenReturn(Callback.Status.WAITING.toString()); + when(callback.getSeniorId()).thenReturn(1L); + when(callback.getSenior()).thenReturn(senior); + when(callback.getSenior().getPhoneNumber()).thenReturn("01012341234"); + + //when + CallbackForSinittoResponse result = callbackService.getCallbackForSinitto(memberId, callbackId); + + //then + assertTrue(result.isAssignedToSelf()); + } + + @Test + @DisplayName("시니또용 콜백 단건 조회 - api 호출한 시니또 본인이 할당된 콜백이 아닌 경우") + void getCallbackForSinitto2() { + //given + Long memberId = 1L; + Long callbackId = 1L; + Callback callback = mock(Callback.class); + + when(callbackRepository.findById(callbackId)).thenReturn(Optional.of(callback)); + when(callback.getAssignedMemberId()).thenReturn(999L); // 여기서 시니또 본인에게 할당된 콜백이 아닌걸 확인 + when(callback.getId()).thenReturn(1L); + when(callback.getSeniorName()).thenReturn("SeniorName"); + when(callback.getPostTime()).thenReturn(LocalDateTime.now()); + when(callback.getStatus()).thenReturn(Callback.Status.WAITING.toString()); + when(callback.getSeniorId()).thenReturn(1L); + + //when + CallbackForSinittoResponse result = callbackService.getCallbackForSinitto(memberId, callbackId); + + //then + assertFalse(result.isAssignedToSelf()); + } }