From e50c6b7cdbe3c880a00feb9c6f0f9d2ac85531c5 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:40:54 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"NABI-250--refactor=20:=20=EC=9D=B8?= =?UTF-8?q?=EA=B8=B0=EC=83=81=ED=92=88=20controller=EC=97=90=EC=84=9C=20si?= =?UTF-8?q?ze=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5b1a79efe62d52af8b410850ce545b9282968b84. --- .../domain/card/api/CardController.java | 17 ++++----- .../card/repository/CardRepositoryCustom.java | 6 +-- .../card/repository/CardRepositoryImpl.java | 38 +++++++++---------- .../domain/card/service/CardService.java | 13 +++---- 4 files changed, 35 insertions(+), 39 deletions(-) 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 a56fc1ad..158c761a 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,7 +1,9 @@ package org.prgrms.nabimarketbe.domain.card.api; -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; 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; @@ -32,10 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -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; @RestController @RequestMapping("/api/v1/cards") @@ -158,10 +157,8 @@ public ResponseEntity deleteCardById( } @GetMapping("/popular") - public ResponseEntity>> getCardsByPopularity( - @RequestParam Integer size - ) { - CardListResponseDTO cardList = cardService.getCardsByPopularity(size); + public ResponseEntity>> getCardsByPopularity() { + CardListResponseDTO cardList = cardService.getCardsByPopularity(); 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 ff71b723..0e8c18eb 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,7 +1,5 @@ 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; @@ -10,6 +8,8 @@ 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(Integer size); + List getCardsByPopularity(); } 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 158683cd..0b543547 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,12 +1,15 @@ package org.prgrms.nabimarketbe.domain.card.repository; -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 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 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; @@ -20,20 +23,17 @@ import org.prgrms.nabimarketbe.global.util.QueryDslUtil; import org.springframework.data.domain.Sort; -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 java.util.ArrayList; +import java.util.List; -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; @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(Integer size) { + public List getCardsByPopularity() { List cardList = jpaQueryFactory .select( Projections.fields( @@ -164,7 +164,7 @@ public List getCardsByPopularity(Integer size) { .from(card) .where(statusEquals(CardStatus.TRADE_AVAILABLE)) .orderBy(card.viewCount.desc(), card.dibCount.desc()) - .limit(size) + .limit(FAMOUS_CARD_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 41ad279e..2b03553f 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,9 +1,6 @@ package org.prgrms.nabimarketbe.domain.card.service; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - +import lombok.RequiredArgsConstructor; 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; @@ -39,7 +36,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import lombok.RequiredArgsConstructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -330,8 +329,8 @@ public List getSuggestionResultCardList( } @Transactional(readOnly = true) - public CardListResponseDTO getCardsByPopularity(Integer size) { - List cardList = cardRepository.getCardsByPopularity(size); + public CardListResponseDTO getCardsByPopularity() { + List cardList = cardRepository.getCardsByPopularity(); CardListResponseDTO response = new CardListResponseDTO<>(cardList); return response;