Skip to content

Commit

Permalink
Merge pull request #31 from Orange-Co/feature/home
Browse files Browse the repository at this point in the history
Feat/home: reflect modifications
  • Loading branch information
Kang1221 authored Jul 11, 2024
2 parents d31625f + 70c7a33 commit 5b267ee
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/main/java/co/orange/ddanzi/domain/Banner.java
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/AddressInfo.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
@Getter
@Builder
public class HomeResponseDto {
private String homeImgUrl;
private List<ProductInfo> productList;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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, Integer> {
Banner findByIsSelected(Boolean isSelected);
}
8 changes: 7 additions & 1 deletion src/main/java/co/orange/ddanzi/service/HomeService.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -21,16 +22,20 @@
@Service
public class HomeService {
private final ProductRepository productRepository;
private final BannerRepository bannerRepository;
private final DiscountRepository discountRepository;
private final OptionRepository optionRepository;
private final OptionDetailRepository optionDetailRepository;
private final InterestProductRepository interestProductRepository;

@Transactional
public ApiResponse<?> getProductList(){
Banner banner = bannerRepository.findByIsSelected(Boolean.TRUE);
List<Product> productList = productRepository.findAllByStock(0);
List<ProductInfo> 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);
}

Expand Down Expand Up @@ -93,6 +98,7 @@ public static List<ProductInfo> setProductList(List<Product> productList, Intere
.name(product.getName())
.originPrice(product.getOriginPrice())
.salePrice(product.getOriginPrice() - product.getDiscountPrice())
.imgUrl(product.getImgUrl())
.interestCount(interestProductRepository.countByProductIdWithLimit(product.getId()))
.build());
}
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/co/orange/ddanzi/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}


Expand Down

0 comments on commit 5b267ee

Please sign in to comment.