Skip to content

Commit

Permalink
Merge pull request #243 from KJBig/feature/S2D-24
Browse files Browse the repository at this point in the history
feat : Item 관련 of, toEntity 메소드 적용
  • Loading branch information
KJBig authored Aug 15, 2023
2 parents 688a526 + 1562113 commit 25cfef8
Show file tree
Hide file tree
Showing 47 changed files with 551 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -187,7 +184,7 @@ public ClosetDetailResDto<ItemSimpleResDto> getClosetDetails(User user, Long clo

Page<Item> itemPage = itemRepository.getClosetItems(closet, pageable);

List<ItemSimpleResDto> content = getItemContent(itemPage);
List<ItemSimpleResDto> content = getItemContent(user, itemPage);

return ClosetDetailResDto.<ItemSimpleResDto>builder()
.hasNext(itemPage.hasNext())
Expand All @@ -204,27 +201,15 @@ public ClosetDetailResDto<ItemSimpleResDto> getClosetDetails(User user, Long clo

}

private List<ItemSimpleResDto> getItemContent(Page<Item> itemPage) {
return itemPage.stream().map(item -> {
private List<ItemSimpleResDto> getItemContent(User user, Page<Item> itemPage) {
List<Closet> 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<ClosetResDto> getClosetList(User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public ResponseEntity<SuccessDataResponse<TempItemPostResDto>> postTempItem(@Aut
return ResponseEntity.ok().body(
SuccessDataResponse.<TempItemPostResDto>builder()
.result(
TempItemPostResDto.builder()
.tempItemId(tempItemService.postTempItem(user, reqDto))
.build()
TempItemPostResDto.of(
tempItemService.postTempItem(user, reqDto)
)
.build()
)
.build()
);
}
@Operation(
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
public class HotPlaceResDto {
@Schema(description = "장소명")
private String placeName;

public static HotPlaceResDto of(String placeName){
return HotPlaceResDto.builder()
.placeName(placeName)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
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")
private Long id;
@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();
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/sluv/server/domain/item/dto/ItemCategoryDto.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -20,10 +20,13 @@ public class ItemCategoryParentResponseDto {
@Schema(description = "하위 카테고리 목록")
private List<ItemCategoryChildResponseDto> subCategoryList;

@Builder
public ItemCategoryParentResponseDto(Long id, String name, List<ItemCategoryChildResponseDto> subCategoryList) {
this.id = id;
this.name = name;
this.subCategoryList = subCategoryList;
public static ItemCategoryParentResponseDto of(ItemCategory itemCategory,
List<ItemCategoryChildResponseDto> subCategoryList){

return ItemCategoryParentResponseDto.builder()
.id(itemCategory.getId())
.name(itemCategory.getName())
.subCategoryList(subCategoryList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ItemImgResDto> imgList, List<ItemLinkResDto> linkList, List<HashtagResponseDto> hashtagList,
List<ItemSimpleResDto> sameCelebItemList, List<ItemSimpleResDto> sameBrandItemList, List<ItemSimpleResDto> 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();
}



Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/sluv/server/domain/item/dto/ItemImgResDto.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

}
16 changes: 16 additions & 0 deletions src/main/java/com/sluv/server/domain/item/dto/ItemLinkResDto.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

}
Loading

0 comments on commit 25cfef8

Please sign in to comment.