Skip to content
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
12 changes: 12 additions & 0 deletions src/main/java/com/back/domain/cart/controller/CartController.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ public ResponseEntity<RsData<CartResponseDto>> toggleSelection(
return ResponseEntity.ok(RsData.of("200", "선택 상태가 변경되었습니다.", responseDto));
}

@PutMapping("/toggle-all-selection")
@Operation(summary = "장바구니 전체 선택 토글", description = "모든 장바구니 아이템의 선택 상태를 일괄 변경합니다.")
public ResponseEntity<RsData<List<CartResponseDto>>> toggleAllSelection(
@AuthenticationPrincipal CustomUserDetails customUserDetails,
@RequestParam boolean isSelected) {

User user = customUserDetails.getUser();
List<CartResponseDto> responseDtos = cartService.toggleAllSelection(user, isSelected);
String message = isSelected ? "모든 장바구니 아이템이 선택되었습니다." : "모든 장바구니 아이템이 해제되었습니다.";
return ResponseEntity.ok(RsData.of("200", message, responseDtos));
}

@GetMapping("/selected")
@Operation(
summary = "선택된 장바구니 아이템 조회",
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/back/domain/cart/service/CartService.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,32 @@ public CartResponseDto toggleSelection(User user, Long cartId) {
return CartResponseDto.from(updatedCart);
}

/**
* 장바구니 전체 선택 토글
*/
@Transactional
public List<CartResponseDto> toggleAllSelection(User user, boolean isSelected) {
// 1. 사용자의 모든 장바구니 아이템 조회 (상품/펀딩 fetch join)
List<Cart> userCarts = cartRepository.findByUserWithProduct(user);

// 2. 모든 아이템의 선택 상태를 일괄 변경
for (Cart cart : userCarts) {
if (isSelected) {
cart.select();
} else {
cart.unselect();
}
}

// 3. 일괄 저장
List<Cart> updatedCarts = cartRepository.saveAll(userCarts);

// 4. 응답 DTO 변환
return updatedCarts.stream()
.map(CartResponseDto::from)
.collect(Collectors.toList());
}

/**
* 선택된 장바구니 아이템 조회
* @param user 사용자
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ void getReviewStats_Success() throws Exception {

// When & Then
mockMvc.perform(get("/api/reviews/stats")
.param("productUuid", TEST_PRODUCT_UUID.toString()))
.param("productUuid", TEST_PRODUCT_UUID.toString())
.with(user(customUserDetails)))
.andExpect(status().isOk());
}

Expand Down