From 1562113bbe1607ed0006a707f641ec471c25c9d3 Mon Sep 17 00:00:00 2001 From: junker Date: Tue, 15 Aug 2023 21:28:16 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Item=20=EA=B4=80=EB=A0=A8=20of,=20to?= =?UTF-8?q?Entity=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/closet/service/ClosetService.java | 35 +--- .../item/controller/ItemController.java | 8 +- .../item/dto/HashtagPostResponseDto.java | 17 +- .../domain/item/dto/HashtagRequestDto.java | 7 +- .../domain/item/dto/HashtagResponseDto.java | 20 +- .../domain/item/dto/HotPlaceResDto.java | 6 + .../dto/ItemCategoryChildResponseDto.java | 18 +- .../domain/item/dto/ItemCategoryDto.java | 18 ++ .../dto/ItemCategoryParentResponseDto.java | 21 ++- .../domain/item/dto/ItemDetailResDto.java | 44 ++++- .../server/domain/item/dto/ItemImgResDto.java | 18 ++ .../domain/item/dto/ItemLinkResDto.java | 16 ++ .../domain/item/dto/ItemPostResDto.java | 6 + .../domain/item/dto/PlaceRankResDto.java | 7 + .../domain/item/dto/TempItemPostResDto.java | 6 + .../domain/item/dto/TempItemResDto.java | 29 ++- .../server/domain/item/entity/DayHotItem.java | 11 +- .../domain/item/entity/EfficientItem.java | 11 +- .../sluv/server/domain/item/entity/Item.java | 75 +++++--- .../domain/item/entity/ItemCategory.java | 9 +- .../domain/item/entity/ItemEditReq.java | 18 +- .../server/domain/item/entity/ItemImg.java | 20 +- .../server/domain/item/entity/ItemLike.java | 13 +- .../server/domain/item/entity/ItemLink.java | 19 +- .../server/domain/item/entity/ItemReport.java | 26 +-- .../server/domain/item/entity/ItemScrap.java | 13 +- .../server/domain/item/entity/LuxuryItem.java | 12 +- .../server/domain/item/entity/PlaceRank.java | 16 +- .../server/domain/item/entity/RecentItem.java | 10 +- .../server/domain/item/entity/TempItem.java | 46 ++--- .../domain/item/entity/TempItemImg.java | 20 +- .../domain/item/entity/TempItemLink.java | 20 +- .../domain/item/entity/WeekHotItem.java | 12 +- .../domain/item/entity/hashtag/Hashtag.java | 13 +- .../item/entity/hashtag/ItemHashtag.java | 13 +- .../item/entity/hashtag/TempItemHashtag.java | 13 +- .../domain/item/service/HashtagService.java | 27 +-- .../item/service/ItemCategoryService.java | 14 +- .../item/service/ItemEditReqService.java | 7 +- .../item/service/ItemReportService.java | 8 +- .../domain/item/service/ItemService.java | 172 +++++------------- .../domain/item/service/PlaceRankService.java | 11 +- .../domain/item/service/TempItemService.java | 118 ++++-------- .../question/service/QuestionService.java | 20 +- .../domain/search/service/SearchService.java | 21 +-- .../domain/user/service/UserService.java | 23 +-- .../server/global/scheduler/Scheduler.java | 16 +- 47 files changed, 551 insertions(+), 552 deletions(-) diff --git a/src/main/java/com/sluv/server/domain/closet/service/ClosetService.java b/src/main/java/com/sluv/server/domain/closet/service/ClosetService.java index b02831ab..efcbfaa8 100644 --- a/src/main/java/com/sluv/server/domain/closet/service/ClosetService.java +++ b/src/main/java/com/sluv/server/domain/closet/service/ClosetService.java @@ -108,10 +108,7 @@ public void postItemScrapToCloset(User user, Long itemId, Long closetId) { log.info("Save ItemScrap with item Id: {}, Closet Id {}", item.getId(), closet.getId()); ItemScrap saveItemScrap = itemScrapRepository.save( - ItemScrap.builder() - .item(item) - .closet(closet) - .build() + ItemScrap.toEntity(item, closet) ); log.info("Save Success with ItemScrap Id: {}", saveItemScrap.getId()); @@ -187,7 +184,7 @@ public ClosetDetailResDto getClosetDetails(User user, Long clo Page itemPage = itemRepository.getClosetItems(closet, pageable); - List content = getItemContent(itemPage); + List content = getItemContent(user, itemPage); return ClosetDetailResDto.builder() .hasNext(itemPage.hasNext()) @@ -204,27 +201,15 @@ public ClosetDetailResDto getClosetDetails(User user, Long clo } - private List getItemContent(Page itemPage) { - return itemPage.stream().map(item -> { + private List getItemContent(User user, Page itemPage) { + List closetList = closetRepository.findAllByUserId(user.getId()); + + return itemPage.stream() + .map(item -> { ItemImg mainImg = itemImgRepository.findMainImg(item.getId()); - return ItemSimpleResDto.builder() - .itemId(item.getId()) - .imgUrl(mainImg.getItemImgUrl()) - .brandName( - item.getBrand() != null - ? item.getBrand().getBrandKr() - : item.getNewBrand().getBrandName() - ) - .itemName(item.getName()) - .celebName( - item.getCeleb() != null - ? item.getCeleb().getCelebNameKr() - : item.getNewCeleb().getCelebName() - ) - .scrapStatus(true) - .build(); - } - ).toList(); + Boolean itemScrapStatus = itemScrapRepository.getItemScrapStatus(item, closetList); + return ItemSimpleResDto.of(item,mainImg, itemScrapStatus); + }).toList(); } public List getClosetList(User user) { diff --git a/src/main/java/com/sluv/server/domain/item/controller/ItemController.java b/src/main/java/com/sluv/server/domain/item/controller/ItemController.java index 02dcac3b..ae805cce 100644 --- a/src/main/java/com/sluv/server/domain/item/controller/ItemController.java +++ b/src/main/java/com/sluv/server/domain/item/controller/ItemController.java @@ -64,11 +64,11 @@ public ResponseEntity> postTempItem(@Aut return ResponseEntity.ok().body( SuccessDataResponse.builder() .result( - TempItemPostResDto.builder() - .tempItemId(tempItemService.postTempItem(user, reqDto)) - .build() + TempItemPostResDto.of( + tempItemService.postTempItem(user, reqDto) ) - .build() + ) + .build() ); } @Operation( diff --git a/src/main/java/com/sluv/server/domain/item/dto/HashtagPostResponseDto.java b/src/main/java/com/sluv/server/domain/item/dto/HashtagPostResponseDto.java index d5933a47..1ae279e4 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/HashtagPostResponseDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/HashtagPostResponseDto.java @@ -1,23 +1,24 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.hashtag.Hashtag; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Data @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder public class HashtagPostResponseDto { @Schema(description = "해쉬태그 id") private Long hashtagId; @Schema(description = "해쉬태그 내용") private String hashtagContent; - @Builder - public HashtagPostResponseDto(Long hashtagId, String hashtagContent) { - this.hashtagId = hashtagId; - this.hashtagContent = hashtagContent; + public static HashtagPostResponseDto of(Hashtag hashtag){ + return HashtagPostResponseDto.builder() + .hashtagId(hashtag.getId()) + .hashtagContent(hashtag.getContent()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/HashtagRequestDto.java b/src/main/java/com/sluv/server/domain/item/dto/HashtagRequestDto.java index 79c6b2d5..4acbbea9 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/HashtagRequestDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/HashtagRequestDto.java @@ -1,18 +1,17 @@ package com.sluv.server.domain.item.dto; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor +@AllArgsConstructor +@Builder public class HashtagRequestDto { @Schema(description = "새로 등록할 해쉬태그명") private String hashtagContent; - @Builder - public HashtagRequestDto(String hashtagContent) { - this.hashtagContent = hashtagContent; - } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/HashtagResponseDto.java b/src/main/java/com/sluv/server/domain/item/dto/HashtagResponseDto.java index c2e1cd58..aa20f829 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/HashtagResponseDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/HashtagResponseDto.java @@ -1,14 +1,14 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.hashtag.Hashtag; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Data @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder public class HashtagResponseDto { @Schema(description = "해쉬태그 id") private Long hashtagId; @@ -17,10 +17,12 @@ public class HashtagResponseDto { @Schema(description = "해쉬태그 누적수") private Long count; - @Builder - public HashtagResponseDto(Long hashtagId, String hashtagContent, Long count) { - this.hashtagId = hashtagId; - this.hashtagContent = hashtagContent; - this.count = count; + public static HashtagResponseDto of(Hashtag hashtag, Long count){ + return HashtagResponseDto.builder() + .hashtagId(hashtag.getId()) + .hashtagContent(hashtag.getContent()) + .count(count) + .build(); } + } diff --git a/src/main/java/com/sluv/server/domain/item/dto/HotPlaceResDto.java b/src/main/java/com/sluv/server/domain/item/dto/HotPlaceResDto.java index 81062881..fca476d5 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/HotPlaceResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/HotPlaceResDto.java @@ -13,4 +13,10 @@ public class HotPlaceResDto { @Schema(description = "장소명") private String placeName; + + public static HotPlaceResDto of(String placeName){ + return HotPlaceResDto.builder() + .placeName(placeName) + .build(); + } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryChildResponseDto.java b/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryChildResponseDto.java index 856b53e2..05d9aef9 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryChildResponseDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryChildResponseDto.java @@ -1,14 +1,14 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.ItemCategory; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Data @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder public class ItemCategoryChildResponseDto { @Schema(description = "하위 카테고리 Id") @@ -16,10 +16,10 @@ public class ItemCategoryChildResponseDto { @Schema(description = "하위 카테고리 이름") private String name; - - @Builder - public ItemCategoryChildResponseDto(Long id, String name) { - this.id = id; - this.name = name; + public static ItemCategoryChildResponseDto of(ItemCategory itemCategory){ + return ItemCategoryChildResponseDto.builder() + .id(itemCategory.getId()) + .name(itemCategory.getName()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryDto.java b/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryDto.java index 2eac68dd..62e8f8ea 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryDto.java @@ -1,5 +1,6 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.ItemCategory; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -17,4 +18,21 @@ public class ItemCategoryDto { private String name; @Schema(description = "아이템 상위 카테고리 이름") private String parentName; + + public static ItemCategoryDto of(ItemCategory itemCategory){ + return ItemCategoryDto.builder() + .id(itemCategory.getId()) + .name(itemCategory.getName()) + .parentId( + itemCategory.getParent() != null + ? itemCategory.getParent().getId() + : null + ) + .parentName( + itemCategory.getParent() != null + ? itemCategory.getParent().getName() + : null + ) + .build(); + } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryParentResponseDto.java b/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryParentResponseDto.java index 26df7622..515e52fe 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryParentResponseDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/ItemCategoryParentResponseDto.java @@ -1,16 +1,16 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.ItemCategory; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import java.util.List; @Data @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder public class ItemCategoryParentResponseDto { @Schema(description = "상위 카테고리 Id") @@ -20,10 +20,13 @@ public class ItemCategoryParentResponseDto { @Schema(description = "하위 카테고리 목록") private List subCategoryList; - @Builder - public ItemCategoryParentResponseDto(Long id, String name, List subCategoryList) { - this.id = id; - this.name = name; - this.subCategoryList = subCategoryList; + public static ItemCategoryParentResponseDto of(ItemCategory itemCategory, + List subCategoryList){ + + return ItemCategoryParentResponseDto.builder() + .id(itemCategory.getId()) + .name(itemCategory.getName()) + .subCategoryList(subCategoryList) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/ItemDetailResDto.java b/src/main/java/com/sluv/server/domain/item/dto/ItemDetailResDto.java index 8ccec352..9bc73059 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/ItemDetailResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/ItemDetailResDto.java @@ -1,7 +1,13 @@ package com.sluv.server.domain.item.dto; import com.sluv.server.domain.brand.dto.BrandSearchResDto; +import com.sluv.server.domain.brand.entity.Brand; +import com.sluv.server.domain.brand.entity.NewBrand; import com.sluv.server.domain.celeb.dto.CelebSearchResDto; +import com.sluv.server.domain.celeb.entity.Celeb; +import com.sluv.server.domain.celeb.entity.NewCeleb; +import com.sluv.server.domain.item.entity.Item; +import com.sluv.server.domain.item.entity.ItemCategory; import com.sluv.server.domain.user.dto.UserInfoDto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Size; @@ -84,8 +90,42 @@ public class ItemDetailResDto { @Schema(description = "현재 유저가 작성한 글인지 판단") private Boolean hasMine; - - + public static ItemDetailResDto of(Item item, CelebSearchResDto celeb, String newCelebName, + BrandSearchResDto brand, String newBrandName, ItemCategoryDto itemCategory, + Integer likeNum, Boolean likeStatus, Integer scrapNum, Boolean scrapStatus, + Long viewNum, UserInfoDto writerInfo, Boolean followStatus, Boolean hasMine, + List imgList, List linkList, List hashtagList, + List sameCelebItemList, List sameBrandItemList, List otherSluverItemList + ){ + + return ItemDetailResDto.builder() + .imgList(imgList) + .celeb(celeb) + .newCelebName(newCelebName) + .category(itemCategory) + .itemName(item.getName()) + .brand(brand) + .newBrandName(newBrandName) + .likeNum(likeNum) + .likeStatus(likeStatus) + .scrapNum(scrapNum) + .scrapStatus(scrapStatus) + .viewNum(viewNum) + .linkList(linkList) + .writer(writerInfo) + .whenDiscovery(item.getWhenDiscovery()) + .whereDiscovery(item.getWhereDiscovery()) + .price(item.getPrice()) + .additionalInfo(item.getAdditionalInfo()) + .hashTagList(hashtagList) + .infoSource(item.getInfoSource()) + .sameCelebItemList(sameCelebItemList) + .sameBrandItemList(sameBrandItemList) + .otherSluverItemList(otherSluverItemList) + .followStatus(followStatus) + .hasMine(hasMine) + .build(); + } diff --git a/src/main/java/com/sluv/server/domain/item/dto/ItemImgResDto.java b/src/main/java/com/sluv/server/domain/item/dto/ItemImgResDto.java index a067010c..f12e6358 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/ItemImgResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/ItemImgResDto.java @@ -1,5 +1,7 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.ItemImg; +import com.sluv.server.domain.item.entity.TempItemImg; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -16,4 +18,20 @@ public class ItemImgResDto { @Schema(description = "이미지 순서") private Integer sortOrder; + public static ItemImgResDto of(ItemImg itemImg){ + return ItemImgResDto.builder() + .imgUrl(itemImg.getItemImgUrl()) + .representFlag(itemImg.getRepresentFlag()) + .sortOrder(itemImg.getSortOrder()) + .build(); + } + + public static ItemImgResDto of(TempItemImg tempItemImg){ + return ItemImgResDto.builder() + .imgUrl(tempItemImg.getTempItemImgUrl()) + .representFlag(tempItemImg.getRepresentFlag()) + .sortOrder(tempItemImg.getSortOrder()) + .build(); + } + } diff --git a/src/main/java/com/sluv/server/domain/item/dto/ItemLinkResDto.java b/src/main/java/com/sluv/server/domain/item/dto/ItemLinkResDto.java index 02d7822a..99caa403 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/ItemLinkResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/ItemLinkResDto.java @@ -1,5 +1,7 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.ItemLink; +import com.sluv.server.domain.item.entity.TempItemLink; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -15,4 +17,18 @@ public class ItemLinkResDto { @Schema(description = "아이템 링크 이름") private String linkName; + public static ItemLinkResDto of(ItemLink itemLink){ + return ItemLinkResDto.builder() + .itemLinkUrl(itemLink.getItemLinkUrl()) + .linkName(itemLink.getLinkName()) + .build(); + } + + public static ItemLinkResDto of(TempItemLink tempItemLink ){ + return ItemLinkResDto.builder() + .itemLinkUrl(tempItemLink.getTempItemLinkUrl()) + .linkName(tempItemLink.getLinkName()) + .build(); + } + } diff --git a/src/main/java/com/sluv/server/domain/item/dto/ItemPostResDto.java b/src/main/java/com/sluv/server/domain/item/dto/ItemPostResDto.java index cae2f271..55104d68 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/ItemPostResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/ItemPostResDto.java @@ -13,4 +13,10 @@ public class ItemPostResDto { @Schema(description = "아이템 Id1") private Long itemId; + + public static ItemPostResDto of(Long itemId){ + return ItemPostResDto.builder() + .itemId(itemId) + .build(); + } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/PlaceRankResDto.java b/src/main/java/com/sluv/server/domain/item/dto/PlaceRankResDto.java index 2bded496..13713a71 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/PlaceRankResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/PlaceRankResDto.java @@ -1,5 +1,6 @@ package com.sluv.server.domain.item.dto; +import com.sluv.server.domain.item.entity.PlaceRank; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -13,4 +14,10 @@ public class PlaceRankResDto { @Schema(description = "입력한 장소 이름") private String placeName; + + public static PlaceRankResDto of(PlaceRank placeRank){ + return PlaceRankResDto.builder() + .placeName(placeRank.getPlace()) + .build(); + } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/TempItemPostResDto.java b/src/main/java/com/sluv/server/domain/item/dto/TempItemPostResDto.java index f1203c4b..5885899f 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/TempItemPostResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/TempItemPostResDto.java @@ -13,4 +13,10 @@ public class TempItemPostResDto { @Schema(description = "TempItem Id") private Long tempItemId; + + public static TempItemPostResDto of(Long tempItemId){ + return TempItemPostResDto.builder() + .tempItemId(tempItemId) + .build(); + } } diff --git a/src/main/java/com/sluv/server/domain/item/dto/TempItemResDto.java b/src/main/java/com/sluv/server/domain/item/dto/TempItemResDto.java index d0050808..68ed960b 100644 --- a/src/main/java/com/sluv/server/domain/item/dto/TempItemResDto.java +++ b/src/main/java/com/sluv/server/domain/item/dto/TempItemResDto.java @@ -4,8 +4,7 @@ import com.sluv.server.domain.brand.entity.Brand; import com.sluv.server.domain.celeb.dto.CelebDto; import com.sluv.server.domain.celeb.dto.NewCelebPostResDto; -import com.sluv.server.domain.celeb.entity.Celeb; -import com.sluv.server.domain.item.entity.ItemCategory; +import com.sluv.server.domain.item.entity.TempItem; import com.sluv.server.domain.item.entity.hashtag.Hashtag; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; @@ -15,7 +14,6 @@ import java.time.LocalDateTime; import java.util.List; -import java.util.Map; @Data @NoArgsConstructor @@ -62,4 +60,29 @@ public class TempItemResDto { @Schema(description = "최신 update 시점") private LocalDateTime updatedAt; + public static TempItemResDto of(TempItem tempItem, CelebDto celeb, NewCelebPostResDto newCeleb, + Brand brand, NewBrandPostResDto newBrand, ItemCategoryDto itemCategory, + List imgList, List linkList, List hashtagList + ){ + + return TempItemResDto.builder() + .id(tempItem.getId()) + .imgList(imgList) + .celeb(celeb) + .newCeleb(newCeleb) + .category(itemCategory) + .itemName(tempItem.getName()) + .brand(brand) + .newBrand(newBrand) + .linkList(linkList) + .whenDiscovery(tempItem.getWhenDiscovery()) + .whereDiscovery(tempItem.getWhereDiscovery()) + .price(tempItem.getPrice()) + .additionalInfo(tempItem.getAdditionalInfo()) + .hashTagList(hashtagList) + .infoSource(tempItem.getInfoSource()) + .updatedAt(tempItem.getUpdatedAt()) + .build(); + } + } diff --git a/src/main/java/com/sluv/server/domain/item/entity/DayHotItem.java b/src/main/java/com/sluv/server/domain/item/entity/DayHotItem.java index d326fc78..b5fcbf9b 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/DayHotItem.java +++ b/src/main/java/com/sluv/server/domain/item/entity/DayHotItem.java @@ -3,6 +3,7 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,6 +11,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "day_hot_item") public class DayHotItem extends BaseEntity { @@ -24,9 +27,9 @@ public class DayHotItem extends BaseEntity { private Item item; - @Builder - public DayHotItem(Long id, Item item) { - this.id = id; - this.item = item; + public static DayHotItem toEntity(Item item) { + return DayHotItem.builder() + .item(item) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/EfficientItem.java b/src/main/java/com/sluv/server/domain/item/entity/EfficientItem.java index 611ef30c..e44a8812 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/EfficientItem.java +++ b/src/main/java/com/sluv/server/domain/item/entity/EfficientItem.java @@ -3,6 +3,7 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,6 +11,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "efficient_item") public class EfficientItem extends BaseEntity { @@ -23,9 +26,9 @@ public class EfficientItem extends BaseEntity { private Item item; - @Builder - public EfficientItem(Long id, Item item) { - this.id = id; - this.item = item; + public static EfficientItem toEntity(Item item) { + return EfficientItem.builder() + .item(item) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/Item.java b/src/main/java/com/sluv/server/domain/item/entity/Item.java index b5d1212e..53fac368 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/Item.java +++ b/src/main/java/com/sluv/server/domain/item/entity/Item.java @@ -4,12 +4,14 @@ import com.sluv.server.domain.brand.entity.NewBrand; import com.sluv.server.domain.celeb.entity.Celeb; import com.sluv.server.domain.celeb.entity.NewCeleb; +import com.sluv.server.domain.item.dto.ItemPostReqDto; import com.sluv.server.domain.item.enums.ItemStatus; import com.sluv.server.domain.user.entity.User; import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -19,6 +21,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "item") public class Item extends BaseEntity { @@ -72,31 +76,60 @@ public class Item extends BaseEntity { @Column(columnDefinition = "TEXT") private String infoSource; + @Builder.Default @Column(name = "view_num") - private Long viewNum; + private Long viewNum = 0L; + @Builder.Default @Enumerated(EnumType.STRING) @Column(length = 45, columnDefinition = "varchar(45) default 'ACTIVE'") - private ItemStatus itemStatus; - - @Builder - public Item(Long id, User user, Celeb celeb, NewCeleb newCeleb, ItemCategory category, Brand brand, NewBrand newBrand, String name, LocalDateTime whenDiscovery, String whereDiscovery, int price, String color, String additionalInfo, String infoSource, Long viewNum, ItemStatus itemStatus) { - this.id = id; - this.user = user; - this.celeb = celeb; - this.newCeleb = newCeleb; - this.category = category; - this.brand = brand; - this.newBrand = newBrand; - this.name = name; - this.whenDiscovery = whenDiscovery; - this.whereDiscovery = whereDiscovery; - this.price = price; - this.color = color; - this.additionalInfo = additionalInfo; - this.infoSource = infoSource; - this.viewNum = viewNum; - this.itemStatus = itemStatus; + private ItemStatus itemStatus = ItemStatus.ACTIVE; + + /** + * Item 생성 + */ + public static Item toEntity(User user, Celeb celeb, NewCeleb newCeleb, + ItemCategory itemCategory, Brand brand, NewBrand newBrand, + ItemPostReqDto dto) { + return Item.builder() + .user(user) + .celeb(celeb) + .category(itemCategory) + .brand(brand) + .newBrand(newBrand) + .newCeleb(newCeleb) + .name(dto.getItemName()) + .whenDiscovery(dto.getWhenDiscovery()) + .whereDiscovery(dto.getWhereDiscovery()) + .price(dto.getPrice()) + .additionalInfo(dto.getAdditionalInfo()) + .infoSource(dto.getInfoSource()) + .build(); + + } + + /** + * Item 수정 + */ + public static Item toEntity(Long id, User user, Celeb celeb, NewCeleb newCeleb, + ItemCategory itemCategory, Brand brand, NewBrand newBrand, + ItemPostReqDto dto) { + return Item.builder() + .id(id) + .user(user) + .celeb(celeb) + .category(itemCategory) + .brand(brand) + .newBrand(newBrand) + .newCeleb(newCeleb) + .name(dto.getItemName()) + .whenDiscovery(dto.getWhenDiscovery()) + .whereDiscovery(dto.getWhereDiscovery()) + .price(dto.getPrice()) + .additionalInfo(dto.getAdditionalInfo()) + .infoSource(dto.getInfoSource()) + .build(); + } public void increaseViewNum(){ diff --git a/src/main/java/com/sluv/server/domain/item/entity/ItemCategory.java b/src/main/java/com/sluv/server/domain/item/entity/ItemCategory.java index 14378df5..12aeea18 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/ItemCategory.java +++ b/src/main/java/com/sluv/server/domain/item/entity/ItemCategory.java @@ -4,6 +4,7 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,6 +12,8 @@ @Entity @NoArgsConstructor +@AllArgsConstructor +@Builder @Getter @Table(name = "item_category") public class ItemCategory extends BaseEntity { @@ -27,10 +30,4 @@ public class ItemCategory extends BaseEntity { @JoinColumn(name = "parent_id") private ItemCategory parent; - @Builder - public ItemCategory(Long id, String name, ItemCategory parent) { - this.id = id; - this.name = name; - this.parent = parent; - } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/ItemEditReq.java b/src/main/java/com/sluv/server/domain/item/entity/ItemEditReq.java index 6be5f1c4..fc02bd3a 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/ItemEditReq.java +++ b/src/main/java/com/sluv/server/domain/item/entity/ItemEditReq.java @@ -1,17 +1,21 @@ package com.sluv.server.domain.item.entity; +import com.sluv.server.domain.item.dto.ItemEditReqDto; import com.sluv.server.domain.item.enums.ItemEditReqReason; import com.sluv.server.domain.user.entity.User; import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @NoArgsConstructor +@AllArgsConstructor +@Builder @Getter @Table(name = "item_edit_req") public class ItemEditReq extends BaseEntity { @@ -37,12 +41,12 @@ public class ItemEditReq extends BaseEntity { @Size(max = 1002) private String content; - @Builder - public ItemEditReq(Long id, User requester, Item item, ItemEditReqReason itemEditReqReason, String content) { - this.id = id; - this.requester = requester; - this.item = item; - this.itemEditReqReason = itemEditReqReason; - this.content = content; + public static ItemEditReq toEntity(User user, Item item, ItemEditReqDto dto){ + return ItemEditReq.builder() + .requester(user) + .item(item) + .itemEditReqReason(dto.getReason()) + .content(dto.getContent()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/ItemImg.java b/src/main/java/com/sluv/server/domain/item/entity/ItemImg.java index 368c37fa..0a394c5b 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/ItemImg.java +++ b/src/main/java/com/sluv/server/domain/item/entity/ItemImg.java @@ -1,9 +1,11 @@ package com.sluv.server.domain.item.entity; +import com.sluv.server.domain.item.dto.ItemImgResDto; import com.sluv.server.global.common.entity.BaseEntity; import com.sluv.server.global.common.enums.ItemImgOrLinkStatus; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,6 +14,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "item_img") public class ItemImg extends BaseEntity { @@ -32,6 +36,7 @@ public class ItemImg extends BaseEntity { @ColumnDefault("0") private Boolean representFlag; + @Builder.Default @Enumerated(EnumType.STRING) @Column(length = 45, columnDefinition = "varchar(45) default 'ACTIVE'") private ItemImgOrLinkStatus itemImgOrLinkStatus = ItemImgOrLinkStatus.ACTIVE; @@ -39,13 +44,12 @@ public class ItemImg extends BaseEntity { private Integer sortOrder; - @Builder - public ItemImg(Long id, Item item, String itemImgUrl, Boolean representFlag, ItemImgOrLinkStatus itemImgOrLinkStatus, Integer sortOrder) { - this.id = id; - this.item = item; - this.itemImgUrl = itemImgUrl; - this.representFlag = representFlag; - this.itemImgOrLinkStatus = itemImgOrLinkStatus; - this.sortOrder = sortOrder; + public static ItemImg toEntity(Item item, ItemImgResDto dto){ + return ItemImg.builder() + .item(item) + .itemImgUrl(dto.getImgUrl()) + .representFlag(dto.getRepresentFlag()) + .sortOrder(dto.getSortOrder()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/ItemLike.java b/src/main/java/com/sluv/server/domain/item/entity/ItemLike.java index 7f151cf4..e587621c 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/ItemLike.java +++ b/src/main/java/com/sluv/server/domain/item/entity/ItemLike.java @@ -4,6 +4,7 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,6 +12,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "item_like") public class ItemLike extends BaseEntity { @@ -29,10 +32,10 @@ public class ItemLike extends BaseEntity { private User user; - @Builder - public ItemLike(Long id, Item item, User user) { - this.id = id; - this.item = item; - this.user = user; + public static ItemLike toEntity(Item item, User user) { + return ItemLike.builder() + .item(item) + .user(user) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/ItemLink.java b/src/main/java/com/sluv/server/domain/item/entity/ItemLink.java index ce598be0..de444432 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/ItemLink.java +++ b/src/main/java/com/sluv/server/domain/item/entity/ItemLink.java @@ -1,10 +1,12 @@ package com.sluv.server.domain.item.entity; +import com.sluv.server.domain.item.dto.ItemLinkResDto; import com.sluv.server.global.common.entity.BaseEntity; import com.sluv.server.global.common.enums.ItemImgOrLinkStatus; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,6 +14,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "item_link") public class ItemLink extends BaseEntity { @@ -32,16 +36,17 @@ public class ItemLink extends BaseEntity { @Column(columnDefinition = "TEXT") private String itemLinkUrl; + @Builder.Default @Enumerated(EnumType.STRING) @Column(length = 45, columnDefinition = "varchar(45) default 'ACTIVE'") private ItemImgOrLinkStatus itemImgOrLinkStatus = ItemImgOrLinkStatus.ACTIVE; - @Builder - public ItemLink(Long id, Item item, String linkName, String itemLinkUrl, ItemImgOrLinkStatus itemImgOrLinkStatus) { - this.id = id; - this.item = item; - this.linkName = linkName; - this.itemLinkUrl = itemLinkUrl; - this.itemImgOrLinkStatus = itemImgOrLinkStatus; + + public static ItemLink toEntity(Item item , ItemLinkResDto dto){ + return ItemLink.builder() + .item(item) + .linkName(dto.getLinkName()) + .itemLinkUrl(dto.getItemLinkUrl()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/ItemReport.java b/src/main/java/com/sluv/server/domain/item/entity/ItemReport.java index 98d860e7..ce26da9b 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/ItemReport.java +++ b/src/main/java/com/sluv/server/domain/item/entity/ItemReport.java @@ -1,5 +1,6 @@ package com.sluv.server.domain.item.entity; +import com.sluv.server.domain.item.dto.ItemReportReqDto; import com.sluv.server.domain.item.enums.ItemReportReason; import com.sluv.server.domain.user.entity.User; import com.sluv.server.global.common.entity.BaseEntity; @@ -7,6 +8,7 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -14,6 +16,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "item_report") public class ItemReport extends BaseEntity { @@ -38,18 +42,16 @@ public class ItemReport extends BaseEntity { @Size(max = 1002) private String content; + @Builder.Default @Enumerated(EnumType.STRING) - @Column(length = 45, columnDefinition = "varchar(45) default 'WAITING'") - private ReportStatus reportStatus; - - - @Builder - public ItemReport(Long id, Item item, User reporter, ItemReportReason itemReportReason, String content, ReportStatus reportStatus) { - this.id = id; - this.item = item; - this.reporter = reporter; - this.itemReportReason = itemReportReason; - this.content = content; - this.reportStatus = reportStatus; + private ReportStatus reportStatus = ReportStatus.WAITING; + + public static ItemReport toEntity(Item item, User user, ItemReportReqDto dto){ + return ItemReport.builder() + .item(item) + .reporter(user) + .itemReportReason(dto.getReason()) + .content(dto.getContent()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/ItemScrap.java b/src/main/java/com/sluv/server/domain/item/entity/ItemScrap.java index 87aa1254..af012bd4 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/ItemScrap.java +++ b/src/main/java/com/sluv/server/domain/item/entity/ItemScrap.java @@ -4,6 +4,7 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,6 +12,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "item_scrap") public class ItemScrap extends BaseEntity { @@ -29,11 +32,11 @@ public class ItemScrap extends BaseEntity { private Closet closet; - @Builder - public ItemScrap(Long id, Item item, Closet closet) { - this.id = id; - this.item = item; - this.closet = closet; + public static ItemScrap toEntity(Item item, Closet closet) { + return ItemScrap.builder() + .item(item) + .closet(closet) + .build(); } public void changeCloset(Closet closet){ diff --git a/src/main/java/com/sluv/server/domain/item/entity/LuxuryItem.java b/src/main/java/com/sluv/server/domain/item/entity/LuxuryItem.java index c94d6434..5b092818 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/LuxuryItem.java +++ b/src/main/java/com/sluv/server/domain/item/entity/LuxuryItem.java @@ -4,6 +4,7 @@ import com.sluv.server.global.common.enums.ItemImgOrLinkStatus; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,6 +13,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "luxury_item") public class LuxuryItem extends BaseEntity { @@ -24,10 +27,9 @@ public class LuxuryItem extends BaseEntity { @NotNull private Item item; - - @Builder - public LuxuryItem(Long id, Item item) { - this.id = id; - this.item = item; + public static LuxuryItem toEntity(Item item) { + return LuxuryItem.builder() + .item(item) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/PlaceRank.java b/src/main/java/com/sluv/server/domain/item/entity/PlaceRank.java index ab5f62c6..c72897d0 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/PlaceRank.java +++ b/src/main/java/com/sluv/server/domain/item/entity/PlaceRank.java @@ -1,10 +1,12 @@ package com.sluv.server.domain.item.entity; +import com.sluv.server.domain.item.dto.PlaceRankReqDto; import com.sluv.server.domain.user.entity.User; import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,6 +14,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "place_rank") public class PlaceRank extends BaseEntity { @@ -28,12 +32,10 @@ public class PlaceRank extends BaseEntity { @Size(max = 255) private String place; - - - @Builder - public PlaceRank(Long id, User user, String place) { - this.id = id; - this.user = user; - this.place = place; + public static PlaceRank toEntity(User user, PlaceRankReqDto dto) { + return PlaceRank.builder() + .user(user) + .place(dto.getPlaceName()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/RecentItem.java b/src/main/java/com/sluv/server/domain/item/entity/RecentItem.java index 32d2e9d8..b510cd4c 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/RecentItem.java +++ b/src/main/java/com/sluv/server/domain/item/entity/RecentItem.java @@ -4,6 +4,7 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,6 +12,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "recent_item") public class RecentItem extends BaseEntity { @@ -28,11 +31,4 @@ public class RecentItem extends BaseEntity { @NotNull private User user; - - @Builder - public RecentItem(Long id, Item item, User user) { - this.id = id; - this.item = item; - this.user = user; - } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/TempItem.java b/src/main/java/com/sluv/server/domain/item/entity/TempItem.java index 6cf863f2..d7fd6dde 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/TempItem.java +++ b/src/main/java/com/sluv/server/domain/item/entity/TempItem.java @@ -4,16 +4,14 @@ import com.sluv.server.domain.brand.entity.NewBrand; import com.sluv.server.domain.celeb.entity.Celeb; import com.sluv.server.domain.celeb.entity.NewCeleb; +import com.sluv.server.domain.item.dto.TempItemPostReqDto; import com.sluv.server.domain.item.enums.ItemStatus; import com.sluv.server.domain.user.entity.User; import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import java.time.LocalDateTime; @@ -21,6 +19,8 @@ @Getter @Setter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "temp_item") public class TempItem extends BaseEntity { @@ -68,25 +68,27 @@ public class TempItem extends BaseEntity { @Column(columnDefinition = "TEXT") private String infoSource; + @Builder.Default @Enumerated(EnumType.STRING) @Column(length = 45, columnDefinition = "varchar(45) default 'ACTIVE'") - private ItemStatus itemStatus; - - @Builder - public TempItem(Long id, User user, Celeb celeb, NewCeleb newCeleb, ItemCategory category, Brand brand, NewBrand newBrand, String name, LocalDateTime whenDiscovery, String whereDiscovery, Integer price, String additionalInfo, String infoSource, ItemStatus itemStatus) { - this.id = id; - this.user = user; - this.celeb = celeb; - this.newCeleb = newCeleb; - this.category = category; - this.brand = brand; - this.newBrand = newBrand; - this.name = name; - this.whenDiscovery = whenDiscovery; - this.whereDiscovery = whereDiscovery; - this.price = price; - this.additionalInfo = additionalInfo; - this.infoSource = infoSource; - this.itemStatus = itemStatus; + private ItemStatus itemStatus = ItemStatus.ACTIVE; + + public static TempItem toEntity(User user, Celeb celeb, NewCeleb newCeleb, + ItemCategory category, Brand brand, NewBrand newBrand, + TempItemPostReqDto dto) { + return TempItem.builder() + .user(user) + .celeb(celeb) + .newCeleb(newCeleb) + .category(category) + .brand(brand) + .newBrand(newBrand) + .name(dto.getItemName()) + .whenDiscovery(dto.getWhenDiscovery()) + .whereDiscovery(dto.getWhereDiscovery()) + .price(dto.getPrice()) + .additionalInfo(dto.getAdditionalInfo()) + .infoSource(dto.getInfoSource()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/TempItemImg.java b/src/main/java/com/sluv/server/domain/item/entity/TempItemImg.java index 462793fc..43a5fa20 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/TempItemImg.java +++ b/src/main/java/com/sluv/server/domain/item/entity/TempItemImg.java @@ -1,9 +1,11 @@ package com.sluv.server.domain.item.entity; +import com.sluv.server.domain.item.dto.ItemImgResDto; import com.sluv.server.global.common.entity.BaseEntity; import com.sluv.server.global.common.enums.ItemImgOrLinkStatus; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,6 +14,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "temp_item_img") public class TempItemImg extends BaseEntity { @@ -31,6 +35,7 @@ public class TempItemImg extends BaseEntity { @ColumnDefault("0") private Boolean representFlag; + @Builder.Default @Enumerated(EnumType.STRING) @Column(length = 45, columnDefinition = "varchar(45) default 'ACTIVE'") private ItemImgOrLinkStatus itemImgOrLinkStatus = ItemImgOrLinkStatus.ACTIVE; @@ -38,13 +43,12 @@ public class TempItemImg extends BaseEntity { private Integer sortOrder; - @Builder - public TempItemImg(Long id, TempItem tempItem, String tempItemImgUrl, Boolean representFlag, ItemImgOrLinkStatus itemImgOrLinkStatus, Integer sortOrder) { - this.id = id; - this.tempItem = tempItem; - this.tempItemImgUrl = tempItemImgUrl; - this.representFlag = representFlag; - this.itemImgOrLinkStatus = itemImgOrLinkStatus; - this.sortOrder = sortOrder; + public static TempItemImg toEntity(TempItem tempItem, ItemImgResDto dto) { + return TempItemImg.builder() + .tempItem(tempItem) + .tempItemImgUrl(dto.getImgUrl()) + .representFlag(dto.getRepresentFlag()) + .sortOrder(dto.getSortOrder()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/TempItemLink.java b/src/main/java/com/sluv/server/domain/item/entity/TempItemLink.java index 15349927..d349fafd 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/TempItemLink.java +++ b/src/main/java/com/sluv/server/domain/item/entity/TempItemLink.java @@ -1,17 +1,23 @@ package com.sluv.server.domain.item.entity; +import com.sluv.server.domain.item.dto.ItemLinkResDto; import com.sluv.server.global.common.entity.BaseEntity; import com.sluv.server.global.common.enums.ItemImgOrLinkStatus; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.nio.Buffer; + @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "temp_item_link") public class TempItemLink extends BaseEntity { @@ -29,16 +35,16 @@ public class TempItemLink extends BaseEntity { @Column(columnDefinition = "TEXT") private String tempItemLinkUrl; + @Builder.Default @Enumerated(EnumType.STRING) @Column(length = 45, columnDefinition = "varchar(45) default 'ACTIVE'") private ItemImgOrLinkStatus itemImgOrLinkStatus = ItemImgOrLinkStatus.ACTIVE; - @Builder - public TempItemLink(Long id, TempItem tempItem, String linkName, String tempItemLinkUrl, ItemImgOrLinkStatus itemImgOrLinkStatus) { - this.id = id; - this.tempItem = tempItem; - this.linkName = linkName; - this.tempItemLinkUrl = tempItemLinkUrl; - this.itemImgOrLinkStatus = itemImgOrLinkStatus; + public static TempItemLink toEntity(TempItem tempItem, ItemLinkResDto dto) { + return TempItemLink.builder() + .tempItem(tempItem) + .linkName(dto.getLinkName()) + .tempItemLinkUrl(dto.getItemLinkUrl()) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/WeekHotItem.java b/src/main/java/com/sluv/server/domain/item/entity/WeekHotItem.java index 5529f44e..79fd6768 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/WeekHotItem.java +++ b/src/main/java/com/sluv/server/domain/item/entity/WeekHotItem.java @@ -3,6 +3,7 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,6 +11,8 @@ @Entity @Getter @NoArgsConstructor +@AllArgsConstructor +@Builder @Table(name = "week_hot_item") public class WeekHotItem extends BaseEntity { @@ -23,10 +26,9 @@ public class WeekHotItem extends BaseEntity { @NotNull private Item item; - - @Builder - public WeekHotItem(Long id, Item item) { - this.id = id; - this.item = item; + public static WeekHotItem toEntity(Item item) { + return WeekHotItem.builder() + .item(item) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/hashtag/Hashtag.java b/src/main/java/com/sluv/server/domain/item/entity/hashtag/Hashtag.java index a5edddb4..edaf3f7c 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/hashtag/Hashtag.java +++ b/src/main/java/com/sluv/server/domain/item/entity/hashtag/Hashtag.java @@ -4,12 +4,15 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @NoArgsConstructor +@AllArgsConstructor +@Builder @Getter @Table(name = "hashtag") public class Hashtag extends BaseEntity { @@ -22,13 +25,15 @@ public class Hashtag extends BaseEntity { @Size(max = 45) private String content; + @Builder.Default @Enumerated(EnumType.STRING) + @Column(length = 45, columnDefinition = "varchar(45) default 'ACTIVE'") private HashtagStatus hashtagStatus = HashtagStatus.ACTIVE; - @Builder - public Hashtag(Long id, String content) { - this.id = id; - this.content = content; + public static Hashtag toEntity(String content) { + return Hashtag.builder() + .content(content) + .build(); } public void changeStatus(HashtagStatus status){ diff --git a/src/main/java/com/sluv/server/domain/item/entity/hashtag/ItemHashtag.java b/src/main/java/com/sluv/server/domain/item/entity/hashtag/ItemHashtag.java index bbb8ef51..2e370b33 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/hashtag/ItemHashtag.java +++ b/src/main/java/com/sluv/server/domain/item/entity/hashtag/ItemHashtag.java @@ -4,12 +4,15 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @NoArgsConstructor +@AllArgsConstructor +@Builder @Getter @Table(name = "item_hashtag") public class ItemHashtag extends BaseEntity { @@ -28,10 +31,10 @@ public class ItemHashtag extends BaseEntity { @NotNull private Hashtag hashtag; - @Builder - public ItemHashtag(Long id, Item item, Hashtag hashtag) { - this.id = id; - this.item = item; - this.hashtag = hashtag; + public static ItemHashtag toEntity(Item item, Hashtag hashtag) { + return ItemHashtag.builder() + .item(item) + .hashtag(hashtag) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/entity/hashtag/TempItemHashtag.java b/src/main/java/com/sluv/server/domain/item/entity/hashtag/TempItemHashtag.java index e13e319c..ab907db0 100644 --- a/src/main/java/com/sluv/server/domain/item/entity/hashtag/TempItemHashtag.java +++ b/src/main/java/com/sluv/server/domain/item/entity/hashtag/TempItemHashtag.java @@ -4,12 +4,15 @@ import com.sluv.server.global.common.entity.BaseEntity; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity @NoArgsConstructor +@AllArgsConstructor +@Builder @Getter @Table(name = "temp_item_hashtag") public class TempItemHashtag extends BaseEntity { @@ -27,10 +30,10 @@ public class TempItemHashtag extends BaseEntity { @JoinColumn(name = "hashtag_id") private Hashtag hashtag; - @Builder - public TempItemHashtag(Long id, TempItem tempItem, Hashtag hashtag) { - this.id = id; - this.tempItem = tempItem; - this.hashtag = hashtag; + public static TempItemHashtag toEntity(TempItem tempItem, Hashtag hashtag) { + return TempItemHashtag.builder() + .tempItem(tempItem) + .hashtag(hashtag) + .build(); } } diff --git a/src/main/java/com/sluv/server/domain/item/service/HashtagService.java b/src/main/java/com/sluv/server/domain/item/service/HashtagService.java index 63ad2368..7abd9b3a 100644 --- a/src/main/java/com/sluv/server/domain/item/service/HashtagService.java +++ b/src/main/java/com/sluv/server/domain/item/service/HashtagService.java @@ -26,15 +26,9 @@ public class HashtagService { public PaginationResDto getHashtag(String name, Pageable pageable){ Page hashtagPage = hashtagRepository.findAllByContent(name, pageable); List dtoList = hashtagPage - .stream().map(data -> { - Hashtag hashtag = data.get(0, Hashtag.class); - - return HashtagResponseDto.builder() - .hashtagId(hashtag.getId()) - .hashtagContent(hashtag.getContent()) - .count(data.get(1, Long.class)) - .build(); - }).toList(); + .stream().map(data -> + HashtagResponseDto.of(data.get(0, Hashtag.class), data.get(1, Long.class)) + ).toList(); return PaginationResDto.builder() @@ -51,19 +45,12 @@ public HashtagPostResponseDto postHashtag(HashtagRequestDto requestDto){ //있다면 해당 Hashtag를 반환 if(hashtag.isPresent()){ - return HashtagPostResponseDto.builder() - .hashtagId(hashtag.get().getId()) - .hashtagContent(hashtag.get().getContent()) - .build(); + return HashtagPostResponseDto.of(hashtag.get()); }else{ // 없다면 등록후 반환 - Hashtag save = hashtagRepository.save(Hashtag.builder() - .content(requestDto.getHashtagContent()) - .build() + Hashtag save = hashtagRepository.save( + Hashtag.toEntity(requestDto.getHashtagContent()) ); - return HashtagPostResponseDto.builder() - .hashtagId(save.getId()) - .hashtagContent(save.getContent()) - .build(); + return HashtagPostResponseDto.of(save); } } diff --git a/src/main/java/com/sluv/server/domain/item/service/ItemCategoryService.java b/src/main/java/com/sluv/server/domain/item/service/ItemCategoryService.java index 30119217..f3172ad7 100644 --- a/src/main/java/com/sluv/server/domain/item/service/ItemCategoryService.java +++ b/src/main/java/com/sluv/server/domain/item/service/ItemCategoryService.java @@ -25,17 +25,9 @@ public List getItemCategory(){ .stream().map(parent -> { List childDtoList = childList.stream() .filter(child -> Objects.equals(child.getParent().getId(), parent.getId())) - .map(child -> ItemCategoryChildResponseDto.builder() - .id(child.getId()) - .name(child.getName()) - .build() - ).toList(); - - return ItemCategoryParentResponseDto.builder() - .id(parent.getId()) - .name(parent.getName()) - .subCategoryList(childDtoList) - .build(); + .map(ItemCategoryChildResponseDto::of).toList(); + + return ItemCategoryParentResponseDto.of(parent, childDtoList); }).toList(); } diff --git a/src/main/java/com/sluv/server/domain/item/service/ItemEditReqService.java b/src/main/java/com/sluv/server/domain/item/service/ItemEditReqService.java index 384ca32a..146617b6 100644 --- a/src/main/java/com/sluv/server/domain/item/service/ItemEditReqService.java +++ b/src/main/java/com/sluv/server/domain/item/service/ItemEditReqService.java @@ -20,12 +20,7 @@ public void postItemEdit(User user, Long itemId, ItemEditReqDto dto){ Item item = itemRepository.findById(itemId).orElseThrow(ItemNotFoundException::new); itemEditReqRepository.save( - ItemEditReq.builder() - .requester(user) - .item(item) - .itemEditReqReason(dto.getReason()) - .content(dto.getContent()) - .build() + ItemEditReq.toEntity(user, item, dto) ); } } diff --git a/src/main/java/com/sluv/server/domain/item/service/ItemReportService.java b/src/main/java/com/sluv/server/domain/item/service/ItemReportService.java index 07db27d0..f8ddc3a8 100644 --- a/src/main/java/com/sluv/server/domain/item/service/ItemReportService.java +++ b/src/main/java/com/sluv/server/domain/item/service/ItemReportService.java @@ -32,13 +32,7 @@ public void postItemReport(User user, Long itemId, ItemReportReqDto dto) { }else { // 중복이 아니라면 신고 접수 itemReportRepository.save( - ItemReport.builder() - .reporter(user) - .item(target) - .itemReportReason(dto.getReason()) - .content(dto.getContent()) - .reportStatus(ReportStatus.WAITING) - .build() + ItemReport.toEntity(target, user, dto) ); } } diff --git a/src/main/java/com/sluv/server/domain/item/service/ItemService.java b/src/main/java/com/sluv/server/domain/item/service/ItemService.java index 2ae8c9f4..e060e1a0 100644 --- a/src/main/java/com/sluv/server/domain/item/service/ItemService.java +++ b/src/main/java/com/sluv/server/domain/item/service/ItemService.java @@ -102,31 +102,18 @@ public ItemPostResDto postItem(User user, ItemPostReqDto reqDto) { Item item = reqDto.getId() != null ? itemRepository.findById(reqDto.getId()).orElseThrow(ItemNotFoundException::new) :null; - // Item id를 제외한 나머지 부분 Builder로 조립. - Item.ItemBuilder itemBuilder = Item.builder() - .user(user) - .celeb(celeb) - .category(itemCategory) - .brand(brand) - .newBrand(newBrand) - .newCeleb(newCeleb) - .name(reqDto.getItemName()) - .whenDiscovery(reqDto.getWhenDiscovery()) - .whereDiscovery(reqDto.getWhereDiscovery()) - .price(reqDto.getPrice()) - .additionalInfo(reqDto.getAdditionalInfo()) - .infoSource(reqDto.getInfoSource()) - .itemStatus(ItemStatus.ACTIVE) - .viewNum(0L); - + Item postItem; // Item 수정이라면, 기존의 Item의 Id를 추가. if(item != null){ - itemBuilder.id(item.getId()); + postItem = Item.toEntity(item.getId(), user, celeb, newCeleb, itemCategory, brand, newBrand, reqDto); + }else { + // Item 생성 + postItem = Item.toEntity(user, celeb, newCeleb, itemCategory, brand, newBrand, reqDto); } // 완성된 Item save Item newItem = itemRepository.save( - itemBuilder.build() + postItem ); // 기존의 Img, Link, Hashtag가 있다면 모두 삭제 @@ -137,13 +124,7 @@ public ItemPostResDto postItem(User user, ItemPostReqDto reqDto) { // ItemImg 테이블에 추가 reqDto.getImgList().stream() .map(itemImg-> - ItemImg.builder() - .item(newItem) - .itemImgUrl(itemImg.getImgUrl()) - .representFlag(itemImg.getRepresentFlag()) - .itemImgOrLinkStatus(ItemImgOrLinkStatus.ACTIVE) - .sortOrder(itemImg.getSortOrder()) - .build() + ItemImg.toEntity(newItem, itemImg) ).forEach(itemImgRepository::save); @@ -167,33 +148,23 @@ public ItemPostResDto postItem(User user, ItemPostReqDto reqDto) { if(reqDto.getHashTagIdList() != null) { reqDto.getHashTagIdList().stream().map(hashTag -> - ItemHashtag.builder() - .item(newItem) - .hashtag( - hashtagRepository.findById(hashTag) - .orElseThrow(HashtagNotFoundException::new) - ) - .build() - + ItemHashtag.toEntity( + newItem, + hashtagRepository.findById(hashTag) + .orElseThrow(HashtagNotFoundException::new) + ) ).forEach(itemHashtagRepository::save); } - return ItemPostResDto.builder() - .itemId(newItem.getId()) - .build(); + return ItemPostResDto.of(newItem.getId()); } public List getTopPlace() { return itemRepository.findTopPlace().stream() - .map(placeName -> - HotPlaceResDto.builder() - .placeName(placeName) - .build() - ).toList(); - + .map(HotPlaceResDto::of).toList(); } public ItemDetailResDto getItemDetail(User user, Long itemId) { @@ -208,12 +179,7 @@ public ItemDetailResDto getItemDetail(User user, Long itemId) { // 2. Item 이미지들 조회 List imgList = itemImgRepository.findAllByItemId(itemId) .stream() - .map(itemImg -> ItemImgResDto.builder() - .imgUrl(itemImg.getItemImgUrl()) - .representFlag(itemImg.getRepresentFlag()) - .sortOrder(itemImg.getSortOrder()) - .build() - ).toList(); + .map(ItemImgResDto::of).toList(); // 3. Item Celeb CelebSearchResDto celeb = item.getCeleb() != null @@ -225,20 +191,7 @@ public ItemDetailResDto getItemDetail(User user, Long itemId) { : null; // 4. Item Category - ItemCategoryDto category = ItemCategoryDto.builder() - .id(item.getCategory().getId()) - .parentId( - item.getCategory().getParent() != null - ? item.getCategory().getParent().getId() - : null - ) - .name(item.getCategory().getName()) - .parentName( - item.getCategory().getParent() != null - ? item.getCategory().getParent().getName() - : null - ) - .build(); + ItemCategoryDto category = ItemCategoryDto.of(item.getCategory()); // 4. Brand BrandSearchResDto brand = item.getBrand() != null ? @@ -262,12 +215,7 @@ public ItemDetailResDto getItemDetail(User user, Long itemId) { List linkList = itemLinkRepository.findByItemId(itemId) .stream() - .map(itemLink -> ItemLinkResDto.builder() - .linkName(itemLink.getLinkName()) - .itemLinkUrl(itemLink.getItemLinkUrl()) - .build() - ) - .toList(); + .map(ItemLinkResDto::of).toList(); // 9. 작성자 info User writer = userRepository.findById(item.getUser().getId()) @@ -279,11 +227,7 @@ public ItemDetailResDto getItemDetail(User user, Long itemId) { List hashtagList = itemHashtagId.stream() .parallel() .map(itemHashtag -> - HashtagResponseDto.builder() - .hashtagId(itemHashtag.getHashtag().getId()) - .hashtagContent(itemHashtag.getHashtag().getContent()) - .count(null) - .build() + HashtagResponseDto.of(itemHashtag.getHashtag(), null) ).toList(); @@ -311,34 +255,33 @@ user, getClosetItemList(item) // 15. 팔로우 여부 boolean followStatus = followRepository.getFollowStatus(user, writer); + // 16. 스크랩 여부 + List closetList = closetRepository.findAllByUserId(user.getId()); + boolean scrapStatus = itemScrapRepository.getItemScrapStatus(item, closetList); + // Dto 조립 - return ItemDetailResDto.builder() - .imgList(imgList) - .celeb(celeb) - .newCelebName(newCeleb) - .category(category) - .itemName(item.getName()) - .brand(brand) - .newBrandName(newBrand) - .likeNum(likeNum) - .likeStatus(likeStatus) - .scrapNum(scrapNum) - .viewNum(viewNum) - .linkList(linkList) - .writer(writerInfo) - .whenDiscovery(item.getWhenDiscovery()) - .whereDiscovery(item.getWhereDiscovery()) - .price(item.getPrice()) - .additionalInfo(item.getAdditionalInfo()) - .hashTagList(hashtagList) - .infoSource(item.getInfoSource()) - .sameCelebItemList(sameCelebItemList) - .sameBrandItemList(sameBrandItemList) - .otherSluverItemList(sameClosetItemList) - .color(item.getColor()) - .followStatus(followStatus) - .hasMine(item.getUser().getId().equals(user.getId())) - .build(); + return ItemDetailResDto.of( + item, + celeb, + newCeleb, + brand, + newBrand, + category, + likeNum, + likeStatus, + scrapNum, + scrapStatus, + viewNum, + writerInfo, + followStatus, + item.getUser().getId().equals(user.getId()), + imgList, + linkList, + hashtagList, + sameCelebItemList, + sameBrandItemList, + sameClosetItemList + ); } @Transactional @@ -348,10 +291,7 @@ public void postItemLike(User user, Long itemId) { boolean likeExist = itemLikeRepository.existsByUserIdAndItemId(user.getId(), itemId); if(!likeExist){ itemLikeRepository.save( - ItemLike.builder() - .item(item) - .user(user) - .build() + ItemLike.toEntity(item, user) ); }else{ itemLikeRepository.deleteByUserIdAndItemId(user.getId(), itemId); @@ -409,26 +349,8 @@ private List convertItemToItemSimpleResDto(User user, List{ ItemImg itemImg = itemImgRepository.findMainImg(item.getId()); Boolean scrapStatus = itemScrapRepository.getItemScrapStatus(item, closetList); - return ItemSimpleResDto.builder() - .itemId(item.getId()) - .itemName(item.getName()) - .brandName( - item.getBrand() != null - ?item.getBrand().getBrandKr() - :item.getNewBrand().getBrandName() - ) - .celebName( - item.getCeleb() != null - ? item.getCeleb().getParent() != null - ? item.getCeleb().getParent().getCelebNameKr() + " " + item.getCeleb().getCelebNameKr() - : item.getCeleb().getCelebNameKr() - : item.getNewCeleb().getCelebName() - ) - .imgUrl(itemImg.getItemImgUrl()) - .scrapStatus(scrapStatus) - .build(); - }) - .toList(); + return ItemSimpleResDto.of(item, itemImg, scrapStatus); + }).toList(); } public PaginationResDto getRecommendItem(User user, Pageable pageable) { diff --git a/src/main/java/com/sluv/server/domain/item/service/PlaceRankService.java b/src/main/java/com/sluv/server/domain/item/service/PlaceRankService.java index 98d58f3b..d0cb9dd0 100644 --- a/src/main/java/com/sluv/server/domain/item/service/PlaceRankService.java +++ b/src/main/java/com/sluv/server/domain/item/service/PlaceRankService.java @@ -18,10 +18,7 @@ public class PlaceRankService { public void postPlace(User user, PlaceRankReqDto dto) { placeRankRepository.save( - PlaceRank.builder() - .user(user) - .place(dto.getPlaceName()) - .build() + PlaceRank.toEntity(user, dto) ); } @@ -39,10 +36,6 @@ public void deletePlace(User user, String placeName) { public List getRecentPlaceTop20(User user) { return placeRankRepository.getRecentPlaceTop20(user) .stream() - .map(placeRank -> - PlaceRankResDto.builder() - .placeName(placeRank.getPlace()) - .build() - ).toList(); + .map(PlaceRankResDto::of).toList(); } } diff --git a/src/main/java/com/sluv/server/domain/item/service/TempItemService.java b/src/main/java/com/sluv/server/domain/item/service/TempItemService.java index 392c0488..3cd4d343 100644 --- a/src/main/java/com/sluv/server/domain/item/service/TempItemService.java +++ b/src/main/java/com/sluv/server/domain/item/service/TempItemService.java @@ -76,20 +76,15 @@ public Long postTempItem(User user, TempItemPostReqDto reqDto) { TempItem tempItem = reqDto.getId() != null ? tempItemRepository.findById(reqDto.getId()) .orElseThrow(TempItemNotFoundException::new) - :TempItem.builder().itemStatus(ItemStatus.ACTIVE).build(); - - tempItem.setUser(user); - tempItem.setCeleb(celeb); - tempItem.setNewCeleb(newCeleb); - tempItem.setCategory(itemCategory); - tempItem.setBrand(brand); - tempItem.setNewBrand(newBrand); - tempItem.setName(reqDto.getItemName()); - tempItem.setWhenDiscovery(reqDto.getWhenDiscovery()); - tempItem.setWhereDiscovery(reqDto.getWhereDiscovery()); - tempItem.setPrice(reqDto.getPrice()); - tempItem.setAdditionalInfo(reqDto.getAdditionalInfo()); - tempItem.setInfoSource(reqDto.getInfoSource()); + :TempItem.toEntity( + user, + celeb, + newCeleb, + itemCategory, + brand, + newBrand, + reqDto + ); TempItem saveTempItem = tempItemRepository.save(tempItem); @@ -98,13 +93,7 @@ public Long postTempItem(User user, TempItemPostReqDto reqDto) { if(reqDto.getImgList() != null) { reqDto.getImgList().stream() .map(tempItemImg -> - TempItemImg.builder() - .tempItem(saveTempItem) - .tempItemImgUrl(tempItemImg.getImgUrl()) - .representFlag(tempItemImg.getRepresentFlag()) - .itemImgOrLinkStatus(ItemImgOrLinkStatus.ACTIVE) - .sortOrder(tempItemImg.getSortOrder()) - .build() + TempItemImg.toEntity(saveTempItem, tempItemImg) ).forEach(tempItemImgRepository::save); } @@ -114,13 +103,7 @@ public Long postTempItem(User user, TempItemPostReqDto reqDto) { if(reqDto.getLinkList() != null) { reqDto.getLinkList().stream() .map(tempItemLink -> - TempItemLink.builder() - .tempItem(saveTempItem) - .linkName(tempItemLink.getLinkName()) - .tempItemLinkUrl(tempItemLink.getItemLinkUrl()) - .itemImgOrLinkStatus(ItemImgOrLinkStatus.ACTIVE) - .build() - + TempItemLink.toEntity(saveTempItem, tempItemLink) ).forEach(tempItemLinkRepository::save); } @@ -128,14 +111,11 @@ public Long postTempItem(User user, TempItemPostReqDto reqDto) { tempItemHashtagRepository.deleteAllByTempItemId(tempItem.getId()); if(reqDto.getHashTagIdList() != null) { reqDto.getHashTagIdList().stream().map(hashTag -> - TempItemHashtag.builder() - .tempItem(saveTempItem) - .hashtag( - hashtagRepository.findById(hashTag) - .orElseThrow(HashtagNotFoundException::new) - ) - .build() - + TempItemHashtag.toEntity( + saveTempItem, + hashtagRepository.findById(hashTag) + .orElseThrow(HashtagNotFoundException::new) + ) ).forEach(tempItemHashtagRepository::save); } @@ -149,75 +129,39 @@ public PaginationCountResDto getTempItemList(User user, Pageable List dtoList = contentPage.stream().map(tempItem -> { List tempImgList = tempItemImgRepository.findAllByTempItem(tempItem) - .stream().map(tempItemImg -> ItemImgResDto.builder() - .imgUrl(tempItemImg.getTempItemImgUrl()) - .representFlag(tempItemImg.getRepresentFlag()) - .sortOrder(tempItemImg.getSortOrder()) - .build() - ).collect(Collectors.toList()); + .stream().map(ItemImgResDto::of).collect(Collectors.toList()); List tempHashtagList = tempItemHashtagRepository.findAllByTempItem(tempItem) .stream().map(TempItemHashtag::getHashtag).toList(); List tempLinkList = tempItemLinkRepository.findAllByTempItem(tempItem) - .stream().map(tempItemLink -> ItemLinkResDto.builder() - .linkName(tempItemLink.getLinkName()) - .itemLinkUrl(tempItemLink.getTempItemLinkUrl()) - .build() - ).collect(Collectors.toList()); + .stream().map(ItemLinkResDto::of).collect(Collectors.toList()); CelebDto celebDto = tempItem.getCeleb() != null ? CelebDto.of(tempItem.getCeleb()) : null; ItemCategoryDto itemCategoryDto = tempItem.getCategory() != null ? - ItemCategoryDto.builder() - .id(tempItem.getCategory().getId()) - .name(tempItem.getCategory().getName()) - .parentName( - tempItem.getCategory().getParent() != null - ? tempItem.getCategory().getParent().getName() - : null - ) - .parentId( - tempItem.getCategory().getParent() != null - ? tempItem.getCategory().getParent().getId() - : null - ) - .build() + ItemCategoryDto.of(tempItem.getCategory()) : null; Brand brand = tempItem.getBrand() != null ? tempItem.getBrand() : null; - return TempItemResDto.builder() - .id(tempItem.getId()) - .imgList(tempImgList) - .celeb(celebDto) - .brand(brand) - .whenDiscovery(tempItem.getWhenDiscovery()) - .whereDiscovery(tempItem.getWhereDiscovery()) - .category(itemCategoryDto) - .itemName(tempItem.getName()) - .price(tempItem.getPrice()) - .additionalInfo(tempItem.getAdditionalInfo()) - .hashTagList(tempHashtagList) - .linkList(tempLinkList) - .infoSource(tempItem.getInfoSource()) - .newCeleb( - tempItem.getNewCeleb() != null - ? NewCelebPostResDto.of(tempItem.getNewCeleb()) - :null - ) - .newBrand( - tempItem.getNewBrand() != null - ? NewBrandPostResDto.of(tempItem.getNewBrand()) - :null - ) - .updatedAt(tempItem.getUpdatedAt()) - .build(); + NewCelebPostResDto newCelebPostResDto = tempItem.getNewCeleb() != null + ? NewCelebPostResDto.of(tempItem.getNewCeleb()) + : null; + NewBrandPostResDto newBrandPostResDto = tempItem.getNewBrand() != null + ? NewBrandPostResDto.of(tempItem.getNewBrand()) + : null; + + return TempItemResDto.of( + tempItem, celebDto, newCelebPostResDto, + brand, newBrandPostResDto, itemCategoryDto, + tempImgList, tempLinkList, tempHashtagList + ); } ).toList(); diff --git a/src/main/java/com/sluv/server/domain/question/service/QuestionService.java b/src/main/java/com/sluv/server/domain/question/service/QuestionService.java index 62ff34f2..f46e5ce7 100644 --- a/src/main/java/com/sluv/server/domain/question/service/QuestionService.java +++ b/src/main/java/com/sluv/server/domain/question/service/QuestionService.java @@ -387,20 +387,12 @@ public QuestionGetDetailResDto getQuestionDetail(User user, Long questionId) { .stream() .map(questionItem -> { List closetList = closetRepository.findAllByUserId(user.getId()); - ItemSimpleResDto dto = ItemSimpleResDto.builder() - .itemId(questionItem.getItem().getId()) - .itemName(questionItem.getItem().getName()) - .celebName(questionItem.getItem().getBrand() != null - ? questionItem.getItem().getBrand().getBrandKr() - : questionItem.getItem().getNewBrand().getBrandName() - ) - .brandName(questionItem.getItem().getBrand() != null - ? questionItem.getItem().getBrand().getBrandKr() - : questionItem.getItem().getNewBrand().getBrandName() - ) - .imgUrl(itemImgRepository.findMainImg(questionItem.getItem().getId()).getItemImgUrl()) - .scrapStatus(itemScrapRepository.getItemScrapStatus(questionItem.getItem(),closetList)) - .build(); + ItemSimpleResDto dto = ItemSimpleResDto.of( + questionItem.getItem(), + itemImgRepository.findMainImg(questionItem.getItem().getId()), + itemScrapRepository.getItemScrapStatus(questionItem.getItem(),closetList) + ); + QuestionItemResDto.QuestionItemResDtoBuilder builder = QuestionItemResDto.builder() .item(dto) .representFlag(questionItem.getRepresentFlag()) diff --git a/src/main/java/com/sluv/server/domain/search/service/SearchService.java b/src/main/java/com/sluv/server/domain/search/service/SearchService.java index ea9d2298..70a84de8 100644 --- a/src/main/java/com/sluv/server/domain/search/service/SearchService.java +++ b/src/main/java/com/sluv/server/domain/search/service/SearchService.java @@ -83,22 +83,11 @@ public PaginationResDto getSearchItem(User user, String keywor // Cotent 조립 List content = searchItemPage.stream().map(item -> - ItemSimpleResDto.builder() - .itemId(item.getId()) - .imgUrl(itemImgRepository.findMainImg(item.getId()).getItemImgUrl()) - .brandName( - item.getBrand() != null - ? item.getBrand().getBrandKr() - : item.getNewBrand().getBrandName() - ) - .itemName(item.getName()) - .celebName( - item.getCeleb() != null - ? item.getCeleb().getCelebNameKr() - : item.getNewCeleb().getCelebName() - ) - .scrapStatus(itemScrapRepository.getItemScrapStatus(item, closetList)) - .build() + ItemSimpleResDto.of( + item, + itemImgRepository.findMainImg(item.getId()), + itemScrapRepository.getItemScrapStatus(item, closetList) + ) ).toList(); // 최근 검색 등록 diff --git a/src/main/java/com/sluv/server/domain/user/service/UserService.java b/src/main/java/com/sluv/server/domain/user/service/UserService.java index 1b10f577..25b3a416 100644 --- a/src/main/java/com/sluv/server/domain/user/service/UserService.java +++ b/src/main/java/com/sluv/server/domain/user/service/UserService.java @@ -253,24 +253,11 @@ public PaginationResDto getUserItem(User user, Long userId, Pa } private ItemSimpleResDto getItemSimpleResDto(Item item, List closetList) { - return ItemSimpleResDto.builder() - .itemId(item.getId()) - .imgUrl(itemImgRepository.findMainImg(item.getId()).getItemImgUrl()) - .brandName( - item.getBrand() != null - ? item.getBrand().getBrandKr() - : item.getNewBrand().getBrandName() - ) - .itemName(item.getName()) - .celebName( - item.getCeleb() != null - ? item.getCeleb().getParent() != null - ? item.getCeleb().getParent().getCelebNameKr() + " " + item.getCeleb().getCelebNameKr() - : item.getCeleb().getCelebNameKr() - : item.getNewCeleb().getCelebName() - ) - .scrapStatus(itemScrapRepository.getItemScrapStatus(item, closetList)) - .build(); + return ItemSimpleResDto.of( + item, + itemImgRepository.findMainImg(item.getId()), + itemScrapRepository.getItemScrapStatus(item, closetList) + ); } public PaginationResDto getUserCloset(User user, Long userId, Pageable pageable) { diff --git a/src/main/java/com/sluv/server/global/scheduler/Scheduler.java b/src/main/java/com/sluv/server/global/scheduler/Scheduler.java index 03ec7c99..9338b11c 100644 --- a/src/main/java/com/sluv/server/global/scheduler/Scheduler.java +++ b/src/main/java/com/sluv/server/global/scheduler/Scheduler.java @@ -71,9 +71,7 @@ public void updateLuxuryItem(){ newLuxuryItem.forEach(item -> luxuryItemRepository.save( - LuxuryItem.builder() - .item(item) - .build() + LuxuryItem.toEntity(item) ) ); } @@ -96,9 +94,7 @@ public void updateEfficientItem(){ newEfficientItem.forEach(item -> efficientItemRepository.save( - EfficientItem.builder() - .item(item) - .build() + EfficientItem.toEntity(item) ) ); } @@ -121,9 +117,7 @@ public void updateWeekHotItem(){ newWeekHotItem.forEach(item -> weekHotItemRepository.save( - WeekHotItem.builder() - .item(item) - .build() + WeekHotItem.toEntity(item) ) ); } @@ -146,9 +140,7 @@ public void updateDayHotItem(){ newDayHotItem.forEach(item -> dayHotItemRepository.save( - DayHotItem.builder() - .item(item) - .build() + DayHotItem.toEntity(item) ) ); }