From a8c2d5588ac3058db8ccf090a6f5a4998119bca9 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 5 Jul 2024 02:11:01 +0900 Subject: [PATCH 1/5] feat: create check product api --- .../co/orange/ddanzi/dto/AddressInfo.java | 13 +++++++ .../dto/order/CheckProductResponseDto.java | 17 ++++++++++ .../orange/ddanzi/service/ProductService.java | 34 ++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/main/java/co/orange/ddanzi/dto/AddressInfo.java create mode 100644 src/main/java/co/orange/ddanzi/dto/order/CheckProductResponseDto.java 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/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/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); } From 2744b4aa6ec540ae281ca8e7c376c660c04435fa Mon Sep 17 00:00:00 2001 From: kang Date: Sun, 7 Jul 2024 23:08:45 +0900 Subject: [PATCH 2/5] feat: add homeImgUrl field --- src/main/java/co/orange/ddanzi/dto/home/HomeResponseDto.java | 1 + src/main/java/co/orange/ddanzi/service/HomeService.java | 1 + 2 files changed, 2 insertions(+) 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/service/HomeService.java b/src/main/java/co/orange/ddanzi/service/HomeService.java index 03826327..60735912 100644 --- a/src/main/java/co/orange/ddanzi/service/HomeService.java +++ b/src/main/java/co/orange/ddanzi/service/HomeService.java @@ -28,6 +28,7 @@ public class HomeService { @Transactional public ApiResponse getProductList(){ + //TODO : homeImgUrl 리턴 List productList = productRepository.findAllByStock(0); List productInfoList = setProductList(productList, interestProductRepository); HomeResponseDto responseDto = HomeResponseDto.builder().productList(productInfoList).build(); From 590e28223b45d6f2812cd658605dec3cb04ba249 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 12 Jul 2024 02:45:55 +0900 Subject: [PATCH 3/5] fix: add imgUrl in productInfoList builder --- src/main/java/co/orange/ddanzi/service/HomeService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/co/orange/ddanzi/service/HomeService.java b/src/main/java/co/orange/ddanzi/service/HomeService.java index 60735912..2564f4f7 100644 --- a/src/main/java/co/orange/ddanzi/service/HomeService.java +++ b/src/main/java/co/orange/ddanzi/service/HomeService.java @@ -94,6 +94,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()); } From 3aee97466c3cb4fb331f0714e181083418aa6a87 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 12 Jul 2024 02:53:31 +0900 Subject: [PATCH 4/5] feat: creat banner entity --- .../java/co/orange/ddanzi/domain/Banner.java | 26 +++++++++++++++++++ .../ddanzi/repository/BannerRepository.java | 8 ++++++ 2 files changed, 34 insertions(+) create mode 100644 src/main/java/co/orange/ddanzi/domain/Banner.java create mode 100644 src/main/java/co/orange/ddanzi/repository/BannerRepository.java 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/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); +} From 70c7a3345cd7f7378a549da651411ba8ddda8443 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 12 Jul 2024 02:53:54 +0900 Subject: [PATCH 5/5] feat: return banner img in home api --- src/main/java/co/orange/ddanzi/service/HomeService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/service/HomeService.java b/src/main/java/co/orange/ddanzi/service/HomeService.java index 2564f4f7..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,10 +30,12 @@ public class HomeService { @Transactional public ApiResponse getProductList(){ - //TODO : homeImgUrl 리턴 + 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); }