Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: product - room - cart 내 log.debug 삭제 및 접근 제어자 수정, transaction(readOnly=true)를 통해 성능 향상 #139

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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