diff --git a/src/main/java/co/orange/ddanzi/domain/Banner.java b/src/main/java/co/orange/ddanzi/domain/Banner.java new file mode 100644 index 00000000..7a78cca1 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/domain/Banner.java @@ -0,0 +1,26 @@ +package co.orange.ddanzi.domain; + +import co.orange.ddanzi.global.common.domain.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@Table(name = "banners") +@Entity +public class Banner extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "banner_id") + private Integer id; + + @Column(name = "img_url") + private String imgUrl; + + @Column(name = "note") + private String note; + + @Column(name = "is_selected", nullable = false) + private Boolean isSelected; +} diff --git a/src/main/java/co/orange/ddanzi/dto/AddressInfo.java b/src/main/java/co/orange/ddanzi/dto/AddressInfo.java new file mode 100644 index 00000000..4009c154 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/dto/AddressInfo.java @@ -0,0 +1,13 @@ +package co.orange.ddanzi.dto; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class AddressInfo { + private String recipient; + private String zipCode; + private String address; + private String phone; +} diff --git a/src/main/java/co/orange/ddanzi/dto/home/HomeResponseDto.java b/src/main/java/co/orange/ddanzi/dto/home/HomeResponseDto.java index 99f48723..758167a1 100644 --- a/src/main/java/co/orange/ddanzi/dto/home/HomeResponseDto.java +++ b/src/main/java/co/orange/ddanzi/dto/home/HomeResponseDto.java @@ -9,5 +9,6 @@ @Getter @Builder public class HomeResponseDto { + private String homeImgUrl; private List productList; } diff --git a/src/main/java/co/orange/ddanzi/dto/order/CheckProductResponseDto.java b/src/main/java/co/orange/ddanzi/dto/order/CheckProductResponseDto.java new file mode 100644 index 00000000..92227b0f --- /dev/null +++ b/src/main/java/co/orange/ddanzi/dto/order/CheckProductResponseDto.java @@ -0,0 +1,17 @@ +package co.orange.ddanzi.dto.order; + +import co.orange.ddanzi.dto.AddressInfo; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CheckProductResponseDto { + private String productName; + private String imgUrl; + private Integer originPrice; + private AddressInfo addressInfo; + private Integer discountPrice; + private Integer charge; + private Integer totalPrice; +} diff --git a/src/main/java/co/orange/ddanzi/repository/BannerRepository.java b/src/main/java/co/orange/ddanzi/repository/BannerRepository.java new file mode 100644 index 00000000..8066aea9 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/repository/BannerRepository.java @@ -0,0 +1,8 @@ +package co.orange.ddanzi.repository; + +import co.orange.ddanzi.domain.Banner; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BannerRepository extends JpaRepository { + Banner findByIsSelected(Boolean isSelected); +} diff --git a/src/main/java/co/orange/ddanzi/service/HomeService.java b/src/main/java/co/orange/ddanzi/service/HomeService.java index 03826327..c0886f2c 100644 --- a/src/main/java/co/orange/ddanzi/service/HomeService.java +++ b/src/main/java/co/orange/ddanzi/service/HomeService.java @@ -1,5 +1,6 @@ package co.orange.ddanzi.service; +import co.orange.ddanzi.domain.Banner; import co.orange.ddanzi.domain.product.*; import co.orange.ddanzi.dto.ProductInfo; import co.orange.ddanzi.dto.home.*; @@ -21,6 +22,7 @@ @Service public class HomeService { private final ProductRepository productRepository; + private final BannerRepository bannerRepository; private final DiscountRepository discountRepository; private final OptionRepository optionRepository; private final OptionDetailRepository optionDetailRepository; @@ -28,9 +30,12 @@ public class HomeService { @Transactional public ApiResponse getProductList(){ + Banner banner = bannerRepository.findByIsSelected(Boolean.TRUE); List productList = productRepository.findAllByStock(0); List productInfoList = setProductList(productList, interestProductRepository); - HomeResponseDto responseDto = HomeResponseDto.builder().productList(productInfoList).build(); + HomeResponseDto responseDto = HomeResponseDto.builder() + .homeImgUrl(banner.getImgUrl()) + .productList(productInfoList).build(); return ApiResponse.onSuccess(Success.GET_HOME_INFO_SUCCESS, responseDto); } @@ -93,6 +98,7 @@ public static List setProductList(List productList, Intere .name(product.getName()) .originPrice(product.getOriginPrice()) .salePrice(product.getOriginPrice() - product.getDiscountPrice()) + .imgUrl(product.getImgUrl()) .interestCount(interestProductRepository.countByProductIdWithLimit(product.getId())) .build()); } diff --git a/src/main/java/co/orange/ddanzi/service/ProductService.java b/src/main/java/co/orange/ddanzi/service/ProductService.java index 33f91982..f34db969 100644 --- a/src/main/java/co/orange/ddanzi/service/ProductService.java +++ b/src/main/java/co/orange/ddanzi/service/ProductService.java @@ -2,12 +2,19 @@ import co.orange.ddanzi.domain.product.Category; import co.orange.ddanzi.domain.product.Product; +import co.orange.ddanzi.domain.user.Address; +import co.orange.ddanzi.domain.user.User; +import co.orange.ddanzi.dto.AddressInfo; import co.orange.ddanzi.dto.item.ConfirmProductRequestDto; import co.orange.ddanzi.dto.item.ConfirmProductResponseDto; +import co.orange.ddanzi.dto.order.CheckProductResponseDto; +import co.orange.ddanzi.global.common.exception.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.repository.AddressRepository; import co.orange.ddanzi.repository.CategoryRepository; import co.orange.ddanzi.repository.ProductRepository; +import co.orange.ddanzi.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -20,12 +27,37 @@ @RequiredArgsConstructor @Service public class ProductService { + private final UserRepository userRepository; private final ProductRepository productRepository; + private final AddressRepository addressRepository; private final CategoryService categoryService; @Transactional public ApiResponse checkOrderProduct(String productId){ - return ApiResponse.onSuccess(Success.GET_ORDER_PRODUCT_SUCCESS, null); + Product product = productRepository.findById(productId).orElse(null); + if(product == null){ + return ApiResponse.onFailure(Error.PRODUCT_NOT_FOUND, null); + } + User user = userRepository.findById(1L).orElse(null); + Address address = addressRepository.findByUser(user); + + AddressInfo addressInfo = AddressInfo.builder() + .recipient(user.getAuthentication().getName()) + .zipCode(address.getZipCode()) + .address(address.getAddress()+" "+address.getDetailAddress()) + .phone(user.getAuthentication().getPhone()) + .build(); + + CheckProductResponseDto responseDto = CheckProductResponseDto.builder() + .productName(product.getName()) + .imgUrl(product.getImgUrl()) + .originPrice(product.getOriginPrice()) + .addressInfo(addressInfo) + .discountPrice(product.getDiscountPrice()) + .charge(null) + .totalPrice(product.getOriginPrice() - product.getDiscountPrice()) + .build(); + return ApiResponse.onSuccess(Success.GET_ORDER_PRODUCT_SUCCESS, responseDto); }