-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Central-MakeUs/dev
fix: 지그재그 분류 체계에 맞춰 수정
- Loading branch information
Showing
4 changed files
with
167 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 59 additions & 49 deletions
108
core/core-domain/src/main/java/com/mm/coredomain/domain/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ItemImage> itemImages = new ArrayList<ItemImage>(); | ||
@Builder.Default | ||
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<ItemImage> itemImages = new ArrayList<ItemImage>(); | ||
|
||
@Builder.Default | ||
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<ItemVideo> itemVideos = new ArrayList<ItemVideo>(); | ||
@Builder.Default | ||
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<ItemVideo> itemVideos = new ArrayList<ItemVideo>(); | ||
|
||
public void setItemImages(List<ItemImage> itemImages) { | ||
this.itemImages.clear(); | ||
itemImages.forEach(itemImage -> this.itemImages.add(itemImage)); | ||
} | ||
public void setItemImages(List<ItemImage> itemImages) { | ||
this.itemImages.clear(); | ||
itemImages.forEach(itemImage -> this.itemImages.add(itemImage)); | ||
} | ||
|
||
public void setItemVideos(List<ItemVideo> itemVideos) { | ||
this.itemVideos.clear(); | ||
itemVideos.forEach(itemVideo -> this.itemVideos.add(itemVideo)); | ||
} | ||
public void setItemVideos(List<ItemVideo> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 47 additions & 45 deletions
92
.../core-infra-feign/src/main/java/com/mm/coreinfrafeign/crawler/service/CrawlerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |