Skip to content

Commit

Permalink
Merge pull request #88 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 efe6b71 + adca60a commit fb8910f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
22 changes: 18 additions & 4 deletions src/main/java/shop/hooking/hooking/controller/BrandController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package shop.hooking.hooking.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import shop.hooking.hooking.dto.HttpRes;
import shop.hooking.hooking.dto.response.BrandRes;
Expand All @@ -14,6 +16,7 @@
import shop.hooking.hooking.service.JwtTokenProvider;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
Expand All @@ -29,28 +32,38 @@ public class BrandController {


// 전체 브랜드 기본정보 조회
@CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000/, http://localhost:3001/")
@GetMapping("")
public HttpRes<List<BrandRes.BrandDto>> showAllBrand(){
public ResponseEntity<List<BrandRes.BrandDto>> showAllBrand(){
List<BrandRes.BrandDto> brandDtoList = brandService.getBrandList();

return new HttpRes<>(brandDtoList);
return ResponseEntity.status(HttpStatus.OK.value())
.body(brandDtoList);
}

// 해당 브랜드 상세정보 조회

@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 HttpRes<BrandRes.BrandDetailDto> showOneBrand(HttpServletRequest httpRequest,@PathVariable Long brand_id, @PathVariable int index){
public ResponseEntity<BrandRes.BrandDetailDto> showOneBrand(HttpServletRequest httpRequest, @PathVariable Long brand_id, @PathVariable int index){
BrandRes.BrandDetailDto brandDetailDto = brandService.getOneBrand(brand_id); // List<card> 가 전체 반환됨

// 전체 card 리스트를 가져옴
List<Card> cards = brandDetailDto.getCard();


// index와 30을 곱하여 startIndex 계산
int startIndex = index * 30;

// startIndex부터 30개씩의 카드를 잘라서 resultCards 리스트에 저장
List<Card> resultCards = getLimitedCardsByIndex(cards, startIndex);



if (resultCards.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}

brandDetailDto.setCard(resultCards);


Expand All @@ -59,7 +72,8 @@ public HttpRes<BrandRes.BrandDetailDto> showOneBrand(HttpServletRequest httpRequ
setScrapCntWhenTokenNotProvided(brandDetailDto.getCard());
}

return new HttpRes<>(brandDetailDto);
return ResponseEntity.status(HttpStatus.OK.value())
.body(brandDetailDto);
}


Expand Down
36 changes: 16 additions & 20 deletions src/main/java/shop/hooking/hooking/controller/CopyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import shop.hooking.hooking.dto.request.CrawlingData;
import shop.hooking.hooking.dto.request.CrawlingReq;
import shop.hooking.hooking.dto.response.CopyRes;
import shop.hooking.hooking.dto.response.CopySearchResponse;
import shop.hooking.hooking.dto.response.CopySearchResult;
import shop.hooking.hooking.entity.Brand;
import shop.hooking.hooking.entity.Card;
Expand Down Expand Up @@ -79,18 +78,16 @@ public ResponseEntity<List<CopyRes>> copyList(HttpServletRequest httpRequest, @P


@GetMapping("/search/{index}")
public ResponseEntity<CopySearchResponse> copySearchList(HttpServletRequest httpRequest,
public ResponseEntity<List<CopySearchResult>> copySearchList(HttpServletRequest httpRequest,
@RequestParam(name = "keyword") String q,
@PathVariable int index) {
CopySearchResponse response = new CopySearchResponse();

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

if (q.isEmpty()) { // 검색 결과가 없다면
response.setCode(HttpStatus.BAD_REQUEST.value());
response.setMessage("검색 결과를 찾을 수 없습니다.");
response.setData(results);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(response);
.body(results);

}

// 검색 결과 처리 로직...
Expand Down Expand Up @@ -142,24 +139,20 @@ public ResponseEntity<CopySearchResponse> copySearchList(HttpServletRequest http
}

if (results.isEmpty()) {
String errorMessage = "검색 결과를 찾을 수 없습니다.";
response.setCode(HttpStatus.BAD_REQUEST.value());
response.setMessage(errorMessage);
response.setData(results);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(response);
.body(results);

}

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

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

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

}


Expand Down Expand Up @@ -235,12 +228,15 @@ public HttpRes<String> saveCrawling(@RequestBody CrawlingReq crawlingReq) {


@GetMapping("/filter/{index}")
public HttpRes<List<CopyRes>> searchFilterCard(HttpServletRequest httpRequest,@PathVariable int index,CardSearchCondition condition) {
public ResponseEntity<List<CopyRes>> searchFilterCard(HttpServletRequest httpRequest,@PathVariable int index,CardSearchCondition condition) {
List<CopyRes> results = cardJpaRepository.filter(condition);
int startIndex = index * 30; //인덱싱
List<CopyRes> resultCopyRes = getLimitedCopyResByIndex(results, startIndex);
setScrapCntWhenTokenNotProvided(httpRequest, resultCopyRes);
return new HttpRes<>(resultCopyRes);
if(resultCopyRes.isEmpty()){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(resultCopyRes);
}

private void setScrapCntWhenTokenNotProvided(HttpServletRequest httpRequest, List<CopyRes> copyResList) {
Expand Down Expand Up @@ -281,4 +277,4 @@ private List<CopyRes> getLimitedCopyRes(List<CopyRes> copyResList, int limit){
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
@Setter
@NoArgsConstructor
public class CopySearchResponse {
private int code;
private String message;
private List<CopySearchResult> data;

// Constructors, getters, setters, and other methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.stereotype.Repository;
import shop.hooking.hooking.dto.CardSearchCondition;
import shop.hooking.hooking.dto.response.CopyRes;
import shop.hooking.hooking.dto.response.CopySearchResponse;
import shop.hooking.hooking.dto.response.QCopyRes;
import shop.hooking.hooking.entity.*;

Expand Down

0 comments on commit fb8910f

Please sign in to comment.