Skip to content

Commit

Permalink
Merge pull request #90 from Hooking-CEOS/feature/brand
Browse files Browse the repository at this point in the history
Feature/brand
  • Loading branch information
CYJhub authored Jul 27, 2023
2 parents ec913e0 + 7a6dfc5 commit 0a17896
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/main/java/shop/hooking/hooking/controller/CopyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public ResponseEntity<HttpRes<List<CopyRes>>> copyList(HttpServletRequest httpRe
public ResponseEntity<CopySearchResponse> copySearchList(HttpServletRequest httpRequest,
@RequestParam(name = "keyword") String q,
@PathVariable int index) {

int startIndex = index * 30;


CopySearchResponse response = new CopySearchResponse();
List<CopySearchResult> results = new ArrayList<>();

Expand All @@ -105,38 +109,42 @@ public ResponseEntity<CopySearchResponse> copySearchList(HttpServletRequest http
moodCopyRes = cardJpaRepository.searchMood(q);
setScrapCntWhenTokenNotProvided(httpRequest, moodCopyRes);
Collections.shuffle(moodCopyRes);
CopySearchResult moodResult = createCopySearchResult(moodCopyRes);
CopySearchResult moodResult = new CopySearchResult();
moodResult.setType("mood");
moodResult.setKeyword(q); // 현재는 전체 카드 수가 나옴
moodResult.setTotalNum(moodCopyRes.size());
moodResult.setData(getLimitedCopyResByIndex(moodCopyRes,index));
results.add(moodResult);

if (!textCopyRes.isEmpty()) {
setScrapCntWhenTokenNotProvided(httpRequest, textCopyRes);
Collections.shuffle(textCopyRes);
CopySearchResult copyResult = createCopySearchResult(textCopyRes);
CopySearchResult copyResult = new CopySearchResult();
copyResult.setType("copy");
copyResult.setKeyword(q);
copyResult.setTotalNum(textCopyRes.size());
copyResult.setData(getLimitedCopyResByIndex(textCopyRes,index));
setIndicesForCopyRes(textCopyRes, q);
results.add(copyResult);
}
} else if (BrandType.containsKeyword(q)) {
brandCopyRes = cardJpaRepository.searchBrand(q);
setScrapCntWhenTokenNotProvided(httpRequest, brandCopyRes);
Collections.shuffle(brandCopyRes);
CopySearchResult brandResult = createCopySearchResult(brandCopyRes);
CopySearchResult brandResult = new CopySearchResult();
brandResult.setType("brand");
brandResult.setKeyword(q);
brandResult.setTotalNum(brandCopyRes.size());
brandResult.setData(getLimitedCopyResByIndex(brandCopyRes,index));
results.add(brandResult);
} else if (!textCopyRes.isEmpty()) {
setScrapCntWhenTokenNotProvided(httpRequest, textCopyRes);
Collections.shuffle(textCopyRes);
CopySearchResult copyResult = createCopySearchResult(textCopyRes);
CopySearchResult copyResult = new CopySearchResult();
copyResult.setType("copy");
copyResult.setKeyword(q);
copyResult.setTotalNum(textCopyRes.size());
copyResult.setData(getLimitedCopyResByIndex(textCopyRes,index));
setIndicesForCopyRes(textCopyRes, q);
results.add(copyResult);
}
Expand All @@ -150,16 +158,13 @@ public ResponseEntity<CopySearchResponse> copySearchList(HttpServletRequest http
.body(response);
}

// 요청한 index에 따라 30개씩 다른 결과를 생성
int startIndex = index * 30;
List<CopySearchResult> resultCopyRes = getLimitedCopyResByIndex2(results, startIndex);

response.setCode(HttpStatus.OK.value());
response.setMessage("요청에 성공하였습니다.");
response.setData(resultCopyRes);
response.setData(results);

return ResponseEntity.status(HttpStatus.OK)
.body(response);

}


Expand All @@ -169,11 +174,6 @@ private List<CopyRes> getLimitedCopyResByIndex(List<CopyRes> copyResList, int st
return copyResList.subList(startIndex, endIndex);
}

private List<CopySearchResult> getLimitedCopyResByIndex2(List<CopySearchResult> copyResList, int startIndex) {
int endIndex = Math.min(startIndex + 30, copyResList.size());
return copyResList.subList(startIndex, endIndex);
}




Expand Down

0 comments on commit 0a17896

Please sign in to comment.