Skip to content

Commit

Permalink
Merge pull request #63 from Hooking-CEOS/feature/brand
Browse files Browse the repository at this point in the history
[feat] 카피 전체 조회시 브랜드별 최신 5개
  • Loading branch information
CYJhub authored Jul 22, 2023
2 parents bc8849b + a33a6e7 commit 45c76f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ public class CopyController {
// 전체 카피라이팅 조회
@GetMapping("")
public HttpRes<List<CopyRes>> copyList() {
List<CopyRes> copyRes = copyService.getCopyList();
List<CopyRes> limitedCopyRes = getLimitedCopyRes(copyRes,30);
Long[] brandIds = {2L, 17L, 4L, 28L, 3L, 21L, 25L, 24L, 15L};

List<CopyRes> limitedCopyRes = new ArrayList<>();

for (Long brandId : brandIds) {
List<CopyRes> copyRes = copyService.getCopyList(brandId);
limitedCopyRes.addAll(getLimitedCopyRes(copyRes, 30));
}

return new HttpRes<>(limitedCopyRes);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shop.hooking.hooking.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import shop.hooking.hooking.entity.Brand;
import shop.hooking.hooking.entity.Card;
Expand All @@ -11,6 +12,8 @@
@Repository
public interface CardRepository extends JpaRepository<Card, Long>{

List<Card> findTop5ByBrandIdOrderByCreatedAtDesc(Long brandId);


Card findCardByBrandId(Long brandId); // 브랜드 아이디로 카피라이팅 카드 찾기

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/shop/hooking/hooking/service/CopyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class CopyService {


@Transactional
public List<CopyRes> getCopyList() {
List<Card> cards = cardRepository.findAll(); //카피 다가져옴
public List<CopyRes> getCopyList(Long brandId) {
List<Card> cards = cardRepository.findTop5ByBrandIdOrderByCreatedAtDesc(brandId);
List<CopyRes> copyResList = new ArrayList<>();

for (Card card : cards) {
CopyRes copyRes = createCopyRes(card); //하나씩 card 객체 생성
copyResList.add(copyRes); //하나씩 cardRes를 List에 add
CopyRes copyRes = createCopyRes(card);
copyResList.add(copyRes);
}

return copyResList;
Expand Down

0 comments on commit 45c76f7

Please sign in to comment.