Skip to content

Commit

Permalink
Merge pull request #139 from Shimpyo-House/refactor/product
Browse files Browse the repository at this point in the history
refactor: product - room - cart 내 log.debug 삭제 및 접근 제어자 수정, transaction(readOnly=true)를 통해 성능 향상
  • Loading branch information
wocjf0513 authored Dec 15, 2023
2 parents 3bbd461 + 6843e96 commit cc302eb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -25,6 +26,7 @@
@RestController
@RequestMapping("/api/carts")
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CartRestController {

private final CartService cartService;
Expand All @@ -36,10 +38,9 @@ public ResponseEntity<ResponseDto<List<CartResponse>>> getCarts() {
}

@PostMapping
@Transactional
public ResponseEntity<ResponseDto<CartResponse>> addCart(
@Valid @RequestBody CartCreateRequest cartCreateRequest) {
log.debug("startDate: {}, endDate: {}, price: {}", cartCreateRequest.startDate(),
cartCreateRequest.endDate(), cartCreateRequest.price());
if (DateTimeUtil.isNotValidDate(DateTimeUtil.toLocalDate(cartCreateRequest.startDate()),
DateTimeUtil.toLocalDate(cartCreateRequest.endDate()))) {
throw new InvalidDateException();
Expand All @@ -50,9 +51,9 @@ public ResponseEntity<ResponseDto<CartResponse>> addCart(
}

@DeleteMapping("/{cartId}")
@Transactional
public ResponseEntity<ResponseDto<CartDeleteResponse>> deleteCart(
@PathVariable("cartId") Long cartId) {
log.debug("cartId: {}", cartId);
return ResponseEntity.ok().body(
ResponseDto.res(HttpStatus.OK, cartService.deleteCart(cartId), "장바구니를 성공적으로 삭제했습니다."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CartResponse {
private final String checkOut;

@Builder
public CartResponse(Long cartId, Long productId, String productName, String image,
private CartResponse(Long cartId, Long productId, String productName, String image,
Long roomCode,
String roomName, Long price, String description, Long standard, Long capacity,
String startDate, String endDate, String checkIn, String checkOut) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -31,6 +32,7 @@
@RequestMapping("/api/products")
@RequiredArgsConstructor
@Validated
@Transactional(readOnly = true)
public class ProductRestController {

private final ProductService productService;
Expand All @@ -43,7 +45,6 @@ public ResponseEntity<ResponseDto<PaginatedProductResponse>> getProducts(
@RequestParam(required = false, defaultValue = "") String category,
@RequestParam(required = false, defaultValue = "0") Long capacity,
@PageableConstraint(Product.class) @PageableDefault(size = 10, page = 0) Pageable pageable) {
log.debug("productName: {}, address: {}, category: {}", productName, address, category);
SearchKeywordRequest searchKeywordRequest = SearchKeywordRequest.builder()
.productName(productName).address(address).category(category).capacity(capacity)
.build();
Expand All @@ -57,7 +58,6 @@ public ResponseEntity<ResponseDto<ProductDetailsResponse>> getProductDetails(
@PathVariable("productId") Long productId,
@RequestParam @Pattern(regexp = DateTimeUtil.LOCAL_DATE_REGEX_PATTERN, message = "잘못된 시간 형식입니다. (올바른 예시: 2023-10-25)") String startDate,
@RequestParam @Pattern(regexp = DateTimeUtil.LOCAL_DATE_REGEX_PATTERN, message = "잘못된 시간 형식입니다. (올바른 예시: 2023-10-25)") String endDate) {
log.debug("productId: {}, startDate: {}, endDate: {}", productId, startDate, endDate);
if (DateTimeUtil.isNotValidDate(DateTimeUtil.toLocalDate(startDate),
DateTimeUtil.toLocalDate(endDate))) {
throw new InvalidDateException();
Expand All @@ -72,7 +72,6 @@ public ResponseEntity<ResponseDto<Void>> isAvailableForReservation(
@PathVariable("roomId") Long roomId,
@RequestParam @Pattern(regexp = DateTimeUtil.LOCAL_DATE_REGEX_PATTERN, message = "잘못된 시간 형식입니다. (올바른 예시: 2023-10-25)") String startDate,
@RequestParam @Pattern(regexp = DateTimeUtil.LOCAL_DATE_REGEX_PATTERN, message = "잘못된 시간 형식입니다. (올바른 예시: 2023-10-25)") String endDate) {
log.debug("roomId: {}, startDate: {}, endDate: {}", roomId, startDate, endDate);
if (DateTimeUtil.isNotValidDate(DateTimeUtil.toLocalDate(startDate),
DateTimeUtil.toLocalDate(endDate))) {
throw new InvalidDateException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RoomResponse {
private Long remaining;

@Builder
public RoomResponse(Long roomCode, String roomName, Long price, String description,
private RoomResponse(Long roomCode, String roomName, Long price, String description,
Long standard,
Long capacity, String checkIn, String checkOut, Long remaining,
RoomOptionResponse roomOptionResponse,
Expand Down

0 comments on commit cc302eb

Please sign in to comment.