Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 콜백 단건조회 api 응답값에 boolean isAssignedToSelf, String seniorPhoneNumber 추가 #104

Merged
merged 8 commits into from
Oct 26, 2024
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());
}
Comment on lines +237 to +239
Copy link
Collaborator

@eunsoni eunsoni Oct 23, 2024

Choose a reason for hiding this comment

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

음 저는 가이드라인 조회에서 사용자 검증할 때, 검증에 실패할 시 예외 처리하고, 성공할 시 response를 보내주는 로직으로 작성해두었는데,
혹시 검증에 실패하더라도 response에 검증여부(false)정보를 담아서 보내야하는 이유가 따로 있을까요?

Copy link
Contributor Author

@zzoe2346 zzoe2346 Oct 24, 2024

Choose a reason for hiding this comment

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

어라 그러네요; 한번 false 어디에 쓰시는지 물어보겠습니다. 생각해보니 검증 로직만 제대로하면 해결이 되는 문제일 수 도 있겠네요.

Copy link
Contributor Author

@zzoe2346 zzoe2346 Oct 24, 2024

Choose a reason for hiding this comment

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

저 페이지가 하나의 페이지로 구현하신거라서 이런 응답이 필요하다고 하시네요! true/false 있으면 기존보다 API 호출을 줄일 수 있어서 시니또가 수락하기 할 때 더 빨리 페이지가 갱신되는 효과가 있을거 같습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

아하 그렇군용!

Copy link
Collaborator

Choose a reason for hiding this comment

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

아래에 조금 더 자세한 설명으로 코멘트 달아놨지만 간단하게 보충하겠습니다!

콜백 상세 조회 페이지가 figma 상으로는 두 페이지(수락 전, 수락 후)지만 실제로는 같은 페이지내에서 현재 시니또가 콜백 요청을 수락했는지 아닌지에 따라 하단메뉴가 달라지는 방식으로 구현됐습니다.
이를 위해서는 현재 조회하고 있는 콜백 요청이 시니또가 수락한 것인지 아닌지에 대한 정보가 필요해 isAssignedToSelf 추가를 요청드렸습니다.

isAssignedToSelf가 false인 경우(현재 시니또가 수락하지 않은 콜백인 경우) 수락 전 페이지가 조회되고, true인 경우(현재 시니또가 수락한 콜백인 경우) 수락 후 페이지가 조회되도록 구현했습니다.


return new CallbackForSinittoResponse(callback.getId(), callback.getSeniorName(), callback.getPostTime(), callback.getStatus(), callback.getSeniorId(), false, "");
Copy link
Contributor Author

@zzoe2346 zzoe2346 Oct 24, 2024

Choose a reason for hiding this comment

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

"" 존재 이유

isAssignedToSelf 가 false인 경우에도 시니어 번호를 전달하는 것을 방지하기 위해서 이렇게 만들어 보았습니다.

시니또 본인에게 할당 콜백 조회의 경우(isAssignedToSelf 가 true인 경우)

SCR-20241025-bong

시니또 본인에게 할당 콜백 아닌 경우(isAssignedToSelf 가 false인 경우)

SCR-20241025-bokn

Copy link
Member

Choose a reason for hiding this comment

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

아~ 이해했습니다!
좋은 것 같네요 ㅎㅎ

Copy link
Collaborator

Choose a reason for hiding this comment

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

오호 좋네요!!

}

}
12 changes: 7 additions & 5 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,23 +300,23 @@ 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));
callbackRepository.save(new Callback(Callback.Status.WAITING, senior1)).assignMember(1L);

callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior2));
callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior2));
callbackRepository.save(new Callback(Callback.Status.WAITING, senior2));
callbackRepository.save(new Callback(Callback.Status.WAITING, senior2)).assignMember(2L);

callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior3));
callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior3));
callbackRepository.save(new Callback(Callback.Status.WAITING, senior3));
callbackRepository.save(new Callback(Callback.Status.WAITING, senior3)).assignMember(3L);

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.WAITING, senior4)).assignMember(4L);

callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior5));
callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior5));
callbackRepository.save(new Callback(Callback.Status.WAITING, senior5));
callbackRepository.save(new Callback(Callback.Status.WAITING, senior5)).assignMember(5L);

callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior6));
callbackRepository.save(new Callback(Callback.Status.COMPLETE, senior6));
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,56 @@ 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);
Senior senior = mock(Senior.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(callback.getSenior()).thenReturn(senior);
when(callback.getSenior().getPhoneNumber()).thenReturn("01012341234");

//when
CallbackForSinittoResponse result = callbackService.getCallbackForSinitto(memberId, callbackId);

//then
assertFalse(result.isAssignedToSelf());
}
}
Loading