Skip to content

Commit

Permalink
Merge pull request #83 from YAPP-Github/feat/ISSUE-82
Browse files Browse the repository at this point in the history
feat: My carpool list API
  • Loading branch information
Park-Young-Hun authored Feb 11, 2024
2 parents e2efc71 + a807795 commit f308b7a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fullcar.carpool.domain.service.CarpoolIdService;
import com.fullcar.carpool.presentation.carpool.dto.request.CarpoolRequestDto;
import com.fullcar.carpool.presentation.carpool.dto.response.CarpoolResponseDto;
import com.fullcar.carpool.presentation.carpool.dto.response.MyCarpoolDto;
import com.fullcar.member.domain.car.Car;
import com.fullcar.member.domain.member.Member;

Expand Down Expand Up @@ -53,6 +54,17 @@ public CarpoolResponseDto.CarpoolDetailDtO toDetailDto(Carpool carpool, Member m
.build();
}

public MyCarpoolDto toMyCarpoolDto(Carpool carpool, Member member) {
return MyCarpoolDto.builder()
.id(carpool.getCarpoolId().getId())
.pickupLocation(carpool.getPickupLocation())
.money(carpool.getCost().getMoney())
.periodType(carpool.getCost().getPeriodType())
.carpoolState(carpool.getCarpoolState())
.createdAt(carpool.getCreatedAt())
.build();
}

public Carpool toEntity(Member member, CarpoolRequestDto carpoolRequestDto) {
return Carpool.builder()
.carpoolId(carpoolIdService.nextId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.fullcar.carpool.domain.carpool.Carpool;
import com.fullcar.carpool.domain.carpool.CarpoolId;
import com.fullcar.carpool.domain.carpool.CarpoolRepository;
import com.fullcar.carpool.domain.carpool.Driver;
import com.fullcar.carpool.presentation.carpool.dto.request.CarpoolRequestDto;
import com.fullcar.carpool.presentation.carpool.dto.response.CarpoolResponseDto;
import com.fullcar.carpool.presentation.carpool.dto.response.MyCarpoolDto;
import com.fullcar.core.exception.CustomException;
import com.fullcar.core.response.ErrorCode;
import com.fullcar.member.domain.car.Car;
Expand Down Expand Up @@ -63,4 +65,18 @@ public CarpoolResponseDto.CarpoolDetailDtO getCarpool(Member member, CarpoolId c

return carpoolMapper.toDetailDto(carpool, member, car);
}

@Transactional(readOnly = true)
public List<MyCarpoolDto> getMyCarpoolList(Member member) {
List<Carpool> carpools = carpoolRepository.findAllByDriverAndIsDeletedOrderByCreatedAtDesc(
Driver.builder()
.memberId(member.getId())
.build(),
false
);

return carpools.stream()
.map(carpool -> carpoolMapper.toMyCarpoolDto(carpool, member))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface CarpoolRepository extends JpaRepository<Carpool, CarpoolId> {
Optional<Carpool> findByCarpoolIdAndIsDeleted(CarpoolId carpoolId, boolean isDeleted);
Slice<Carpool> findAllByIsDeletedOrderByCreatedAtDesc(boolean isDeleted, Pageable pageable);
List<Carpool> findAllByDriverAndIsDeletedOrderByCreatedAtDesc(Driver driver, boolean isDeleted);

default Carpool findByCarpoolIdAndIsDeletedOrThrow(CarpoolId carpoolId, boolean isDeleted) {
return findByCarpoolIdAndIsDeleted(carpoolId, isDeleted).orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fullcar.carpool.domain.carpool.CarpoolId;
import com.fullcar.carpool.presentation.carpool.dto.request.CarpoolRequestDto;
import com.fullcar.carpool.presentation.carpool.dto.response.CarpoolResponseDto;
import com.fullcar.carpool.presentation.carpool.dto.response.MyCarpoolDto;
import com.fullcar.core.annotation.CurrentMember;
import com.fullcar.core.response.ApiResponse;
import com.fullcar.core.response.SuccessCode;
Expand All @@ -17,20 +18,21 @@
import org.springframework.data.domain.Slice;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "[Carpool] 카풀 관련 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/carpools")
@RequestMapping("/api/v1")
public class CarpoolController {
private final CarpoolService carpoolService;

@Operation(summary = "카풀 등록 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "등록 성공")
})
@PostMapping("")
@PostMapping("/carpools")
public ApiResponse<CarpoolResponseDto> postCarpool(
@Parameter(hidden = true)
@CurrentMember Member member,
Expand All @@ -47,7 +49,7 @@ public ApiResponse<CarpoolResponseDto> postCarpool(
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "조회 성공")
})
@GetMapping("")
@GetMapping("/carpools")
public ApiResponse<Slice<CarpoolResponseDto>> getCarpools(
@Parameter(hidden = true)
@CurrentMember Member member,
Expand All @@ -64,7 +66,7 @@ public ApiResponse<Slice<CarpoolResponseDto>> getCarpools(
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "조회 성공")
})
@GetMapping("/{carpoolId}")
@GetMapping("/carpools/{carpoolId}")
public ApiResponse<CarpoolResponseDto.CarpoolDetailDtO> getCarpool(
@Parameter(hidden = true)
@CurrentMember Member member,
Expand All @@ -75,4 +77,19 @@ public ApiResponse<CarpoolResponseDto.CarpoolDetailDtO> getCarpool(
carpoolService.getCarpool(member, new CarpoolId(carpoolId))
);
}

@Operation(summary = "내 카풀 목록 조회 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "조회 성공")
})
@GetMapping("/my-carpools")
public ApiResponse<List<MyCarpoolDto>> getMyCarpools(
@Parameter(hidden = true)
@CurrentMember Member member
) {
return ApiResponse.success(
SuccessCode.READ_SUCCESS,
carpoolService.getMyCarpoolList(member)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.fullcar.carpool.presentation.carpool.dto.response;

import com.fullcar.carpool.domain.carpool.CarpoolState;
import com.fullcar.carpool.domain.carpool.PeriodType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.time.LocalDateTime;


@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Schema(description = "카풀 List 응답 모델")
public class MyCarpoolDto {
@Schema(description = "카풀 id")
private Long id;

@Schema(description = "픽업장소")
private String pickupLocation;

@Schema(description = "희망비용(기간)")
private PeriodType periodType;

@Schema(description = "희망비용(가격)")
private Long money;

@Schema(description = "카풀 상태")
private CarpoolState carpoolState;

@Schema(description = "생성 Timestamp")
private LocalDateTime createdAt;
}

0 comments on commit f308b7a

Please sign in to comment.