|
1 | 1 | package com.univ.sohwakhaeng.product.service;
|
2 | 2 |
|
3 | 3 | import com.amazonaws.services.s3.AmazonS3Client;
|
| 4 | +import com.univ.sohwakhaeng.enterprise.Enterprise; |
| 5 | +import com.univ.sohwakhaeng.enterprise.exception.EnterpriseNotFoundException; |
| 6 | +import com.univ.sohwakhaeng.enterprise.service.EnterpriseService; |
4 | 7 | import com.univ.sohwakhaeng.product.Product;
|
| 8 | +import com.univ.sohwakhaeng.product.api.dto.ProductRequestDto; |
| 9 | +import com.univ.sohwakhaeng.product.api.dto.ProductResponseDto; |
5 | 10 | import com.univ.sohwakhaeng.product.exception.ProductNotFoundException;
|
6 | 11 | import com.univ.sohwakhaeng.product.repository.ProductRepository;
|
| 12 | +import java.util.List; |
7 | 13 | import lombok.RequiredArgsConstructor;
|
8 | 14 | import org.springframework.beans.factory.annotation.Value;
|
9 | 15 | import org.springframework.stereotype.Service;
|
|
15 | 21 | @RequiredArgsConstructor
|
16 | 22 | public class ProductService {
|
17 | 23 |
|
18 |
| - private final ProductRepository productRepository; |
19 |
| - private final AmazonS3Client amazonS3Client; |
| 24 | + private EnterpriseService enterpriseService; |
| 25 | + private ProductRepository productRepository; |
| 26 | + private AmazonS3Client amazonS3Client; |
| 27 | + public ProductService(EnterpriseService enterpriseService, ProductRepository productRepository, AmazonS3Client amazonS3Client) { |
| 28 | + this.enterpriseService = enterpriseService; |
| 29 | + this.productRepository = productRepository; |
| 30 | + this.amazonS3Client = amazonS3Client; |
| 31 | + } |
| 32 | + |
20 | 33 | @Value("${cloud.aws.s3.bucket}")
|
21 | 34 | private String awsBucket;
|
22 | 35 |
|
| 36 | + public Void postProducts(List<ProductRequestDto> dtos) throws EnterpriseNotFoundException { |
| 37 | + for (ProductRequestDto dto : dtos) { |
| 38 | + Enterprise enterprise = enterpriseService.getEnterpriseEntityById(dto.enterpriseId()); |
| 39 | + saveProduct(Product.createProduct(dto, enterprise)); |
| 40 | + } |
| 41 | + return null; |
| 42 | + } |
| 43 | + |
| 44 | + public void saveProduct(Product product) { |
| 45 | + productRepository.save(product); |
| 46 | + } |
| 47 | + |
23 | 48 | @Transactional(readOnly = true)
|
24 | 49 | public Product getProductById(Long id) throws ProductNotFoundException {
|
25 | 50 | return findProductById(id);
|
|
0 commit comments