From a3ec6b0e19b7f92aebc11d03e91a01599a46f01c Mon Sep 17 00:00:00 2001 From: KarmaPol Date: Wed, 14 Feb 2024 21:41:43 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20data=20sql=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core-infra-qdsl/src/main/resources/data.sql | 12 ------------ core/core-infra-rdb/src/main/resources/data.sql | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 core/core-infra-qdsl/src/main/resources/data.sql create mode 100644 core/core-infra-rdb/src/main/resources/data.sql diff --git a/core/core-infra-qdsl/src/main/resources/data.sql b/core/core-infra-qdsl/src/main/resources/data.sql deleted file mode 100644 index 71d004d..0000000 --- a/core/core-infra-qdsl/src/main/resources/data.sql +++ /dev/null @@ -1,12 +0,0 @@ -insert into permission(id, name) values(1, 'ROLE_ADMIN'); -insert into permission(id, name) values(2, 'ROLE_USER'); - -insert into groups(id, name) values(1, 'ADMIN_GROUP'); -insert into groups(id, name) values(2, 'USER_GROUP'); - -insert into group_permission(id, groups_id, permission_id) values(1, 1, 1); -insert into group_permission(id, groups_id, permission_id) values(2, 1, 2); -insert into group_permission(id, groups_id, permission_id) values(3, 2, 2); - -insert into member(id, name, email, point, groups_id) -values(1, 'test', 'test@test', 10000000, 1); diff --git a/core/core-infra-rdb/src/main/resources/data.sql b/core/core-infra-rdb/src/main/resources/data.sql new file mode 100644 index 0000000..01ae6c0 --- /dev/null +++ b/core/core-infra-rdb/src/main/resources/data.sql @@ -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); From adb1f449028991260a6b4afe86d8ca33eb0e48f3 Mon Sep 17 00:00:00 2001 From: KarmaPol Date: Thu, 15 Feb 2024 22:12:14 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=EC=A7=80=EA=B7=B8=EC=9E=AC=EA=B7=B8?= =?UTF-8?q?=20=EB=B6=84=EB=A5=98=20=EC=B2=B4=EA=B3=84=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EC=B6=B0=20=EB=B6=84=EB=A5=98=20=EC=B2=B4=EA=B3=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/http/test.http | 3 +- .../coredomain/domain/ItemCategoryType.java | 66 +++++++++++-- .../crawler/service/CrawlerService.java | 92 ++++++++++--------- 3 files changed, 108 insertions(+), 53 deletions(-) diff --git a/api/http/test.http b/api/http/test.http index ccd84e6..74e7fc7 100644 --- a/api/http/test.http +++ b/api/http/test.http @@ -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 diff --git a/core/core-domain/src/main/java/com/mm/coredomain/domain/ItemCategoryType.java b/core/core-domain/src/main/java/com/mm/coredomain/domain/ItemCategoryType.java index d50cebd..e0b4951 100644 --- a/core/core-domain/src/main/java/com/mm/coredomain/domain/ItemCategoryType.java +++ b/core/core-domain/src/main/java/com/mm/coredomain/domain/ItemCategoryType.java @@ -15,14 +15,66 @@ public enum ItemCategoryType { private final String value; private final Integer refundPercent; private static final List TopsList = List.of( - "상의", - "아우터", - "원피스", - "니트/카디건", - "투피스/세트"); + "티셔츠", + "니트/스웨터", + "셔츠", + "블라우스", + "맨투맨/스웨트셔츠", + "후드", + "민소매/슬리브리스", + "카디건", + "재킷", + "레더재킷", + "트위드재킷", + "코트", + "숏패딩", + "롱패딩", + "경량 패딩", + "트렌치코트", + "사파리/헌팅재킷", + "점퍼", + "무스탕", + "베스트", + "레인코트", + "미니원피스", + "미디원피스", + "롱원피스", + "라운드 니트", + "브이넥 니트", + "터틀넥 니트", + "오프숄더 니트", + "스퀘어넥 니트", + "니트 베스트", + "니트원피스", + "카디건", + "트레이닝 상의", + "트레이닝 세트", + "시밀러룩", + "스커트 세트", + "팬츠 세트", + "원피스 세트", + "임부복 상의", + "임부복 아우터", + "임부복 원피스" + ); private static final List BottomsList = List.of( - "바지", - "스커트"); + "일자팬츠", + "슬랙스팬츠", + "숏팬츠", + "와이드팬츠", + "스키니팬츠", + "부츠컷팬츠", + "조거팬츠", + "점프수트", + "레깅스", + "기타팬츠", + "미니스커트", + "미디스커트", + "롱스커트", + "트레이닝 하의", + "임부복 스커트", + "임부복 바지" + ); ItemCategoryType(String value, Integer refundPercent) { this.value = value; diff --git a/core/core-infra-feign/src/main/java/com/mm/coreinfrafeign/crawler/service/CrawlerService.java b/core/core-infra-feign/src/main/java/com/mm/coreinfrafeign/crawler/service/CrawlerService.java index 8478074..b0da8ea 100644 --- a/core/core-infra-feign/src/main/java/com/mm/coreinfrafeign/crawler/service/CrawlerService.java +++ b/core/core-infra-feign/src/main/java/com/mm/coreinfrafeign/crawler/service/CrawlerService.java @@ -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 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 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; + } } From ba52c5da279404d1a2cd68aa7a5c4c9fe75369f7 Mon Sep 17 00:00:00 2001 From: KarmaPol Date: Thu, 15 Feb 2024 22:16:28 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20item=20=ED=95=98=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mm/coredomain/domain/Item.java | 108 ++++++++++-------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/core/core-domain/src/main/java/com/mm/coredomain/domain/Item.java b/core/core-domain/src/main/java/com/mm/coredomain/domain/Item.java index c76136d..6e761a4 100644 --- a/core/core-domain/src/main/java/com/mm/coredomain/domain/Item.java +++ b/core/core-domain/src/main/java/com/mm/coredomain/domain/Item.java @@ -1,76 +1,86 @@ package com.mm.coredomain.domain; -import jakarta.persistence.*; -import lombok.*; -import org.hibernate.annotations.SQLDelete; - import java.util.ArrayList; import java.util.List; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + @Entity @Getter @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor -@SQLDelete(sql = "UPDATE item SET deleted = true WHERE id = ?") public class Item extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - private String title; + private String title; - @Lob - private String redirectUrl; + @Lob + private String redirectUrl; - @Enumerated(value = EnumType.STRING) - private ItemCategoryType categoryType; + @Enumerated(value = EnumType.STRING) + private ItemCategoryType categoryType; - private Integer price; + private Integer price; - private Integer refund; + private Integer refund; - private Double rating; + private Double rating; - @Lob - private String thumbnailUrl; + @Lob + private String thumbnailUrl; - @Builder.Default - private Boolean isSuggested = false; + @Builder.Default + private Boolean isSuggested = false; - @Builder.Default - @OneToMany(mappedBy = "item", cascade = CascadeType.ALL, orphanRemoval = true) - private List itemImages = new ArrayList(); + @Builder.Default + @OneToMany(mappedBy = "item", cascade = CascadeType.ALL, orphanRemoval = true) + private List itemImages = new ArrayList(); - @Builder.Default - @OneToMany(mappedBy = "item", cascade = CascadeType.ALL, orphanRemoval = true) - private List itemVideos = new ArrayList(); + @Builder.Default + @OneToMany(mappedBy = "item", cascade = CascadeType.ALL, orphanRemoval = true) + private List itemVideos = new ArrayList(); - public void setItemImages(List itemImages) { - this.itemImages.clear(); - itemImages.forEach(itemImage -> this.itemImages.add(itemImage)); - } + public void setItemImages(List itemImages) { + this.itemImages.clear(); + itemImages.forEach(itemImage -> this.itemImages.add(itemImage)); + } - public void setItemVideos(List itemVideos) { - this.itemVideos.clear(); - itemVideos.forEach(itemVideo -> this.itemVideos.add(itemVideo)); - } + public void setItemVideos(List itemVideos) { + this.itemVideos.clear(); + itemVideos.forEach(itemVideo -> this.itemVideos.add(itemVideo)); + } - public void setItemSuggested() { - this.isSuggested = true; - } + public void setItemSuggested() { + this.isSuggested = true; + } - public void setItemNotSuggested() { - this.isSuggested = false; - } + public void setItemNotSuggested() { + this.isSuggested = false; + } - public void updateItem(ItemUpdate itemUpdate) { - this.title = itemUpdate.title(); - this.redirectUrl = itemUpdate.redirectUrl(); - this.categoryType = itemUpdate.categoryType(); - this.price = itemUpdate.price(); - this.refund = itemUpdate.refund(); - this.rating = itemUpdate.rating(); - this.thumbnailUrl = itemUpdate.thumbnailUrl(); - } + public void updateItem(ItemUpdate itemUpdate) { + this.title = itemUpdate.title(); + this.redirectUrl = itemUpdate.redirectUrl(); + this.categoryType = itemUpdate.categoryType(); + this.price = itemUpdate.price(); + this.refund = itemUpdate.refund(); + this.rating = itemUpdate.rating(); + this.thumbnailUrl = itemUpdate.thumbnailUrl(); + } }