diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java index 158c761a..a56fc1ad 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/api/CardController.java @@ -1,9 +1,7 @@ package org.prgrms.nabimarketbe.domain.card.api; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.RequiredArgsConstructor; +import java.util.List; + import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO; import org.prgrms.nabimarketbe.domain.card.dto.request.CardStatusUpdateRequestDTO; import org.prgrms.nabimarketbe.domain.card.dto.request.CardUpdateRequestDTO; @@ -34,7 +32,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.util.List; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.RequiredArgsConstructor; @RestController @RequestMapping("/api/v1/cards") @@ -157,8 +158,10 @@ public ResponseEntity deleteCardById( } @GetMapping("/popular") - public ResponseEntity>> getCardsByPopularity() { - CardListResponseDTO cardList = cardService.getCardsByPopularity(); + public ResponseEntity>> getCardsByPopularity( + @RequestParam Integer size + ) { + CardListResponseDTO cardList = cardService.getCardsByPopularity(size); return ResponseEntity.ok(ResponseFactory.getSingleResult(cardList)); } diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java index 0e8c18eb..ff71b723 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryCustom.java @@ -1,5 +1,7 @@ package org.prgrms.nabimarketbe.domain.card.repository; +import java.util.List; + import org.prgrms.nabimarketbe.domain.card.dto.response.projection.CardFamousResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.wrapper.CardPagingResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.wrapper.CardSuggestionResponseDTO; @@ -8,8 +10,6 @@ import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; import org.prgrms.nabimarketbe.domain.user.entity.User; -import java.util.List; - public interface CardRepositoryCustom { CardPagingResponseDTO getCardsByCondition( CategoryEnum category, @@ -32,5 +32,5 @@ List getSuggestionAvailableCards( Long targetCardId ); - List getCardsByPopularity(); + List getCardsByPopularity(Integer size); } diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java index 0b543547..158683cd 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepositoryImpl.java @@ -1,15 +1,12 @@ package org.prgrms.nabimarketbe.domain.card.repository; -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.Order; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringExpressions; -import com.querydsl.core.types.dsl.StringTemplate; -import com.querydsl.jpa.impl.JPAQueryFactory; -import lombok.RequiredArgsConstructor; +import static org.prgrms.nabimarketbe.domain.card.entity.QCard.card; +import static org.prgrms.nabimarketbe.domain.item.entity.QItem.item; +import static org.prgrms.nabimarketbe.domain.suggestion.entity.QSuggestion.suggestion; + +import java.util.ArrayList; +import java.util.List; + import org.prgrms.nabimarketbe.domain.card.dto.response.projection.CardFamousResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.projection.CardInfoResponseDTO; import org.prgrms.nabimarketbe.domain.card.dto.response.projection.CardListReadResponseDTO; @@ -23,17 +20,20 @@ import org.prgrms.nabimarketbe.global.util.QueryDslUtil; import org.springframework.data.domain.Sort; -import java.util.ArrayList; -import java.util.List; +import com.querydsl.core.types.ConstantImpl; +import com.querydsl.core.types.Order; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringExpressions; +import com.querydsl.core.types.dsl.StringTemplate; +import com.querydsl.jpa.impl.JPAQueryFactory; -import static org.prgrms.nabimarketbe.domain.card.entity.QCard.card; -import static org.prgrms.nabimarketbe.domain.item.entity.QItem.item; -import static org.prgrms.nabimarketbe.domain.suggestion.entity.QSuggestion.suggestion; +import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class CardRepositoryImpl implements CardRepositoryCustom { - private static final int FAMOUS_CARD_SIZE = 5; - private final JPAQueryFactory jpaQueryFactory; @Override @@ -150,7 +150,7 @@ public List getSuggestionAvailableCards( } @Override - public List getCardsByPopularity() { + public List getCardsByPopularity(Integer size) { List cardList = jpaQueryFactory .select( Projections.fields( @@ -164,7 +164,7 @@ public List getCardsByPopularity() { .from(card) .where(statusEquals(CardStatus.TRADE_AVAILABLE)) .orderBy(card.viewCount.desc(), card.dibCount.desc()) - .limit(FAMOUS_CARD_SIZE) + .limit(size) .fetch(); return cardList; diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java b/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java index 2b03553f..41ad279e 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/card/service/CardService.java @@ -1,6 +1,9 @@ package org.prgrms.nabimarketbe.domain.card.service; -import lombok.RequiredArgsConstructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + import org.prgrms.nabimarketbe.domain.card.dto.request.CardCreateRequestDTO; import org.prgrms.nabimarketbe.domain.card.dto.request.CardStatusUpdateRequestDTO; import org.prgrms.nabimarketbe.domain.card.dto.request.CardUpdateRequestDTO; @@ -36,9 +39,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor @@ -329,8 +330,8 @@ public List getSuggestionResultCardList( } @Transactional(readOnly = true) - public CardListResponseDTO getCardsByPopularity() { - List cardList = cardRepository.getCardsByPopularity(); + public CardListResponseDTO getCardsByPopularity(Integer size) { + List cardList = cardRepository.getCardsByPopularity(size); CardListResponseDTO response = new CardListResponseDTO<>(cardList); return response;