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
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ public ResponseEntity<ApiResponse<AuctionListResponse>> getAuctions(
// Pageable 객체 생성
Pageable pageable = PageRequest.of(page, size);

// 둜그인 μ•ˆ ν–ˆμœΌλ©΄ null
// 둜그인 ν–ˆμœΌλ©΄ userId
Long loginUserId = null;
try {
loginUserId = currentUserProvider.getCurrentUserId(request);
} catch (Exception e) {
// λΉ„λ‘œκ·ΈμΈ μš”μ²­μ΄λ©΄ κ·ΈλŒ€λ‘œ null μœ μ§€
}

// μΆ”κ°€: RECOMMENDED μƒνƒœμΌ λ•ŒλŠ” 별도 처리
if (status == AuctionStatus.RECOMMENDED) {
Long userId = currentUserProvider.getCurrentUserId(request);
Expand All @@ -193,7 +202,7 @@ public ResponseEntity<ApiResponse<AuctionListResponse>> getAuctions(
}

// μ„œλΉ„μŠ€ 호좜
AuctionListResponse response = itemService.getAuctionList(status, categories, minPrice, maxPrice, sort, pageable);
AuctionListResponse response = itemService.getAuctionList(status, categories, minPrice, maxPrice, sort, pageable, loginUserId);

return ResponseEntity.ok(ApiResponse.onSuccess(response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,30 @@ public static AuctionListItemDTO toAuctionListItemDTO(Item item) {
.build();
}

//⭐좔가 λ©”μ„œλ“œ: 차단 μ—¬λΆ€ 포함 버전
public static AuctionListItemDTO toAuctionListItemDTO(
Item item,
boolean blockedSeller // Serviceμ—μ„œ κ³„μ‚°λœ κ°’
) {
List<String> imageUrls = item.getImages().stream()
.map(ItemImage::getImageUrl)
.collect(Collectors.toList());

return AuctionListItemDTO.builder()
.itemId(item.getItemId())
.title(item.getTitle())
.imageUrls(imageUrls)
.currentPrice(item.getCurrentPrice())
.bidderCount(item.getBidCount())
.endTime(item.getEndTime())
.viewCount(item.getViewCount())
.itemStatus(item.getItemStatus().name())
.startPrice(item.getStartPrice())
.createdAt(item.getCreatedAt())
.blockedSeller(blockedSeller) // 차단 μ—¬λΆ€
.build();
}

/**
* Item β†’ MyAuctionItemDTO λ³€ν™˜
* @param item μƒν’ˆ μ—”ν‹°ν‹°
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public class AuctionListItemDTO {

@Schema(description = "κ²½λ§€ μ‹œμž‘ λ‚ μ§œ")
private LocalDateTime createdAt; // 생성일(κ²½λ§€ μ‹œμž‘λ‚ μ§œ) μΆ”κ°€

// 둜그인 μ‚¬μš©μžκ°€ 이 판맀자λ₯Ό μ°¨λ‹¨ν–ˆλŠ”μ§€ μ—¬λΆ€
@Schema(description = "μ°¨λ‹¨ν•œ 판맀자의 μƒν’ˆμΈμ§€ μ—¬λΆ€", example = "false")
private boolean blockedSeller;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ List<Item> findByEndTimeBeforeAndItemStatus(
JOIN region r ON i.region_id = r.region_id
WHERE i.item_type = 'AUCTION'
AND i.item_status = CAST(:status AS varchar)
AND (
:me IS NULL OR i.seller NOT IN (
SELECT bl.blocked
FROM BlockList bl
WHERE bl.blocker.id = :me
)
)
AND (
6371 * acos(
LEAST(1, GREATEST(-1,
Expand All @@ -83,13 +76,6 @@ SELECT count(1)
JOIN region r ON i.region_id = r.region_id
WHERE i.item_type = 'AUCTION'
AND i.item_status = CAST(:status AS varchar)
AND (
:me IS NULL OR i.seller NOT IN (
SELECT bl.blocked
FROM BlockList bl
WHERE bl.blocker.id = :me
)
)
AND (
6371 * acos(
LEAST(1, GREATEST(-1,
Expand All @@ -106,7 +92,6 @@ Page<Item> findNearbyItems(
@Param("lat") double centerLat,
@Param("lon") double centerLon,
@Param("distanceKm") double distanceKm,
@Param("me") Long me,
Pageable pageable
);

Expand All @@ -117,13 +102,6 @@ Page<Item> findNearbyItems(
SELECT i FROM Item i
WHERE i.itemType = com.salemale.global.common.enums.ItemType.AUCTION
AND i.itemStatus = :status
AND (
:me IS NULL OR i.seller NOT IN (
SELECT bl.blocked
FROM BlockList bl
WHERE bl.blocker.id = :me
)
)
AND (
LOWER(i.title) LIKE LOWER(CONCAT('%', :keyword, '%'))
OR LOWER(i.name) LIKE LOWER(CONCAT('%', :keyword, '%'))
Expand All @@ -133,7 +111,6 @@ OR LOWER(i.name) LIKE LOWER(CONCAT('%', :keyword, '%'))
Page<Item> searchItemsByKeyword(
@Param("status") com.salemale.global.common.enums.ItemStatus status,
@Param("keyword") String keyword,
@Param("me") Long me,
Pageable pageable
);

Expand All @@ -147,13 +124,6 @@ Page<Item> searchItemsByKeyword(
SELECT i FROM Item i
WHERE i.itemType = com.salemale.global.common.enums.ItemType.AUCTION
AND i.itemStatus = :status
AND (
:me IS NULL OR i.seller NOT IN (
SELECT bl.blocked
FROM BlockList bl
WHERE bl.blocker.id = :me
)
)
AND (
LOWER(i.title) LIKE LOWER(CONCAT('%', :keyword, '%'))
OR LOWER(i.name) LIKE LOWER(CONCAT('%', :keyword, '%'))
Expand All @@ -176,7 +146,6 @@ Page<Item> searchItemsByKeywordWithFilters(
@Param("isPopular") boolean isPopular,
@Param("threeDaysAgo") LocalDateTime threeDaysAgo,
@Param("now") LocalDateTime now,
@Param("me") Long me,
Pageable pageable
);

Expand All @@ -190,13 +159,6 @@ Page<Item> searchItemsByKeywordWithFilters(
SELECT i FROM Item i
WHERE i.itemType = com.salemale.global.common.enums.ItemType.AUCTION
AND i.itemStatus = :status
AND (
:me IS NULL OR i.seller NOT IN (
SELECT bl.blocked
FROM BlockList bl
WHERE bl.blocker.id = :me
)
)
AND (:categories IS NULL OR i.category IN :categories)
AND (:minPrice IS NULL OR i.currentPrice >= :minPrice)
AND (:maxPrice IS NULL OR i.currentPrice <= :maxPrice)
Expand All @@ -214,7 +176,6 @@ Page<Item> searchItemsByFiltersOnly(
@Param("isPopular") boolean isPopular,
@Param("threeDaysAgo") LocalDateTime threeDaysAgo,
@Param("now") LocalDateTime now,
@Param("me") Long me,
Pageable pageable
);

Expand All @@ -227,13 +188,6 @@ Page<Item> searchItemsByFiltersOnly(
JOIN region r ON i.region_id = r.region_id
WHERE i.item_type = 'AUCTION'
AND i.item_status = CAST(:status AS varchar)
AND (
:me IS NULL OR i.seller NOT IN (
SELECT bl.blocked
FROM BlockList bl
WHERE bl.blocker.id = :me
)
)
AND (
LOWER(i.title) LIKE LOWER(CONCAT('%', :keyword, '%'))
OR LOWER(i.name) LIKE LOWER(CONCAT('%', :keyword, '%'))
Expand All @@ -255,13 +209,6 @@ SELECT count(1)
JOIN region r ON i.region_id = r.region_id
WHERE i.item_type = 'AUCTION'
AND i.item_status = CAST(:status AS varchar)
AND (
:me IS NULL OR i.seller NOT IN (
SELECT bl.blocked
FROM BlockList bl
WHERE bl.blocker.id = :me
)
)
AND (
LOWER(i.title) LIKE LOWER(CONCAT('%', :keyword, '%'))
OR LOWER(i.name) LIKE LOWER(CONCAT('%', :keyword, '%'))
Expand All @@ -283,7 +230,6 @@ Page<Item> findNearbyItemsByKeyword(
@Param("lat") double centerLat,
@Param("lon") double centerLon,
@Param("distanceKm") double distanceKm,
@Param("me") Long me,
Pageable pageable
);
Long countBySeller(User seller);
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/com/salemale/domain/item/service/ItemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.salemale.domain.region.entity.Region;
import com.salemale.domain.s3.service.S3Service;
import com.salemale.domain.user.entity.User;
import com.salemale.domain.user.repository.BlockListRepository;
import com.salemale.domain.user.repository.UserRegionRepository;
import com.salemale.domain.user.repository.UserRepository;
import com.salemale.global.common.enums.*;
Expand All @@ -35,6 +36,8 @@
import java.time.format.DateTimeParseException;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Slf4j
Expand All @@ -52,6 +55,7 @@ public class ItemService {
private final ImageService imageService;
private final RecommendationService recommendationService;
private final ReviewRepository reviewRepository;
private final BlockListRepository blockListRepository; //차단 쑰회용

//μ°œν•˜κΈ°
@Transactional
Expand Down Expand Up @@ -365,16 +369,32 @@ public AuctionListResponse getAuctionList(
Integer minPrice,
Integer maxPrice,
AuctionSortType sortType,
Pageable pageable
Pageable pageable,
Long loginUserId // 둜그인 μ‚¬μš©μž ID
) {
// 1. QueryDSL둜 동적 쿼리 μ‹€ν–‰ (이미 DBμ—μ„œ 정렬됨)
Page<Item> itemPage = itemRepository.findAuctionList(
status, categories, minPrice, maxPrice, sortType, pageable
);

// 2. DTO λ³€ν™˜ (μ—”ν‹°ν‹°μ˜ bidCount μ‚¬μš©)
// ⭐ μ°¨λ‹¨ν•œ 판맀자 ID λͺ©λ‘ 쑰회 (둜그인 μƒνƒœμΌ λ•Œλ§Œ)
Set<Long> tempblockedSellerIds = Collections.emptySet();
if (loginUserId != null) {
tempblockedSellerIds = blockListRepository.findBlockedUserIds(loginUserId)
.stream()
.collect(Collectors.toSet());
}

final Set<Long> blockedSellerIds = tempblockedSellerIds;
// ⭐ DTO λ³€ν™˜ + 차단 μ—¬λΆ€ 계산
List<AuctionListItemDTO> items = itemPage.getContent().stream()
.map(item -> ItemConverter.toAuctionListItemDTO(item))
.map(item -> {
boolean blockedSeller =
loginUserId != null &&
blockedSellerIds.contains(item.getSeller().getId());

return ItemConverter.toAuctionListItemDTO(item, blockedSeller);
})
.toList();

// 3. νŽ˜μ΄μ§• 정보와 ν•¨κ»˜ 응닡 DTO 생성
Expand Down Expand Up @@ -407,7 +427,7 @@ public AuctionListResponse getRecommendedAuctionList(Long userId, Pageable pagea
if (recommendedItemIds.isEmpty()) {
log.info("[μΆ”μ²œ λŒ€μ²΄] μ‚¬μš©μž ID: {}, 인기 μƒν’ˆμœΌλ‘œ λŒ€μ²΄", userId);
return getAuctionList(AuctionStatus.POPULAR, null, null, null,
AuctionSortType.BID_COUNT_DESC, pageable);
AuctionSortType.BID_COUNT_DESC, pageable, userId);
}

// 3. νŽ˜μ΄μ§• 처리
Expand Down
Loading