Skip to content

Commit

Permalink
Merge pull request #83 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 f283db1 + 6726093 commit 6712242
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ 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}","/example/login"
.antMatchers("**/oath-processor/**","/kakaologin","/copy/{index}", "/copy/search","/copy/filter","/copy/crawling", "/brand", "/brand/{brand_id}/{index}","/example/login"

).permitAll()

Expand Down
26 changes: 23 additions & 3 deletions src/main/java/shop/hooking/hooking/controller/BrandController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.springframework.web.bind.annotation.*;
import shop.hooking.hooking.dto.HttpRes;
import shop.hooking.hooking.dto.response.BrandRes;
import shop.hooking.hooking.dto.response.CopyRes;
import shop.hooking.hooking.dto.response.ReviewRes;
import shop.hooking.hooking.entity.Card;
import shop.hooking.hooking.entity.User;
import shop.hooking.hooking.exception.BadRequestException;
import shop.hooking.hooking.repository.UserRepository;
Expand Down Expand Up @@ -35,13 +37,31 @@ public HttpRes<List<BrandRes.BrandDto>> showAllBrand(){
}

// 해당 브랜드 상세정보 조회
@PostMapping("/{brand_id}")
public HttpRes<BrandRes.BrandDetailDto> showOneBrand(@PathVariable Long brand_id){
BrandRes.BrandDetailDto brandDetailDto = brandService.getOneBrand(brand_id);
@PostMapping("/{brand_id}/{index}")
public HttpRes<BrandRes.BrandDetailDto> showOneBrand(@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);
System.out.println(resultCards.size());

brandDetailDto.setCard(resultCards);

return new HttpRes<>(brandDetailDto);
}

// startIndex부터 30개의 카드를 잘라서 반환하는 메서드
private List<Card> getLimitedCardsByIndex(List<Card> cards, int startIndex) {
int endIndex = Math.min(startIndex + 30, cards.size());
return cards.subList(startIndex, endIndex);
}

// // 해당 브랜드 팔로우
// @CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000, http://localhost:3001")
// @PostMapping("/{brand_id}/follow")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request
Collections.shuffle(moodCopyRes);
CopySearchResult moodResult = createCopySearchResult(moodCopyRes);
moodResult.setType("mood");
moodResult.setKeyword(q);
moodResult.setKeyword(q); // 현재는 전체 카드 수가 나옴
moodResult.setTotalNum(moodCopyRes.size());
results.add(moodResult);

if(!textCopyRes.isEmpty()){
Expand All @@ -112,6 +113,7 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request
CopySearchResult copyResult = createCopySearchResult(textCopyRes);
copyResult.setType("copy");
copyResult.setKeyword(q);
copyResult.setTotalNum(textCopyRes.size());
setIndicesForCopyRes(textCopyRes, q);
results.add(copyResult);
}
Expand All @@ -122,13 +124,15 @@ public CopySearchResponse copySearchList(HttpServletRequest httpRequest,@Request
CopySearchResult brandResult = createCopySearchResult(brandCopyRes);
brandResult.setType("brand");
brandResult.setKeyword(q);
brandResult.setTotalNum(brandCopyRes.size());
results.add(brandResult);
} else if (!textCopyRes.isEmpty()){
setScrapCntWhenTokenNotProvided(httpRequest, textCopyRes);
Collections.shuffle(textCopyRes);
CopySearchResult copyResult = createCopySearchResult(textCopyRes);
copyResult.setType("copy");
copyResult.setKeyword(q);
copyResult.setTotalNum(textCopyRes.size());
setIndicesForCopyRes(textCopyRes, q);
results.add(copyResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Setter
@NoArgsConstructor
public class CopySearchResult {
private int totalNum;
private String keyword;
private String type;
private List<CopyRes> data;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/shop/hooking/hooking/entity/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.sun.istack.NotNull;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.*;

import org.springframework.data.annotation.CreatedDate;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;


Expand All @@ -19,6 +19,7 @@
@Entity
@DynamicInsert
@Table(name="card")
@OnDelete(action = OnDeleteAction.CASCADE)
public class Card {

@Id
Expand Down

0 comments on commit 6712242

Please sign in to comment.