Skip to content

Commit

Permalink
Feat: 상품 상세 조회 및 전체 조회 수정 #18
Browse files Browse the repository at this point in the history
  • Loading branch information
tokyj515 committed Aug 2, 2023
1 parent 1ce3d1a commit b7b8376
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
22 changes: 12 additions & 10 deletions src/main/java/com/example/neoul/dto/product/ProductRes.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.neoul.dto.product;

import lombok.*;

import java.time.LocalDate;
import java.util.List;

public class ProductRes {
Expand All @@ -13,20 +15,20 @@ public class ProductRes {
@Getter
// main - 상품 상세조회
public static class ProductDetailRes {
private Long pid; //상품 id
private Long bid; //브랜드 id
private Long cid; //카테고리 id
private String category; //상품 카테고리
private String pName; //상품명
private Long productId; //상품 id
private Long brandId; //브랜드 id
private Long categoryPId; //카테고리 id
private String categoryName; //상품 카테고리
private String productName; //상품명
private Integer price; //상품금액
private List<String> pImgList; //상품사진
private String pDeliveryInfo; //상품 배송정보 (무료배송 etc..)
private String pUrl; //상품상세 url
private List<String> productImgList; //상품사진
private String deliveryInfo; //상품 배송정보 (무료배송 etc..)
private String productUrl; //상품상세 url
private Integer pLikeCNT; //상품찜 개수
private Boolean pHearted; //상품찜 여부 true false
private String pCreatedAt; //상품 업로드 일자
private LocalDate createdAt; //상품 업로드 일자

private String clickedAt; //상품 클릭 일시
// private LocalDate clickedAt; //상품 클릭 일시
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.example.neoul.repository;

import com.example.neoul.entity.brand.Product;
import com.example.neoul.entity.brand.ProductImage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProductImageRepository extends JpaRepository<ProductImage, Long> {

List<ProductImage> findAllByProduct(Product product);
}
31 changes: 20 additions & 11 deletions src/main/java/com/example/neoul/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import com.example.neoul.dto.product.ProductRes;
import com.example.neoul.entity.brand.Product;
import com.example.neoul.entity.brand.ProductImage;
import com.example.neoul.global.exception.NotFoundException;
import com.example.neoul.repository.ProductImageRepository;
import com.example.neoul.repository.ProductRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Service
public class ProductService {

private final ProductRepository productRepository;

private final ProductImageRepository productImageRepository;


// 상품 전체 리스트
public List<ProductRes.ProductDetailRes> getAllProducts() {
Expand All @@ -34,20 +37,26 @@ public List<ProductRes.ProductDetailRes> getAllProducts() {

public ProductRes.ProductDetailRes getProduct(Long productId) {
Product product = getProductByProductId(productId);
List<ProductImage> productImages = productImageRepository.findAllByProduct(product);
List<String> productImgList = new ArrayList<>();

for(ProductImage productImage : productImages){
productImgList.add(productImage.getUrl());
}

return ProductRes.ProductDetailRes.builder()
.pid(product.getId())
.bid(product.getBrand().getId())
.cid(product.getCategoryP().getId())
// .category(product.getCategory()) //얘는 살려야함
.pName(product.getName())
.productId(product.getId())
.brandId(product.getBrand().getId())
.categoryPId(product.getCategoryP().getId())
.categoryName(product.getCategoryP().getName()) //얘는 살려야함
.productName(product.getName())
.price(product.getPrice())
// .pImgList(product.getImgList()) //얘는 살려야함
// .pDeliveryInfo(product.getDeliveryInfo())
.pUrl(product.getProductUrl())
.productImgList(productImgList) //얘는 살려야함
.deliveryInfo(product.getDeliveryInfo())
.productUrl(product.getProductUrl())
// .pLikeCNT(product.getLikeCount())
// .pHearted(product.isHearted()) //얘는 살려야함
// .pCreatedAt(product.getCreatedAt())
// .pHearted(product.isHearted())
.createdAt(product.getCreatedAt().toLocalDate())
// .clickedAt(product.getClickedAt())
.build();
}
Expand Down

0 comments on commit b7b8376

Please sign in to comment.