diff --git a/src/main/java/shop/hooking/hooking/config/OAuth2SuccessHandler.java b/src/main/java/shop/hooking/hooking/config/OAuth2SuccessHandler.java index f05604c..e5b9681 100644 --- a/src/main/java/shop/hooking/hooking/config/OAuth2SuccessHandler.java +++ b/src/main/java/shop/hooking/hooking/config/OAuth2SuccessHandler.java @@ -66,14 +66,9 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo } else if (referer != null && referer.startsWith("http://localhost:3000/") && host.equals("hooking.shop")) { targetUrl = "http://localhost:3000/oath-processor"; // 로컬 환경 } else if (referer != null && referer.startsWith("https://hooking.me/") && host.equals("hooking.shop")) { - targetUrl = "https://hooking.me/oath-processor"; // 배포 + targetUrl = "https://hooking.me/oath-processor"; // 실배포 환경 } - -// else if (referer != null && referer.startsWith("https://hooking.me/") && host.equals("hooking.shop")) { -// targetUrl = "https://hooking.me/oath-processor"; // 로컬 환경 -// } - else { // 기본적으로 로컬 개발 환경으로 설정 targetUrl = "http://localhost:3000/oath-processor"; // 로컬 환경 diff --git a/src/main/java/shop/hooking/hooking/config/SecurityConfig.java b/src/main/java/shop/hooking/hooking/config/SecurityConfig.java index 7a71be5..91dffdc 100644 --- a/src/main/java/shop/hooking/hooking/config/SecurityConfig.java +++ b/src/main/java/shop/hooking/hooking/config/SecurityConfig.java @@ -58,8 +58,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() - .antMatchers("**/oath-processor/**","/kakaologin","/copy/{index}", "/copy/search","/copy/filter","/copy/crawling", "/brand", "/brand/{brand_id}/{index}","/example/login" + .antMatchers("**/oath-processor/**","/kakaologin","/copy/{index}", "/copy/search/{index}","/copy/filter/{index}","/copy/crawling", "/brand", "/brand/{brand_id}/{index}","/example/login" ).permitAll() .anyRequest().authenticated() diff --git a/src/main/java/shop/hooking/hooking/controller/BrandController.java b/src/main/java/shop/hooking/hooking/controller/BrandController.java index 03f4879..87105a1 100644 --- a/src/main/java/shop/hooking/hooking/controller/BrandController.java +++ b/src/main/java/shop/hooking/hooking/controller/BrandController.java @@ -37,8 +37,9 @@ public HttpRes> showAllBrand(){ } // 해당 브랜드 상세정보 조회 + @PostMapping("/{brand_id}/{index}") - public HttpRes showOneBrand(@PathVariable Long brand_id, @PathVariable int index){ + public HttpRes showOneBrand(HttpServletRequest httpRequest,@PathVariable Long brand_id, @PathVariable int index){ BrandRes.BrandDetailDto brandDetailDto = brandService.getOneBrand(brand_id); // List 가 전체 반환됨 // 전체 card 리스트를 가져옴 @@ -53,8 +54,21 @@ public HttpRes showOneBrand(@PathVariable Long brand_id brandDetailDto.setCard(resultCards); + + // 로그인이 안되어있을 경우 scrapCnt를 0으로 설정 + if (jwtTokenProvider.getUserInfoByToken(httpRequest) == null) { + setScrapCntWhenTokenNotProvided(brandDetailDto.getCard()); + } + return new HttpRes<>(brandDetailDto); } + private void setScrapCntWhenTokenNotProvided(List cardList) { + for (Card card : cardList) { + card.setScrapCnt(0); + } + } + + // startIndex부터 30개의 카드를 잘라서 반환하는 메서드 private List getLimitedCardsByIndex(List cards, int startIndex) { diff --git a/src/main/java/shop/hooking/hooking/controller/CopyController.java b/src/main/java/shop/hooking/hooking/controller/CopyController.java index 623d969..64f23de 100644 --- a/src/main/java/shop/hooking/hooking/controller/CopyController.java +++ b/src/main/java/shop/hooking/hooking/controller/CopyController.java @@ -71,19 +71,17 @@ public HttpRes> copyList(HttpServletRequest httpRequest,@PathVaria } - private List getLimitedCopyResByIndex(List copyResList, int startIndex) { - int endIndex = Math.min(startIndex + 30, copyResList.size()); - return copyResList.subList(startIndex, endIndex); - } @Cacheable("copySearchCache") - @GetMapping("/search") - public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@RequestParam(name = "keyword") String q) { + @GetMapping("/search/{index}") + public CopySearchResponse copySearchList(HttpServletRequest httpRequest, + @RequestParam(name = "keyword") String q, + @PathVariable int index) { CopySearchResponse response = new CopySearchResponse(); List results = new ArrayList<>(); - if (q.isEmpty()) { //검색 결과가 없다면 + if (q.isEmpty()) { // 검색 결과가 없다면 response.setCode(HttpStatus.BAD_REQUEST.value()); response.setMessage("검색 결과를 찾을 수 없습니다."); response.setData(results); @@ -107,7 +105,7 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request moodResult.setTotalNum(moodCopyRes.size()); results.add(moodResult); - if(!textCopyRes.isEmpty()){ + if (!textCopyRes.isEmpty()) { setScrapCntWhenTokenNotProvided(httpRequest, textCopyRes); Collections.shuffle(textCopyRes); CopySearchResult copyResult = createCopySearchResult(textCopyRes); @@ -126,7 +124,7 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request brandResult.setKeyword(q); brandResult.setTotalNum(brandCopyRes.size()); results.add(brandResult); - } else if (!textCopyRes.isEmpty()){ + } else if (!textCopyRes.isEmpty()) { setScrapCntWhenTokenNotProvided(httpRequest, textCopyRes); Collections.shuffle(textCopyRes); CopySearchResult copyResult = createCopySearchResult(textCopyRes); @@ -144,30 +142,41 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request return response; } + // 요청한 index에 따라 30개씩 다른 결과를 생성 + int startIndex = index * 30; + List resultCopyRes = getLimitedCopyResByIndex2(results, startIndex); + response.setCode(HttpStatus.OK.value()); response.setMessage("요청에 성공하였습니다."); - response.setData(results); + response.setData(resultCopyRes); + return response; } + private List getLimitedCopyResByIndex(List copyResList, int startIndex) { + int endIndex = Math.min(startIndex + 30, copyResList.size()); + return copyResList.subList(startIndex, endIndex); + } + + private List getLimitedCopyResByIndex2(List copyResList, int startIndex) { + int endIndex = Math.min(startIndex + 30, copyResList.size()); + return copyResList.subList(startIndex, endIndex); + } + + @CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000/, http://localhost:3001/") - @GetMapping("/scrap") - public HttpRes> copyScrapList(HttpServletRequest httpRequest) { + @GetMapping("/scrap/{index}") + public HttpRes> copyScrapList(HttpServletRequest httpRequest,@PathVariable int index) { User user = jwtTokenProvider.getUserInfoByToken(httpRequest); List copyRes = copyService.getCopyScrapList(user); - int endIndex = Math.min(30, copyRes.size()); - List limitedCopyRes = copyRes.subList(0, endIndex); - -// if(user == null){ -// List notLoginCopyRes = copyRes.subList(0, endIndex); -// return new HttpRes<>(notLoginCopyRes); -// } + int startIndex = index * 30; //인덱싱 + List resultCopyRes = getLimitedCopyResByIndex(copyRes, startIndex); - return new HttpRes<>(limitedCopyRes); + return new HttpRes<>(resultCopyRes); } @@ -214,12 +223,13 @@ public HttpRes saveCrawling(@RequestBody CrawlingReq crawlingReq) { } - @GetMapping("/filter") - public HttpRes> searchFilterCard(HttpServletRequest httpRequest,CardSearchCondition condition) { + @GetMapping("/filter/{index}") + public HttpRes> searchFilterCard(HttpServletRequest httpRequest,@PathVariable int index,CardSearchCondition condition) { List results = cardJpaRepository.filter(condition); - List limitedResults = getLimitedCopyRes(results,30); - setScrapCntWhenTokenNotProvided(httpRequest, limitedResults); - return new HttpRes<>(limitedResults); + int startIndex = index * 30; //인덱싱 + List resultCopyRes = getLimitedCopyResByIndex(results, startIndex); + setScrapCntWhenTokenNotProvided(httpRequest, resultCopyRes); + return new HttpRes<>(resultCopyRes); } private void setScrapCntWhenTokenNotProvided(HttpServletRequest httpRequest, List copyResList) { diff --git a/src/main/java/shop/hooking/hooking/dto/HttpRes.java b/src/main/java/shop/hooking/hooking/dto/HttpRes.java index 70713fa..0985328 100644 --- a/src/main/java/shop/hooking/hooking/dto/HttpRes.java +++ b/src/main/java/shop/hooking/hooking/dto/HttpRes.java @@ -31,4 +31,8 @@ public HttpRes(T data) { } + + + + } diff --git a/src/main/java/shop/hooking/hooking/entity/Card.java b/src/main/java/shop/hooking/hooking/entity/Card.java index 5a280b6..ffb837b 100644 --- a/src/main/java/shop/hooking/hooking/entity/Card.java +++ b/src/main/java/shop/hooking/hooking/entity/Card.java @@ -10,6 +10,8 @@ import javax.persistence.Entity; import javax.persistence.Table; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; @DynamicUpdate @@ -43,9 +45,13 @@ public class Card { @JoinColumn(name="brand_id") private Brand brand; + @Column(name = "created_at") private LocalDateTime createdAt; + @OneToMany(mappedBy = "card", cascade = CascadeType.ALL, orphanRemoval = true) + private List scraps = new ArrayList<>(); + @PrePersist public void prePersist() { this.scrapCnt= this.scrapCnt == null ? 0 : this.scrapCnt;