Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/We-Food-C-I-A/BACK into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
minm063 committed Aug 24, 2024
2 parents 4caef6c + fedb2af commit 41afdcf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -18,6 +19,7 @@
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class UploadImageRequestDto {
@NotNull(message = "파일이 입력되지 않았습니다.")
private List<MultipartFile> files;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wefood.back.product.repository;

import com.wefood.back.product.entity.Item;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

/**
Expand All @@ -11,4 +12,5 @@
*/
public interface ItemRepository extends JpaRepository<Item,Long> {

Optional<Item> findByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import com.wefood.back.global.image.dto.ImageDetailResponse;
import com.wefood.back.product.dto.ProductResponse;
import com.wefood.back.product.entity.Category;
import com.wefood.back.product.entity.Item;
import com.wefood.back.product.entity.Product;
import com.wefood.back.product.entity.ProductCategory;
import com.wefood.back.product.entity.ProductTag;
import com.wefood.back.product.entity.Tag;
import com.wefood.back.product.exception.CategoryNotFoundException;
import com.wefood.back.product.exception.ProductNotFoundException;
import com.wefood.back.product.repository.CategoryRepository;
import com.wefood.back.product.repository.ItemRepository;
import com.wefood.back.product.repository.ProductCategoryRepository;
import com.wefood.back.product.repository.ProductRepository;
import com.wefood.back.product.repository.ProductTagRepository;
Expand Down Expand Up @@ -52,19 +54,22 @@ public class ProductService {
private final ProductCategoryRepository productCategoryRepository;
private final FarmRepository farmRepository;

private final ItemRepository itemRepository;

private final TagRepository tagRepository;

public ProductService(ProductRepository productRepository,
ProductTagRepository productTagRepository, ProductImageRepository productImageRepository, CategoryRepository categoryRepository, FarmImageRepository farmImageRepository,
ProductCategoryRepository productCategoryRepository, FarmRepository farmRepository,
TagRepository tagRepository) {
ItemRepository itemRepository, TagRepository tagRepository) {
this.productRepository = productRepository;
this.productTagRepository = productTagRepository;
this.productImageRepository = productImageRepository;
this.categoryRepository = categoryRepository;
this.farmImageRepository = farmImageRepository;
this.productCategoryRepository = productCategoryRepository;
this.farmRepository = farmRepository;
this.itemRepository = itemRepository;
this.tagRepository = tagRepository;
}

Expand Down Expand Up @@ -156,8 +161,9 @@ public Page<ProductResponse> getProductByTag(String search, Pageable pageable) {
public Long create(Long farmId, CreateProductRequest createProductRequest) {
Farm farm = farmRepository.findById(farmId).orElseThrow(()->new IllegalArgumentException(farmId+"의 농가는 존재하지않습니다"));
Category category = categoryRepository.findById(createProductRequest.getCategoryId()).orElseThrow(()->new IllegalArgumentException(createProductRequest.getCategoryId()+"의 카테고리는 존재하지않습니다"));
Item item = itemRepository.findByName("해당 없음").orElseThrow(()->new IllegalArgumentException("예상치못한 에러값이 들어왔습니다"));
Product product = productRepository.save(Product.builder().name("["+farm.getName()+"] "+createProductRequest.getName()).price(createProductRequest.getPrice()).detail(
createProductRequest.getDetail()).isStatus(true).farm(farm).build());
createProductRequest.getDetail()).isStatus(true).farm(farm).item(item).build());
productCategoryRepository.save(ProductCategory.builder().pk(ProductCategory.Pk.builder().productId(
product.getId()).categoryId(
category.getId())
Expand Down

0 comments on commit 41afdcf

Please sign in to comment.