Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] isScrap 처리 #104

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public class CopyController {
// 페이지네이션
@GetMapping("/{index}")
public ResponseEntity<HttpRes<List<CopyRes>>> copyList(HttpServletRequest httpRequest, @PathVariable int index) {

User user = jwtTokenProvider.getUserInfoByToken(httpRequest);
int limit = 30;
List<CopyRes> resultCopyRes = copyService.getCopyListFromBrandsAndSetScrapCnt(httpRequest,index,limit);
copyService.setIsScrapWithUser(user, resultCopyRes);
return ResponseEntity.ok(new HttpRes<>(resultCopyRes));

}
Expand All @@ -65,7 +66,13 @@ public ResponseEntity<HttpRes<List<CopyRes>>> copyList(HttpServletRequest httpRe
public ResponseEntity<CopySearchRes> copySearchList(HttpServletRequest httpRequest,
@RequestParam(name = "keyword") String q,
@PathVariable int index) {
User user = jwtTokenProvider.getUserInfoByToken(httpRequest);
CopySearchRes response = copyService.copySearchList(httpRequest, q, index);
List<CopySearchResult> copySearchResults = response.getData();
for(CopySearchResult copySearchResult : copySearchResults){
List<CopyRes> copyRes = copySearchResult.getData();
copyService.setIsScrapWithUser(user, copyRes);
}
if (response.getCode() == HttpStatus.BAD_REQUEST.value()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
} else {
Expand Down Expand Up @@ -126,10 +133,12 @@ public ResponseEntity<HttpRes<String>> saveCrawling(@RequestBody CrawlingReq cra
// 카피라이팅 필터링
@GetMapping("/filter/{index}")
public ResponseEntity<List<CopyRes>> searchFilterCard(HttpServletRequest httpRequest, @PathVariable int index, CardSearchCondition condition) {
User user = jwtTokenProvider.getUserInfoByToken(httpRequest);
List<CopyRes> resultCopyRes = copyService.searchFilterCard(httpRequest, index, condition);
if (resultCopyRes.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
copyService.setIsScrapWithUser(user,resultCopyRes);
return ResponseEntity.status(HttpStatus.OK).body(resultCopyRes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class CopyRes implements Comparable<CopyRes>{
private LocalDateTime createdAt;
private List<Integer> index;
private LocalDateTime scrapTime;
private Integer isScrap;

@Builder
@QueryProjection
Expand All @@ -42,7 +43,6 @@ public CopyRes(Long id, Brand brand, String text, LocalDateTime createdAt) {
this.text = text;
this.scrapCnt = 0;
this.createdAt = createdAt;

}

//왜안됨..?
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/shop/hooking/hooking/service/CopyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ public List<CopyRes> getCopyList(Long brandId) {
return copyResList;
}

public void setIsScrapWithUser(User user, List<CopyRes> copyResList) {
List<Scrap> scraps = scrapRepository.findScrapByUser(user);

// cardList의 id와 scraps의 card_id를 비교하여 isScrap 값을 설정
for (CopyRes copyRes : copyResList) {
long cardId = copyRes.getId();
boolean isScrapFound = scraps.stream().anyMatch(scrap -> scrap.getCard().getId() == cardId);
copyRes.setIsScrap(isScrapFound ? 1 : 0);
}
}
@Transactional

public void saveCrawlingData(List<CrawlingData> dataList) {
Expand Down