Skip to content

Commit

Permalink
Feat: 콜백 단건조회 api 응답값에 boolean isAssignedToSelf, String seniorPhoneNu…
Browse files Browse the repository at this point in the history
…mber 추가 (#104)

* feat: 콜백 단건 조회 응답 요소 추가

* refactor: 더 명확한 메서드 명으로 수정 getCallback->getCallbackForSinitto

* test: 시니또용 콜백 단건 조회 테스트 작성

* chore: 프론트 테스트를 더 명확히하기위해 콜백 더미 데이터에 할당된 시니어 추가

* refactor: 본인에게 할당된 콜백이 아닌것에대한 콜백 상세조회 할때는 시니어 번호 없도록 수정

* test: 테스트 통과하도록 수정

* chore: 더미데이터 개선
  • Loading branch information
zzoe2346 authored Oct 26, 2024
1 parent dd93a62 commit 08bf252
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -89,11 +90,12 @@ public ResponseEntity<Page<CallbackUsageHistoryResponse>> getAcceptedCallback(@M
return ResponseEntity.ok(callbackService.getCallbackHistoryOfGuard(memberId, pageable));
}

@Operation(summary = "콜백 단건 조회", description = "콜백 id 로 콜백을 단건 조회합니다.")
@Operation(summary = "콜백 단건 조회 (시니또용)", description = "콜백 id 로 콜백을 단건 조회합니다.")
@GetMapping("/{callbackId}")
public ResponseEntity<CallbackResponse> getCallback(@PathVariable("callbackId") Long callbackId) {
public ResponseEntity<CallbackForSinittoResponse> getCallback(@MemberId Long memberId,
@PathVariable("callbackId") Long callbackId) {

return ResponseEntity.ok(callbackService.getCallback(callbackId));
return ResponseEntity.ok(callbackService.getCallbackForSinitto(memberId, callbackId));
}

}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -228,12 +229,16 @@ public Page<CallbackUsageHistoryResponse> 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, "");
}

}
15 changes: 12 additions & 3 deletions src/main/java/com/example/sinitto/common/dummy/InitialData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +72,7 @@ public InitialData(MemberRepository memberRepository, SeniorRepository seniorRep
}

@Override
@Transactional
public void run(String... args) {
initial();
saveRefreshTokenToRedis();
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 08bf252

Please sign in to comment.