Skip to content

Commit

Permalink
chore: get discount info from discount entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kang1221 committed Jul 16, 2024
1 parent 3303757 commit 017a847
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/co/orange/ddanzi/service/ProductService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.orange.ddanzi.service;

import co.orange.ddanzi.domain.product.Category;
import co.orange.ddanzi.domain.product.Discount;
import co.orange.ddanzi.domain.product.Product;
import co.orange.ddanzi.domain.user.Address;
import co.orange.ddanzi.domain.user.User;
Expand All @@ -11,24 +12,21 @@
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 co.orange.ddanzi.repository.*;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Slf4j
@RequiredArgsConstructor
@Service
public class ProductService {
private final UserRepository userRepository;
private final ProductRepository productRepository;
private final DiscountRepository discountRepository;
private final AddressRepository addressRepository;
private final CategoryService categoryService;

Expand All @@ -38,6 +36,7 @@ public ApiResponse<?> checkOrderProduct(String productId){
if(product == null){
return ApiResponse.onFailure(Error.PRODUCT_NOT_FOUND, null);
}
Discount discount = discountRepository.findById(productId).orElse(null);
User user = userRepository.findById(1L).orElse(null);
Address address = addressRepository.findByUser(user);

Expand All @@ -53,9 +52,9 @@ public ApiResponse<?> checkOrderProduct(String productId){
.imgUrl(product.getImgUrl())
.originPrice(product.getOriginPrice())
.addressInfo(addressInfo)
.discountPrice(product.getDiscountPrice())
.discountPrice(discount.getDiscountPrice())
.charge(null)
.totalPrice(product.getOriginPrice() - product.getDiscountPrice())
.totalPrice(product.getOriginPrice() - discount.getDiscountPrice())
.build();
return ApiResponse.onSuccess(Success.GET_ORDER_PRODUCT_SUCCESS, responseDto);
}
Expand All @@ -78,11 +77,12 @@ public ApiResponse<?> confirmProduct(ConfirmProductRequestDto requestDto){
product = newProduct;
log.info("상품 등록 완료 -> product_id: {}",product.getId());
}
Discount discount = discountRepository.findById(product.getId()).orElse(null);
ConfirmProductResponseDto responseDto = ConfirmProductResponseDto.builder()
.productId(product.getId())
.productName(product.getName())
.originPrice(product.getOriginPrice())
.salePrice(product.getOriginPrice() - product.getDiscountPrice())
.salePrice(product.getOriginPrice() - discount.getDiscountPrice())
.build();
return ApiResponse.onSuccess(Success.CREATE_PRODUCT_SUCCESS, responseDto);
}
Expand Down

0 comments on commit 017a847

Please sign in to comment.