Skip to content

Commit

Permalink
Merge pull request #51 from Central-MakeUs/dev
Browse files Browse the repository at this point in the history
fix: 지그재그 분류 체계에 맞춰 수정
  • Loading branch information
KarmaPol authored Feb 15, 2024
2 parents 1023e92 + adb1f44 commit 76cb59f
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 66 deletions.
3 changes: 2 additions & 1 deletion api/http/test.http
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ GET http://localhost:8080/api/v1/items?page=2
GET http://localhost:8080/api/v1/items/1

### 어드민 크롤링 기능
POST http://localhost:8080/api/v1/admin/items/crawl?url=https://s.zigzag.kr/f2KRWpFiXx
POST http://localhost:8080/api/v1/admin/items/crawl?
url=https://zigzag.kr/catalog/products/131506009

### 카카오 로그인
GET http://localhost:8080/api/v1/auth/login/kakao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,66 @@ public enum ItemCategoryType {
private final String value;
private final Integer refundPercent;
private static final List<String> TopsList = List.of(
"상의",
"아우터",
"원피스",
"니트/카디건",
"투피스/세트");
"티셔츠",
"니트/스웨터",
"셔츠",
"블라우스",
"맨투맨/스웨트셔츠",
"후드",
"민소매/슬리브리스",
"카디건",
"재킷",
"레더재킷",
"트위드재킷",
"코트",
"숏패딩",
"롱패딩",
"경량 패딩",
"트렌치코트",
"사파리/헌팅재킷",
"점퍼",
"무스탕",
"베스트",
"레인코트",
"미니원피스",
"미디원피스",
"롱원피스",
"라운드 니트",
"브이넥 니트",
"터틀넥 니트",
"오프숄더 니트",
"스퀘어넥 니트",
"니트 베스트",
"니트원피스",
"카디건",
"트레이닝 상의",
"트레이닝 세트",
"시밀러룩",
"스커트 세트",
"팬츠 세트",
"원피스 세트",
"임부복 상의",
"임부복 아우터",
"임부복 원피스"
);
private static final List<String> BottomsList = List.of(
"바지",
"스커트");
"일자팬츠",
"슬랙스팬츠",
"숏팬츠",
"와이드팬츠",
"스키니팬츠",
"부츠컷팬츠",
"조거팬츠",
"점프수트",
"레깅스",
"기타팬츠",
"미니스커트",
"미디스커트",
"롱스커트",
"트레이닝 하의",
"임부복 스커트",
"임부복 바지"
);

ItemCategoryType(String value, Integer refundPercent) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
package com.mm.coreinfrafeign.crawler.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mm.coredomain.domain.Item;
import com.mm.coredomain.domain.ItemCategoryType;
import com.mm.coredomain.domain.ItemImage;
import com.mm.coreinfrafeign.crawler.client.ZigZagCrawlerClient;
import com.mm.coreinfrafeign.crawler.dto.requset.ZigZagCrawlerRequest;
import com.mm.coreinfrafeign.crawler.dto.response.ZigZagCrawlerResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import lombok.RequiredArgsConstructor;

@Service
@Transactional
@RequiredArgsConstructor
public class CrawlerService {
private final ZigZagCrawlerClient zigZagCrawlerClient;

public Item getZigZagItemByCrawler(String redirectUrl) {
ZigZagCrawlerResponse response = zigZagCrawlerClient.call(new ZigZagCrawlerRequest(redirectUrl));

ItemCategoryType categoryType = getCategoryType(response);

Item item = Item.builder()
.price(response.finalPrice())
.title(response.name())
.redirectUrl(response.pageUrl())
.categoryType(categoryType)
.refund(getRefundPrice(response.finalPrice(), categoryType.getRefundPercent()))
.thumbnailUrl(response.thumbnailUrl())
.build();

List<ItemImage> itemImages = response.productImageList()
.stream()
.map(image -> ItemImage.builder()
.item(item)
.url(image.url())
.build())
.toList();

item.setItemImages(itemImages);
return item;
}

private static ItemCategoryType getCategoryType(ZigZagCrawlerResponse response) {
String itemCategory = response.managedCategoryList().get(0).value();
if (itemCategory.equals("패션의류")) {
itemCategory = response.managedCategoryList().get(1).value();
return ItemCategoryType.fromValueForClothes(itemCategory);
}

return ItemCategoryType.fromValue(itemCategory);
}

private Integer getRefundPrice(Integer price, Integer percent) {
return price * percent / 100;
}
private final ZigZagCrawlerClient zigZagCrawlerClient;

public Item getZigZagItemByCrawler(String redirectUrl) {
ZigZagCrawlerResponse response = zigZagCrawlerClient.call(new ZigZagCrawlerRequest(redirectUrl));

ItemCategoryType categoryType = getCategoryType(response);

Item item = Item.builder()
.price(response.finalPrice())
.title(response.name())
.redirectUrl(response.pageUrl())
.categoryType(categoryType)
.refund(getRefundPrice(response.finalPrice(), categoryType.getRefundPercent()))
.thumbnailUrl(response.thumbnailUrl())
.build();

List<ItemImage> itemImages = response.productImageList()
.stream()
.map(image -> ItemImage.builder()
.item(item)
.url(image.url())
.build())
.toList();

item.setItemImages(itemImages);
return item;
}

private static ItemCategoryType getCategoryType(ZigZagCrawlerResponse response) {
String itemCategory = response.managedCategoryList().get(0).value();
if (itemCategory.equals("패션의류")) {
itemCategory = response.managedCategoryList().get(2).value();
return ItemCategoryType.fromValueForClothes(itemCategory);
}

return ItemCategoryType.fromValue(itemCategory);
}

private Integer getRefundPrice(Integer price, Integer percent) {
return price * percent / 100;
}
}
12 changes: 0 additions & 12 deletions core/core-infra-qdsl/src/main/resources/data.sql

This file was deleted.

12 changes: 12 additions & 0 deletions core/core-infra-rdb/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
insert into permission(id, name) values(1, 'ROLE_ADMIN');
insert into permission(id, name) values(2, 'ROLE_USER');

insert into member_groups(id, name) values(1, 'ADMIN_GROUP');
insert into member_groups(id, name) values(2, 'USER_GROUP');

insert into group_permission(id, member_groups_id, permission_id) values(1, 1, 1);
insert into group_permission(id, member_groups_id, permission_id) values(2, 1, 2);
insert into group_permission(id, member_groups_id, permission_id) values(3, 2, 2);

insert into member(id, name, email, point, member_groups_id)
values(1, 'test', 'test@test', 10000000, 1);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring:
spring:
config:
activate:
on-profile: prod
on-profile: prod, stage
data:
redis:
port: 6379
Expand Down

0 comments on commit 76cb59f

Please sign in to comment.