Skip to content

Commit

Permalink
Merge pull request #102 from YAPP-Github/fix/ISSUE-101
Browse files Browse the repository at this point in the history
fix: Revise Carpool, Form list dto
  • Loading branch information
Park-Young-Hun authored Feb 24, 2024
2 parents bfcdbbf + f5de187 commit e873b6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ public CarpoolResponseDto registerCarpool(Member member, CarpoolRequestDto carpo
}

@Transactional(readOnly = true)
public Slice<CarpoolResponseDto> getCarpoolList(Member member, int page, int size) {
public Slice<CarpoolResponseDto> getCarpoolList(int page, int size) {
Sort sort = Sort.by(Sort.Direction.DESC, "createdAt");
PageRequest pageRequest = PageRequest.of(page, size, sort);

Slice<Carpool> carpools = carpoolRepository.findAllByIsDeletedOrderByCreatedAtDesc(false, pageRequest);

List<CarpoolResponseDto> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -79,14 +79,21 @@ public FormResponseDto requestForm(Member member, CarpoolId carpoolId, FormReque

@Transactional(readOnly = true)
public List<FormResponseDto> readSentFormList(Member member) {
return formRepository.findAllByPassengerAndIsDeletedOrderByCreatedAtDesc(
List<Form> forms = formRepository.findAllByPassengerAndIsDeletedOrderByCreatedAtDesc(
Passenger.builder()
.memberId(member.getId())
.build(),
false
).stream()
.map(form -> formMapper.toDto(form, member))
.toList();
false);

List<FormResponseDto> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ public ApiResponse<CarpoolResponseDto> postCarpool(
})
@GetMapping("/carpools")
public ApiResponse<Slice<CarpoolResponseDto>> 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)
);
}

Expand Down

0 comments on commit e873b6a

Please sign in to comment.