Skip to content

Commit

Permalink
Merge pull request #89 from Hooking-CEOS/feature/copy
Browse files Browse the repository at this point in the history
Feature/copy
  • Loading branch information
JiwonKim08 authored Jul 27, 2023
2 parents fb8910f + ad86119 commit ec913e0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ 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 ResponseEntity<List<BrandRes.BrandDto>> showAllBrand(){
public ResponseEntity<HttpRes<List<BrandRes.BrandDto>>> showAllBrand(){
List<BrandRes.BrandDto> brandDtoList = brandService.getBrandList();

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

// 전체 card 리스트를 가져옴
Expand All @@ -61,7 +60,8 @@ public ResponseEntity<BrandRes.BrandDetailDto> showOneBrand(HttpServletRequest h


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

brandDetailDto.setCard(resultCards);
Expand All @@ -72,8 +72,7 @@ public ResponseEntity<BrandRes.BrandDetailDto> showOneBrand(HttpServletRequest h
setScrapCntWhenTokenNotProvided(brandDetailDto.getCard());
}

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


Expand Down
46 changes: 29 additions & 17 deletions src/main/java/shop/hooking/hooking/controller/CopyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 @@ -49,7 +50,7 @@ public class CopyController {
// 전체 카피라이팅 조회
// 페이지네이션 구현
@GetMapping("/{index}") //copy/0=> 0-30 copy/1=>0~30 copy/2=>60~90 copy/9 => 270~300
public ResponseEntity<List<CopyRes>> copyList(HttpServletRequest httpRequest, @PathVariable int index) {
public ResponseEntity<HttpRes<List<CopyRes>>> copyList(HttpServletRequest httpRequest, @PathVariable int index) {
Long[] brandIds = {2L, 3L, 4L, 12L, 15L, 17L, 21L, 24L, 25L, 28L};

List<CopyRes> tempCopyRes = new ArrayList<>();
Expand All @@ -72,22 +73,24 @@ public ResponseEntity<List<CopyRes>> copyList(HttpServletRequest httpRequest, @P

setScrapCntWhenTokenNotProvided(httpRequest, resultCopyRes);

return ResponseEntity.status(HttpStatus.OK).body(resultCopyRes);
return ResponseEntity.ok(new HttpRes<>(resultCopyRes));
}



@GetMapping("/search/{index}")
public ResponseEntity<List<CopySearchResult>> copySearchList(HttpServletRequest httpRequest,
public ResponseEntity<CopySearchResponse> 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(results);

.body(response);
}

// 검색 결과 처리 로직...
Expand Down Expand Up @@ -139,23 +142,28 @@ public ResponseEntity<List<CopySearchResult>> copySearchList(HttpServletRequest
}

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

.body(response);
}

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

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

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

.body(response);
}



private List<CopyRes> getLimitedCopyResByIndex(List<CopyRes> copyResList, int startIndex) {
int endIndex = Math.min(startIndex + 30, copyResList.size());
return copyResList.subList(startIndex, endIndex);
Expand All @@ -171,34 +179,38 @@ private List<CopySearchResult> getLimitedCopyResByIndex2(List<CopySearchResult>

@CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000/, http://localhost:3001/")
@GetMapping("/scrap/{index}")
public ResponseEntity<List<CopyRes>> copyScrapList(HttpServletRequest httpRequest, @PathVariable int index) {
public ResponseEntity<HttpRes<List<CopyRes>>> copyScrapList(HttpServletRequest httpRequest, @PathVariable int index) {
User user = jwtTokenProvider.getUserInfoByToken(httpRequest);
List<CopyRes> copyRes = copyService.getCopyScrapList(user);

int startIndex = index * 30;
List<CopyRes> resultCopyRes = getLimitedCopyResByIndex(copyRes, startIndex);

return ResponseEntity.ok(resultCopyRes);
return ResponseEntity.ok(new HttpRes<>(resultCopyRes));
}



@CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000/, http://localhost:3001/")
@PostMapping("/scrap")
public ResponseEntity<String> copyScrap(HttpServletRequest httpRequest, @RequestBody CopyReq copyReq) throws IOException {
public ResponseEntity<HttpRes<String>> copyScrap(HttpServletRequest httpRequest, @RequestBody CopyReq copyReq) throws IOException {
User user = jwtTokenProvider.getUserInfoByToken(httpRequest);
Card card = cardRepository.findCardById(copyReq.getCardId());
boolean isScrap = copyService.saveCopy(user, card);

if (isScrap) {
return ResponseEntity.ok("스크랩을 완료하였습니다.");
return ResponseEntity.ok(new HttpRes<>("스크랩을 완료하였습니다."));
} else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("중복 스크랩이 불가능합니다.");
String errorMessage = "중복 스크랩이 불가능합니다.";
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new HttpRes<>(HttpStatus.BAD_REQUEST.value(), errorMessage));
}
}






@PostMapping("/crawling")
public HttpRes<String> saveCrawling(@RequestBody CrawlingReq crawlingReq) {
List<CrawlingData> dataList = crawlingReq.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
@Setter
@NoArgsConstructor
public class CopySearchResponse {
private int code;
private String message;
private List<CopySearchResult> data;


// Constructors, getters, setters, and other methods
}

0 comments on commit ec913e0

Please sign in to comment.