Skip to content

Commit

Permalink
Merge pull request #65 from Hooking-CEOS/feature/brand
Browse files Browse the repository at this point in the history
[fix] 주석 및 불필요 문장 제거
  • Loading branch information
CYJhub authored Jul 22, 2023
2 parents fb3934d + 2fa5bf7 commit a3f3bd5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ public class BrandController {

// 전체 브랜드 기본정보 조회
@GetMapping("")
public HttpRes<List<BrandRes.BrandDto>> showAllBrand(){ // 로그인하지 않은 모든 사용자가 이용할 수 있음
public HttpRes<List<BrandRes.BrandDto>> showAllBrand(){
List<BrandRes.BrandDto> brandDtoList = brandService.getBrandList();

return new HttpRes<>(brandDtoList); // 브랜드 기본정보 반환
return new HttpRes<>(brandDtoList);
}

// 해당 브랜드 상세정보 조회
@PostMapping("/{brand_id}")
public HttpRes<BrandRes.BrandDetailDto> showOneBrand(@PathVariable Long brand_id){ // 로그인하지 않은 모든 사용자가 이용할 수 있음
public HttpRes<BrandRes.BrandDetailDto> showOneBrand(@PathVariable Long brand_id){
BrandRes.BrandDetailDto brandDetailDto = brandService.getOneBrand(brand_id);

return new HttpRes<>(brandDetailDto); // 브랜드 상세정보 반환
return new HttpRes<>(brandDetailDto);
}

// // 해당 브랜드 팔로우
Expand Down
34 changes: 11 additions & 23 deletions src/main/java/shop/hooking/hooking/controller/CopyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class CopyController {
public HttpRes<List<CopyRes>> copyList() {
Long[] brandIds = {2L, 3L, 4L, 12L, 15L, 17L, 21L, 24L, 25L, 28L};

List<CopyRes> limitedCopyRes = new ArrayList<>();
List<CopyRes> tempCopyRes = new ArrayList<>();

for (Long brandId : brandIds) {
Expand Down Expand Up @@ -87,7 +86,7 @@ public CopySearchResponse copySearchList(@RequestParam(name = "keyword") String

textCopyRes = copyService.selectCopyByQuery(q);

if (moodType != null) { // 무드 키워드가 있다면
if (moodType != null) {
moodCopyRes = copyService.selectMoodByQuery(q);
Collections.shuffle(moodCopyRes);
CopySearchResult moodResult = createCopySearchResult(moodCopyRes);
Expand All @@ -103,14 +102,14 @@ public CopySearchResponse copySearchList(@RequestParam(name = "keyword") String
setIndicesForCopyRes(textCopyRes, q);
results.add(copyResult);
}
} else if (BrandType.containsKeyword(q)) { // 브랜드에 키워드가 있다면
} else if (BrandType.containsKeyword(q)) {
brandCopyRes = copyService.selectBrandByQuery(q);
Collections.shuffle(brandCopyRes);
CopySearchResult brandResult = createCopySearchResult(brandCopyRes);
brandResult.setType("brand");
brandResult.setKeyword(q);
results.add(brandResult);
} else if (!textCopyRes.isEmpty()){ // text만 있다면
} else if (!textCopyRes.isEmpty()){
Collections.shuffle(textCopyRes);
CopySearchResult copyResult = createCopySearchResult(textCopyRes);
copyResult.setType("copy");
Expand All @@ -119,7 +118,7 @@ public CopySearchResponse copySearchList(@RequestParam(name = "keyword") String
results.add(copyResult);
}

if (results.isEmpty()) { //검색 결과가 없다면
if (results.isEmpty()) {
response.setCode(HttpStatus.BAD_REQUEST.value());
response.setMessage("검색 결과를 찾을 수 없습니다.");
response.setData(results);
Expand All @@ -134,7 +133,7 @@ public CopySearchResponse copySearchList(@RequestParam(name = "keyword") String

private CopySearchResult createCopySearchResult(List<CopyRes> copyResList) {
CopySearchResult result = new CopySearchResult();
int endIndex = Math.min(30, copyResList.size()); // 최대 30개까지만 반환
int endIndex = Math.min(30, copyResList.size());
List<CopyRes> limitedCopyRes = copyResList.subList(0, endIndex);
result.setData(limitedCopyRes);
return result;
Expand All @@ -143,45 +142,37 @@ private CopySearchResult createCopySearchResult(List<CopyRes> copyResList) {

private void setIndicesForCopyRes(List<CopyRes> copyResList, String keyword) {
for (CopyRes copyRes : copyResList) {
String lowercaseText = copyRes.getText().toLowerCase(); // 소문자로 변환
int index = lowercaseText.indexOf(keyword.toLowerCase()); // 첫번째 키워드의 위치 인덱스를 찾은 후,
String lowercaseText = copyRes.getText().toLowerCase();
int index = lowercaseText.indexOf(keyword.toLowerCase());
List<Integer> indices = new ArrayList<>();
while (index != -1) { // index가 -1이 아닐 때까지
while (index != -1) {
indices.add(index);
index = lowercaseText.indexOf(keyword.toLowerCase(), index + 1); // 키워드 위치 인덱스를 indices에 추가
index = lowercaseText.indexOf(keyword.toLowerCase(), index + 1);
}
copyRes.setIndex(indices);
}
}







// 스크랩한 카피라이팅 조회
@CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000/, http://localhost:3001/")
@GetMapping("/scrap")
public HttpRes<List<CopyRes>> copyScrapList(HttpServletRequest httpRequest) {
User user = jwtTokenProvider.getUserInfoByToken(httpRequest);
List<CopyRes> copyRes = copyService.getCopyScrapList(user);

int endIndex = Math.min(30, copyRes.size()); // 최대 30개까지만 반환
int endIndex = Math.min(30, copyRes.size());
List<CopyRes> limitedCopyRes = copyRes.subList(0, endIndex);

return new HttpRes<>(limitedCopyRes);
}



// 카피라이팅 스크랩
@CrossOrigin(origins = "https://hooking.shop, https://hooking-dev.netlify.app/, https://hooking.netlify.app/, http://localhost:3000/, http://localhost:3001/")
@PostMapping("/scrap")
public 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); // 스크랩됐으면->true, 안됐으면->false
boolean isScrap = copyService.saveCopy(user, card);
if(isScrap){
return new HttpRes<>("스크랩을 완료하였습니다.");
}
Expand All @@ -207,8 +198,6 @@ public HttpRes<String> saveCrawling(@RequestBody CrawlingReq crawlingReq) {

Card card = new Card();


// 'text'와 'createdAt' 값을 데이터베이스에 저장
card.setText(text);
card.setCreatedAt(createdAt);
card.setBrand(brand);
Expand All @@ -221,7 +210,6 @@ public HttpRes<String> saveCrawling(@RequestBody CrawlingReq crawlingReq) {
}


//카피라이팅 필터
@GetMapping("/filter")
public HttpRes<List<CopyRes>> searchFilterCard(CardSearchCondition condition) {
List<CopyRes> results = cardJpaRepository.search(condition);
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/shop/hooking/hooking/service/BrandService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ public class BrandService {

public List<BrandRes.BrandDto> getBrandList(){
List<BrandRes.BrandDto> brandDtoList = new ArrayList<>();
List<Brand> brands = brandRepository.findAll();// 데이터베이스에서 모든 브랜드 기본정보 가져옴
//무드 테이블에서 분위기 3개
//카드 테이블에서 카피라이팅 본문만 랜덤 1개 -> 완료
List<Brand> brands = brandRepository.findAll();

for( Brand brand : brands){
Long brandId = brand.getId();
List<Card> cards = cardRepository.findCardsByBrandId(brandId);
Card randomCard = cards.get(0); // 임의로 첫번재 카드 본문 가져오게 만듦
Card randomCard = cards.get(0);

List<Have> haves = haveRepository.findByBrandId(brandId);

Expand All @@ -59,13 +58,9 @@ public List<BrandRes.BrandDto> getBrandList(){


public BrandRes.BrandDetailDto getOneBrand(Long id) {
//무드 테이블에서 분위기 3개
//카드 테이블에서 카피라이팅 본문 랜덤 3개
//카드 테이블에서 카피라이팅 전체 가져오기

Brand brand = brandRepository.findBrandById(id);// brand 엔티티에서 4개(아이디, 이름, 한줄소개, 링크)만 가져옴
Brand brand = brandRepository.findBrandById(id);

List<Card> cards = cardRepository.findCardsByBrandId(brand.getId()); //카드 리스트 가져옴
List<Card> cards = cardRepository.findCardsByBrandId(brand.getId());

List<String> cardTexts = new ArrayList<>();
int maxCardCount = Math.min(cards.size(), 3);
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/shop/hooking/hooking/service/CopyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public List<CopyRes> selectMoodByQuery(String q){

List<Brand> brands = new ArrayList<>();
for (Have have : haves) {
brands.add(have.getBrand()); // 브랜드 다 가져오고
brands.add(have.getBrand());
}
for ( Brand brand : brands){
List<Card> cards = cardRepository.findCardsByBrandId(brand.getId()); // 카드 다 가져오고
List<Card> cards = cardRepository.findCardsByBrandId(brand.getId());

for (Card card : cards) {
CopyRes copyRes = createCopyRes(card);
copyResList.add(copyRes); // 리스트 형태로 반환
copyResList.add(copyRes);
}
}

Expand All @@ -116,7 +116,7 @@ public List<CopyRes> getCopyScrapList(User user) {
public CopyRes createCopyRes(Card card) {
Long id = card.getId(); // id로 넘어옴

List<Scrap> scraps = scrapRepository.findByCardId(id); // 스크랩 객체들 모두 불러옴
List<Scrap> scraps = scrapRepository.findByCardId(id);
int length = scraps.size();

Brand brand = card.getBrand();
Expand All @@ -128,9 +128,9 @@ public CopyRes createCopyRes(Card card) {

@Transactional
public CopyRes createScrapRes(Scrap scrap) {
Long id = scrap.getCard().getId(); // cardId
Long id = scrap.getCard().getId();

List<Scrap> scraps = scrapRepository.findByCardId(id); // 스크랩 객체들 모두 불러옴
List<Scrap> scraps = scrapRepository.findByCardId(id);
int length = scraps.size();

Brand brand = scrap.getCard().getBrand();
Expand All @@ -157,7 +157,4 @@ public boolean saveCopy(User user, Card card) throws IOException {
return true;
}




}

0 comments on commit a3f3bd5

Please sign in to comment.