From f5de187a15f81e7d3d63a694a14a942dc659dcef Mon Sep 17 00:00:00 2001 From: Young Hun Park Date: Sat, 24 Feb 2024 04:01:00 +0900 Subject: [PATCH] fix: Revise Carpool, Form list dto --- .../application/carpool/CarpoolService.java | 8 ++++++-- .../carpool/application/form/FormService.java | 19 +++++++++++++------ .../carpool/CarpoolController.java | 4 +--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/fullcar/carpool/application/carpool/CarpoolService.java b/src/main/java/com/fullcar/carpool/application/carpool/CarpoolService.java index 63c6946..e184ffd 100644 --- a/src/main/java/com/fullcar/carpool/application/carpool/CarpoolService.java +++ b/src/main/java/com/fullcar/carpool/application/carpool/CarpoolService.java @@ -48,14 +48,18 @@ public CarpoolResponseDto registerCarpool(Member member, CarpoolRequestDto carpo } @Transactional(readOnly = true) - public Slice getCarpoolList(Member member, int page, int size) { + public Slice getCarpoolList(int page, int size) { Sort sort = Sort.by(Sort.Direction.DESC, "createdAt"); PageRequest pageRequest = PageRequest.of(page, size, sort); Slice carpools = carpoolRepository.findAllByIsDeletedOrderByCreatedAtDesc(false, pageRequest); List carpoolResponseDtos = carpools.getContent().stream() - .map(carpool -> carpoolMapper.toDto(carpool, member)) + .map(carpool -> carpoolMapper.toDto( + carpool, + memberRepository.findByIdAndIsDeletedOrThrow(carpool.getDriver().getMemberId(), false) + ) + ) .toList(); return new SliceImpl<>(carpoolResponseDtos, carpools.getPageable(), carpools.hasNext()); diff --git a/src/main/java/com/fullcar/carpool/application/form/FormService.java b/src/main/java/com/fullcar/carpool/application/form/FormService.java index f0ff606..59ad29b 100644 --- a/src/main/java/com/fullcar/carpool/application/form/FormService.java +++ b/src/main/java/com/fullcar/carpool/application/form/FormService.java @@ -22,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -33,7 +34,6 @@ public class FormService { private final CarpoolRepository carpoolRepository; private final MemberRepository memberRepository; //TODO: Event 기반으로 변경 필요. private final FormMapper formMapper; - private final NotificationService notificationService; private final ApplicationEventPublisher eventPublisher; @Transactional @@ -79,14 +79,21 @@ public FormResponseDto requestForm(Member member, CarpoolId carpoolId, FormReque @Transactional(readOnly = true) public List readSentFormList(Member member) { - return formRepository.findAllByPassengerAndIsDeletedOrderByCreatedAtDesc( + List
forms = formRepository.findAllByPassengerAndIsDeletedOrderByCreatedAtDesc( Passenger.builder() .memberId(member.getId()) .build(), - false - ).stream() - .map(form -> formMapper.toDto(form, member)) - .toList(); + false); + + List formResponseDtos = new ArrayList<>(); + + for (Form form: forms) { + Carpool carpool = carpoolRepository.findByCarpoolIdAndIsDeletedOrThrow(form.getCarpoolId(), false); + Member driver = memberRepository.findByIdAndIsDeletedOrThrow(carpool.getDriver().getMemberId(), false); + formResponseDtos.add(formMapper.toDto(form, driver)); + } + + return formResponseDtos; } @Transactional(readOnly = true) diff --git a/src/main/java/com/fullcar/carpool/presentation/carpool/CarpoolController.java b/src/main/java/com/fullcar/carpool/presentation/carpool/CarpoolController.java index 847f453..abedd8f 100644 --- a/src/main/java/com/fullcar/carpool/presentation/carpool/CarpoolController.java +++ b/src/main/java/com/fullcar/carpool/presentation/carpool/CarpoolController.java @@ -51,14 +51,12 @@ public ApiResponse postCarpool( }) @GetMapping("/carpools") public ApiResponse> getCarpools( - @Parameter(hidden = true) - @CurrentMember Member member, @RequestParam int page, @RequestParam int size ) { return ApiResponse.success( SuccessCode.READ_SUCCESS, - carpoolService.getCarpoolList(member, page, size) + carpoolService.getCarpoolList(page, size) ); }