-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
396 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...java/com/testcar/car/domains/car/Car.java → ...m/testcar/car/domains/car/entity/Car.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ava/com/testcar/car/domains/car/Type.java → .../testcar/car/domains/car/entity/Type.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.testcar.car.domains.car; | ||
package com.testcar.car.domains.car.entity; | ||
|
||
|
||
import lombok.Getter; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/testcar/car/domains/car/model/RegisterCarRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/testcar/car/domains/car/repository/CarCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/java/com/testcar/car/domains/car/repository/CarCustomRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/testcar/car/domains/car/repository/CarRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/testcar/car/domains/carReservation/CarReservationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.testcar.car.domains.carReservation; | ||
|
||
|
||
import com.testcar.car.common.annotation.AuthMember; | ||
import com.testcar.car.common.annotation.RoleAllowed; | ||
import com.testcar.car.common.response.PageResponse; | ||
import com.testcar.car.domains.carReservation.entity.CarReservation; | ||
import com.testcar.car.domains.carReservation.model.CarReservationResponse; | ||
import com.testcar.car.domains.carReservation.model.dto.CarReservationDto; | ||
import com.testcar.car.domains.carReservation.model.vo.CarReservationFilterCondition; | ||
import com.testcar.car.domains.member.Member; | ||
import com.testcar.car.domains.member.Role; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springdoc.core.annotations.ParameterObject; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "[시험차량 관리] ", description = "시험차량 관리 API") | ||
@RestController | ||
@RequestMapping("/cars") | ||
@RequiredArgsConstructor | ||
public class CarReservationController { | ||
private final CarReservationService carReservationService; | ||
|
||
@GetMapping("/reservations") | ||
@RoleAllowed(role = Role.USER) | ||
@Operation(summary = "[시험차량 관리] 시험차량 대여 이력", description = "조건에 맞는 시험차량 대여 이력을 모두 조회합니다.") | ||
public PageResponse<CarReservationResponse> getCarReservationsByCondition( | ||
@ParameterObject @ModelAttribute CarReservationFilterCondition condition, | ||
@ParameterObject Pageable pageable) { | ||
final Page<CarReservationDto> carReservations = | ||
carReservationService.findAllPageByCondition(condition, pageable); | ||
return PageResponse.from(carReservations.map(CarReservationResponse::from)); | ||
} | ||
|
||
@PostMapping("/{carStockId}/reserve") | ||
@RoleAllowed(role = Role.USER) | ||
@Operation(summary = "[시험차량 관리] 시험차량 대여", description = "시험 차량을 예약합니다.") | ||
public CarReservationResponse postCarReservation( | ||
@AuthMember Member member, @PathVariable Long carStockId) { | ||
final CarReservation carReservation = carReservationService.reserve(member, carStockId); | ||
return CarReservationResponse.from(carReservation); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/testcar/car/domains/carReservation/CarReservationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.testcar.car.domains.carReservation; | ||
|
||
import static com.testcar.car.domains.carStock.entity.StockStatus.AVAILABLE; | ||
|
||
import com.testcar.car.common.exception.BadRequestException; | ||
import com.testcar.car.domains.carReservation.entity.CarReservation; | ||
import com.testcar.car.domains.carReservation.exception.ErrorCode; | ||
import com.testcar.car.domains.carReservation.model.dto.CarReservationDto; | ||
import com.testcar.car.domains.carReservation.model.vo.CarReservationFilterCondition; | ||
import com.testcar.car.domains.carReservation.repository.CarReservationRepository; | ||
import com.testcar.car.domains.carStock.CarStockService; | ||
import com.testcar.car.domains.carStock.entity.CarStock; | ||
import com.testcar.car.domains.member.Member; | ||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class CarReservationService { | ||
private static final int RESERVATION_DATE = 7; | ||
|
||
private final CarStockService carStockService; | ||
private final CarReservationRepository carReservationRepository; | ||
|
||
/** 조건에 맞는 시험차량 대여 이력을 조회합니다. */ | ||
public Page<CarReservationDto> findAllPageByCondition( | ||
CarReservationFilterCondition condition, Pageable pageable) { | ||
return carReservationRepository.findAllPageByCondition(condition, pageable); | ||
} | ||
|
||
/** 시험차량을 예약합니다. */ | ||
public CarReservation reserve(Member member, Long carStockId) { | ||
final CarStock carStock = carStockService.findById(carStockId); | ||
validateCarStockAvailable(carStock); | ||
final LocalDateTime now = LocalDateTime.now(); | ||
final LocalDateTime expiredAt = now.toLocalDate().plusDays(RESERVATION_DATE).atStartOfDay(); | ||
final CarReservation carReservation = | ||
CarReservation.builder() | ||
.member(member) | ||
.carStock(carStock) | ||
.startedAt(now) | ||
.expiredAt(expiredAt) | ||
.build(); | ||
return carReservationRepository.save(carReservation); | ||
} | ||
|
||
public void validateCarStockAvailable(CarStock carStock) { | ||
if (carStock.getStatus() != AVAILABLE) { | ||
throw new BadRequestException(ErrorCode.CAR_STOCK_NOT_AVAILABLE); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/testcar/car/domains/carReservation/exception/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.testcar.car.domains.carReservation.exception; | ||
|
||
|
||
import com.testcar.car.common.exception.BaseErrorCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ErrorCode implements BaseErrorCode { | ||
CAR_STOCK_NOT_AVAILABLE("CRS001", "해당 재고는 대여 불가합니다."); | ||
|
||
private final String code; | ||
private final String message; | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/testcar/car/domains/carReservation/model/CarReservationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.testcar.car.domains.carReservation.model; | ||
|
||
|
||
import com.testcar.car.common.annotation.DateFormat; | ||
import com.testcar.car.domains.carReservation.entity.CarReservation; | ||
import com.testcar.car.domains.carReservation.entity.ReservationStatus; | ||
import com.testcar.car.domains.carReservation.model.dto.CarReservationDto; | ||
import com.testcar.car.domains.carStock.entity.CarStock; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class CarReservationResponse { | ||
@Schema(description = "차량 예약 ID", example = "1") | ||
private final Long id; | ||
|
||
@Schema(description = "차량명", example = "아반떼") | ||
private final String name; | ||
|
||
@Schema(description = "차량 재고번호", example = "2023010300001") | ||
private final String stockNumber; | ||
|
||
@DateFormat | ||
@Schema(description = "차량 대여 시작일", example = "2021-01-01") | ||
private final LocalDateTime startedAt; | ||
|
||
@DateFormat | ||
@Schema(description = "차량 대여 만료일", example = "2021-01-08") | ||
private final LocalDateTime expiredAt; | ||
|
||
@Schema(description = "대여 상태", example = "RESERVED", implementation = ReservationStatus.class) | ||
private final ReservationStatus status; | ||
|
||
public static CarReservationResponse from(CarReservationDto carReservationDto) { | ||
return CarReservationResponse.builder() | ||
.id(carReservationDto.getId()) | ||
.name(carReservationDto.getCarName()) | ||
.stockNumber(carReservationDto.getStockNumber()) | ||
.startedAt(carReservationDto.getStartedAt()) | ||
.expiredAt(carReservationDto.getExpiredAt()) | ||
.status(carReservationDto.getStatus()) | ||
.build(); | ||
} | ||
|
||
public static CarReservationResponse from(CarReservation carReservation) { | ||
final CarStock carStock = carReservation.getCarStock(); | ||
|
||
return CarReservationResponse.builder() | ||
.id(carReservation.getId()) | ||
.name(carStock.getCar().getName()) | ||
.stockNumber(carStock.getStockNumber()) | ||
.startedAt(carReservation.getStartedAt()) | ||
.expiredAt(carReservation.getExpiredAt()) | ||
.status(carReservation.getStatus()) | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/testcar/car/domains/carReservation/model/dto/CarReservationDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.testcar.car.domains.carReservation.model.dto; | ||
|
||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import com.testcar.car.domains.carReservation.entity.CarReservation; | ||
import com.testcar.car.domains.carReservation.entity.ReservationStatus; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CarReservationDto { | ||
private final Long id; | ||
private final String carName; | ||
private final String stockNumber; | ||
private final LocalDateTime startedAt; | ||
private final LocalDateTime expiredAt; | ||
private final ReservationStatus status; | ||
|
||
@QueryProjection | ||
public CarReservationDto(CarReservation carReservation, String carName, String stockNumber) { | ||
this.id = carReservation.getId(); | ||
this.carName = carName; | ||
this.stockNumber = stockNumber; | ||
this.startedAt = carReservation.getStartedAt(); | ||
this.expiredAt = carReservation.getExpiredAt(); | ||
this.status = carReservation.getStatus(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...n/java/com/testcar/car/domains/carReservation/model/vo/CarReservationFilterCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.testcar.car.domains.carReservation.model.vo; | ||
|
||
|
||
import com.testcar.car.common.annotation.DateFormat; | ||
import com.testcar.car.domains.carReservation.entity.ReservationStatus; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDate; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class CarReservationFilterCondition { | ||
@Schema(description = "차량명", example = "null") | ||
private String name; | ||
|
||
@Schema(description = "대여 상태", example = "null", implementation = ReservationStatus.class) | ||
private ReservationStatus status; | ||
|
||
@DateFormat | ||
@Schema(description = "대여일자 시작일", example = "null") | ||
private LocalDate startDate; | ||
|
||
@DateFormat | ||
@Schema(description = "대여일자 종료일", example = "null") | ||
private LocalDate endDate; | ||
} |
Oops, something went wrong.