diff --git a/src/main/java/trothly/trothcam/domain/history/History.java b/src/main/java/trothly/trothcam/domain/history/History.java index a98b27a..ebe7fb2 100644 --- a/src/main/java/trothly/trothcam/domain/history/History.java +++ b/src/main/java/trothly/trothcam/domain/history/History.java @@ -3,6 +3,8 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import trothly.trothcam.domain.member.Member; @@ -15,6 +17,8 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @EntityListeners(AuditingEntityListener.class) +@DynamicInsert +@DynamicUpdate @Table(name = "history") public class History { @@ -40,4 +44,5 @@ public class History { @CreatedDate @Column(name = "sold_at", updatable = false, nullable = false) private LocalDateTime soldAt; + } diff --git a/src/main/java/trothly/trothcam/domain/image/Image.java b/src/main/java/trothly/trothcam/domain/image/Image.java index 714bbc5..625d82d 100644 --- a/src/main/java/trothly/trothcam/domain/image/Image.java +++ b/src/main/java/trothly/trothcam/domain/image/Image.java @@ -34,7 +34,6 @@ public class Image extends BaseTimeEntity { private Member member; @Column(name = "image_share", nullable = false) - @ColumnDefault("N") @Enumerated(EnumType.STRING) private Share share; @@ -50,8 +49,9 @@ public class Image extends BaseTimeEntity { @Column(name = "image_size", nullable = true) private String size; - public Image(String imageHash, Member member) { + public Image(String imageHash, Member member, Share share) { this.imageHash = imageHash; this.member = member; + this.share = share; } } diff --git a/src/main/java/trothly/trothcam/dto/web/HistoryDto.java b/src/main/java/trothly/trothcam/dto/web/HistoryDto.java new file mode 100644 index 0000000..0504d14 --- /dev/null +++ b/src/main/java/trothly/trothcam/dto/web/HistoryDto.java @@ -0,0 +1,17 @@ +package trothly.trothcam.dto.web; + +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class HistoryDto { + private Long historyId; + private Long productId; + private Long sellerId; + private Long buyerId; + private Long price; + private LocalDateTime soldAt; +} diff --git a/src/main/java/trothly/trothcam/dto/web/ProductDetailResDto.java b/src/main/java/trothly/trothcam/dto/web/ProductDetailResDto.java index 13b74ab..3f6aece 100644 --- a/src/main/java/trothly/trothcam/dto/web/ProductDetailResDto.java +++ b/src/main/java/trothly/trothcam/dto/web/ProductDetailResDto.java @@ -7,6 +7,7 @@ import trothly.trothcam.domain.history.History; import trothly.trothcam.domain.product.PublicYn; +import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.List; @@ -28,6 +29,6 @@ public class ProductDetailResDto { private LocalDateTime createdAt; private LocalDateTime updatedAt; private boolean liked; - private List histories; + private List histories; } diff --git a/src/main/java/trothly/trothcam/service/ImageService.java b/src/main/java/trothly/trothcam/service/ImageService.java index 38493b5..1757509 100644 --- a/src/main/java/trothly/trothcam/service/ImageService.java +++ b/src/main/java/trothly/trothcam/service/ImageService.java @@ -6,6 +6,7 @@ import org.springframework.transaction.annotation.Transactional; import trothly.trothcam.domain.image.Image; import trothly.trothcam.domain.image.ImageRepository; +import trothly.trothcam.domain.image.Share; import trothly.trothcam.domain.member.Member; import trothly.trothcam.dto.app.CheckImgHashResDto; import trothly.trothcam.dto.app.ImgHashReqDto; @@ -31,7 +32,7 @@ public SaveImgHashResDto saveImgHash(ImgHashReqDto req, Member member) throws Ba throw new BadRequestException("이미 존재하는 해시 값입니다."); } - Image image = imageRepository.save(new Image(req.getImageHash(), member)); + Image image = imageRepository.save(new Image(req.getImageHash(), member, Share.N)); return new SaveImgHashResDto(image.getId()); } diff --git a/src/main/java/trothly/trothcam/service/web/HistoryService.java b/src/main/java/trothly/trothcam/service/web/HistoryService.java index bb257e6..2ca3e19 100644 --- a/src/main/java/trothly/trothcam/service/web/HistoryService.java +++ b/src/main/java/trothly/trothcam/service/web/HistoryService.java @@ -6,9 +6,11 @@ import trothly.trothcam.domain.history.History; import trothly.trothcam.domain.history.HistoryRepository; import trothly.trothcam.domain.product.ProductRepository; +import trothly.trothcam.dto.web.HistoryDto; import trothly.trothcam.dto.web.ProductReqDto; import trothly.trothcam.exception.base.BaseException; +import java.util.ArrayList; import java.util.List; import static trothly.trothcam.exception.base.ErrorCode.HISTORIES_NOT_FOUND; @@ -22,13 +24,20 @@ public class HistoryService { private final ProductRepository productRepository; // 거래 내역 전체 조회 - public List findAllHistory(ProductReqDto req) { + public List findAllHistory(ProductReqDto req) { List findHistories = historyRepository.findAllByProductId(req.getProductId()); - if(findHistories == null || findHistories.isEmpty()) { - throw new BaseException(HISTORIES_NOT_FOUND); +// if(findHistories == null || findHistories.isEmpty()) { +// throw new BaseException(HISTORIES_NOT_FOUND); +// } + + List historyDto = new ArrayList<>(); + + for (History history : findHistories) { + HistoryDto historyOne = new HistoryDto(history.getId(), history.getProduct().getId(), history.getSeller().getId(), history.getBuyer().getId(), history.getPrice(), history.getSoldAt()); + historyDto.add(historyOne); } - return findHistories; + return historyDto; } // 거래 내역 저장 diff --git a/src/main/java/trothly/trothcam/service/web/ProductService.java b/src/main/java/trothly/trothcam/service/web/ProductService.java index 5701369..8dd8abf 100644 --- a/src/main/java/trothly/trothcam/service/web/ProductService.java +++ b/src/main/java/trothly/trothcam/service/web/ProductService.java @@ -13,6 +13,7 @@ import trothly.trothcam.domain.product.Product; import trothly.trothcam.domain.product.ProductRepository; import trothly.trothcam.domain.product.PublicYn; +import trothly.trothcam.dto.web.HistoryDto; import trothly.trothcam.dto.web.ProductDetailResDto; import trothly.trothcam.dto.web.ProductReqDto; import trothly.trothcam.dto.web.ProductsResDto; @@ -20,6 +21,7 @@ import trothly.trothcam.exception.base.ErrorCode; import trothly.trothcam.exception.custom.BadRequestException; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -34,6 +36,7 @@ public class ProductService { private final HistoryRepository historyRepository; private final LikeProductRepository likeProductRepository; private final ImageRepository imageRepository; + private final HistoryService historyService; /* 공개 인증서 조회 */ @Transactional(readOnly = true) @@ -54,7 +57,7 @@ public List findPublicProducts(String webId) throws BaseExceptio } /* 상품 detail 화면 조회 */ - @Transactional(readOnly = true) + @Transactional public ProductDetailResDto findProductDetail(ProductReqDto req, Member member) { Boolean liked = false; @@ -76,10 +79,10 @@ public ProductDetailResDto findProductDetail(ProductReqDto req, Member member) { liked = false; } - List histories = historyRepository.findAllByProductId(req.getProductId()); + List historyDto = historyService.findAllHistory(req); return new ProductDetailResDto(req.getProductId(), product.getImage().getId(), product.getMember().getId(), product.getTitle(), product.getTags(), product.getPrice(), product.getDescription(),product.getViews(), likes, product.getPublicYn(), product.getCreatedAt(), - product.getLastModifiedAt(), liked, histories); + product.getLastModifiedAt(), liked, historyDto); } -} +} \ No newline at end of file