Skip to content

Commit

Permalink
NABI-250--refactor : 인기상품 controller에서 size받도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
BeommoKoo-dev committed Nov 20, 2023
1 parent 03744ee commit 5b1a79e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -157,8 +158,10 @@ public ResponseEntity<CommonResult> deleteCardById(
}

@GetMapping("/popular")
public ResponseEntity<SingleResult<CardListResponseDTO<CardFamousResponseDTO>>> getCardsByPopularity() {
CardListResponseDTO<CardFamousResponseDTO> cardList = cardService.getCardsByPopularity();
public ResponseEntity<SingleResult<CardListResponseDTO<CardFamousResponseDTO>>> getCardsByPopularity(
@RequestParam Integer size
) {
CardListResponseDTO<CardFamousResponseDTO> cardList = cardService.getCardsByPopularity(size);

return ResponseEntity.ok(ResponseFactory.getSingleResult(cardList));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -32,5 +32,5 @@ List<CardSuggestionResponseDTO> getSuggestionAvailableCards(
Long targetCardId
);

List<CardFamousResponseDTO> getCardsByPopularity();
List<CardFamousResponseDTO> getCardsByPopularity(Integer size);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -150,7 +150,7 @@ public List<CardSuggestionResponseDTO> getSuggestionAvailableCards(
}

@Override
public List<CardFamousResponseDTO> getCardsByPopularity() {
public List<CardFamousResponseDTO> getCardsByPopularity(Integer size) {
List<CardFamousResponseDTO> cardList = jpaQueryFactory
.select(
Projections.fields(
Expand All @@ -164,7 +164,7 @@ public List<CardFamousResponseDTO> getCardsByPopularity() {
.from(card)
.where(statusEquals(CardStatus.TRADE_AVAILABLE))
.orderBy(card.viewCount.desc(), card.dibCount.desc())
.limit(FAMOUS_CARD_SIZE)
.limit(size)
.fetch();

return cardList;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -329,8 +330,8 @@ public List<CardSuggestionResponseDTO> getSuggestionResultCardList(
}

@Transactional(readOnly = true)
public CardListResponseDTO<CardFamousResponseDTO> getCardsByPopularity() {
List<CardFamousResponseDTO> cardList = cardRepository.getCardsByPopularity();
public CardListResponseDTO<CardFamousResponseDTO> getCardsByPopularity(Integer size) {
List<CardFamousResponseDTO> cardList = cardRepository.getCardsByPopularity(size);
CardListResponseDTO<CardFamousResponseDTO> response = new CardListResponseDTO<>(cardList);

return response;
Expand Down

0 comments on commit 5b1a79e

Please sign in to comment.