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

Feature/copy #103

Merged
merged 2 commits 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 @@ -37,23 +37,25 @@ public ResponseEntity<HttpRes<List<BrandRes.BrandDto>>> showAllBrand(){
}

@CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000/, http://localhost:3001/")
@PostMapping("/{brand_id}/{index}")
public ResponseEntity<HttpRes<BrandRes.BrandDetailDto>> showOneBrand(HttpServletRequest httpRequest, @PathVariable Long brand_id, @PathVariable int index){
@GetMapping("/{brand_id}/{index}")
public ResponseEntity<HttpRes<BrandRes.BrandDetailDto>> getOneBrand(HttpServletRequest httpRequest, @PathVariable Long brand_id, @PathVariable int index){
User user = jwtTokenProvider.getUserInfoByToken(httpRequest);
BrandRes.BrandDetailDto brandDetailDto = brandService.getOneBrand(brand_id);


List<BrandRes.cardDto> cards = brandDetailDto.getCard();

int startIndex = index * 30;
List<BrandRes.cardDto> resultCards = brandService.getLimitedCardsByIndex(cards, startIndex);


if (resultCards.isEmpty()) {
String errorMessage = "카드가 없습니다.";
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new HttpRes<>(HttpStatus.BAD_REQUEST.value(), errorMessage));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new HttpRes<>(HttpStatus.BAD_REQUEST.value(), "카드가 없습니다."));
}

brandDetailDto.setCard(resultCards);
brandService.setScrapCntWhenTokenNotProvided(httpRequest, resultCards);
brandService.setIsScrapWithUser(user, resultCards);

return ResponseEntity.ok(new HttpRes<>(brandDetailDto));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public ResponseEntity<HttpRes<List<CopyRes>>> copyScrapList(HttpServletRequest h
for(CopyRes copyRes1 : resultCopyRes){
Scrap scrap = scrapRepository.findByUserAndCardId(user, copyRes1.getId());
copyRes1.setScrapTime(scrap.getCreatedAt());

}

Collections.sort(resultCopyRes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static class cardDto{
private String text;
private Integer scrapCnt;
private LocalDateTime createdAt;
private Integer isScrap;
}

}
4 changes: 2 additions & 2 deletions src/main/java/shop/hooking/hooking/dto/response/CopyRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class CopyRes implements Comparable<CopyRes>{
private String text;
private Integer scrapCnt;
private LocalDateTime createdAt;

private List<Integer> index;

private LocalDateTime scrapTime;

@Builder
Expand All @@ -35,6 +33,7 @@ public CopyRes(Long id, Brand brand, String text, Integer scrapCnt,LocalDateTime
this.text = text;
this.scrapCnt = scrapCnt;
this.createdAt = createdAt;

}

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

}

//왜안됨..?
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/shop/hooking/hooking/service/BrandService.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ public List<BrandRes.cardDto> getLimitedCardsByIndex(List<BrandRes.cardDto> card
return cards.subList(startIndex, endIndex);
}

public void setIsScrapWithUser(User user, List<BrandRes.cardDto> cardList) {
List<Scrap> scraps = scrapRepository.findScrapByUser(user);

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


public void setScrapCntWhenTokenNotProvided(HttpServletRequest httpRequest, List<BrandRes.cardDto> cardList) {
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/shop/hooking/hooking/service/CopyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,6 @@ public String checkKeyword(String q) {
return q;
}

public ResponseEntity<CopySearchRes> getBadRequestResponseEntity(CopySearchRes response, List<CopySearchResult> results) {
response.setCode(HttpStatus.BAD_REQUEST.value());
response.setMessage("검색 결과를 찾을 수 없습니다.");
response.setData(results);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
}

@Transactional
public CopyRes createScrapRes(Scrap scrap) {
Expand Down