From 6444b55cb32605b64eaf0cb62f5000095740f1eb Mon Sep 17 00:00:00 2001 From: Somin Yun Date: Mon, 4 Mar 2024 03:31:50 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20#16=20product=20post,get=20api=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProductController.java | 41 +++++++ .../dto/request/CreateProductRequest.java | 20 ++++ .../soullive_a/dto/response/AgeResponse.java | 9 ++ .../dto/response/BrandImageResponse.java | 7 ++ .../dto/response/CreateProductResponse.java | 62 ++++++++++ .../dto/response/GenderResponse.java | 9 ++ .../dto/response/ProductImageResponse.java | 7 ++ .../dto/response/RangeResponse.java | 7 ++ .../soullive_a/repository/AgeRepository.java | 12 ++ .../repository/BrandImageRepository.java | 12 ++ .../repository/GenderRepository.java | 12 ++ .../repository/ProductImageRepository.java | 12 ++ .../repository/ProductRepository.java | 9 ++ .../repository/RangeRepository.java | 12 ++ .../soullive_a/service/ProductService.java | 9 ++ .../service/impl/ProductServiceImpl.java | 107 ++++++++++++++++++ 16 files changed, 347 insertions(+) create mode 100644 src/main/java/com/backend/soullive_a/controller/ProductController.java create mode 100644 src/main/java/com/backend/soullive_a/dto/request/CreateProductRequest.java create mode 100644 src/main/java/com/backend/soullive_a/dto/response/AgeResponse.java create mode 100644 src/main/java/com/backend/soullive_a/dto/response/BrandImageResponse.java create mode 100644 src/main/java/com/backend/soullive_a/dto/response/CreateProductResponse.java create mode 100644 src/main/java/com/backend/soullive_a/dto/response/GenderResponse.java create mode 100644 src/main/java/com/backend/soullive_a/dto/response/ProductImageResponse.java create mode 100644 src/main/java/com/backend/soullive_a/dto/response/RangeResponse.java create mode 100644 src/main/java/com/backend/soullive_a/repository/AgeRepository.java create mode 100644 src/main/java/com/backend/soullive_a/repository/BrandImageRepository.java create mode 100644 src/main/java/com/backend/soullive_a/repository/GenderRepository.java create mode 100644 src/main/java/com/backend/soullive_a/repository/ProductImageRepository.java create mode 100644 src/main/java/com/backend/soullive_a/repository/ProductRepository.java create mode 100644 src/main/java/com/backend/soullive_a/repository/RangeRepository.java create mode 100644 src/main/java/com/backend/soullive_a/service/ProductService.java create mode 100644 src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java diff --git a/src/main/java/com/backend/soullive_a/controller/ProductController.java b/src/main/java/com/backend/soullive_a/controller/ProductController.java new file mode 100644 index 0000000..9319250 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/controller/ProductController.java @@ -0,0 +1,41 @@ +package com.backend.soullive_a.controller; + +import com.backend.soullive_a.dto.request.CreateProductRequest; +import com.backend.soullive_a.dto.response.CreateProductResponse; +import com.backend.soullive_a.exception.base.BaseResponse; +import com.backend.soullive_a.service.ProductService; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +@Slf4j +@RestController +@RequestMapping("/product") +@RequiredArgsConstructor +public class ProductController { + + private final ProductService productService; + + @PostMapping("") + public BaseResponse createProduct( + @RequestBody @Valid CreateProductRequest createProductRequest + ) { + return BaseResponse.builder() + .isSuccess(true) + .code(200) + .message("광고 상품을 등록했습니다") + .data(productService.createProduct(createProductRequest)) + .build(); + } + + @GetMapping("/{id}") + public BaseResponse getProduct(@PathVariable Long id) { + return BaseResponse.builder() + .isSuccess(true) + .code(200) + .message("productId = " + id + " 광고 상품을 불러옵니다") + .data(productService.getProduct(id)) + .build(); + } +} diff --git a/src/main/java/com/backend/soullive_a/dto/request/CreateProductRequest.java b/src/main/java/com/backend/soullive_a/dto/request/CreateProductRequest.java new file mode 100644 index 0000000..53ac691 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/request/CreateProductRequest.java @@ -0,0 +1,20 @@ +package com.backend.soullive_a.dto.request; + +import com.backend.soullive_a.constant.AgeType; +import com.backend.soullive_a.constant.GenderType; +import jakarta.validation.constraints.NotNull; + +import java.util.List; + +public record CreateProductRequest ( + @NotNull String company, + String brand, + @NotNull List brandImage, + @NotNull String product, + @NotNull String characteristic, + @NotNull List productImage, + @NotNull List gender, + @NotNull List age, + @NotNull List range +){ +} diff --git a/src/main/java/com/backend/soullive_a/dto/response/AgeResponse.java b/src/main/java/com/backend/soullive_a/dto/response/AgeResponse.java new file mode 100644 index 0000000..1e61cb4 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/response/AgeResponse.java @@ -0,0 +1,9 @@ +package com.backend.soullive_a.dto.response; + +import com.backend.soullive_a.constant.AgeType; + +public record AgeResponse( + Long ageId, + AgeType ageType +) { +} diff --git a/src/main/java/com/backend/soullive_a/dto/response/BrandImageResponse.java b/src/main/java/com/backend/soullive_a/dto/response/BrandImageResponse.java new file mode 100644 index 0000000..18837fe --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/response/BrandImageResponse.java @@ -0,0 +1,7 @@ +package com.backend.soullive_a.dto.response; + +public record BrandImageResponse ( + Long brandImageId, + String brandImage +){ +} diff --git a/src/main/java/com/backend/soullive_a/dto/response/CreateProductResponse.java b/src/main/java/com/backend/soullive_a/dto/response/CreateProductResponse.java new file mode 100644 index 0000000..ccb1e4a --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/response/CreateProductResponse.java @@ -0,0 +1,62 @@ +package com.backend.soullive_a.dto.response; + +import com.backend.soullive_a.entity.*; +import lombok.Builder; + +import java.util.List; +import java.util.stream.Collectors; + +@Builder +public record CreateProductResponse( + Long productId, + String company, + String brand, + List brandImages, + String product, + String characteristic, + List productImages, + List genders, + List ages, + List ranges +) { + public static CreateProductResponse fromProduct( + Product product, + List brandImage, + List productImage, + List genderType, + List ageType, + List rangeType) { + List brandImages = brandImage.stream() + .map(image -> new BrandImageResponse(image.getId(), image.getBrandImage())) + .collect(Collectors.toList()); + + List productImages = productImage.stream() + .map(image -> new ProductImageResponse(image.getId(), image.getProductImage())) + .collect(Collectors.toList()); + + List genders = genderType.stream() + .map(gender -> new GenderResponse(gender.getId(), gender.getGender())) + .collect(Collectors.toList()); + + List ages = ageType.stream() + .map(age -> new AgeResponse(age.getId(), age.getAge())) + .collect(Collectors.toList()); + + List ranges = rangeType.stream() + .map(range -> new RangeResponse(range.getId(), range.getRange())) + .collect(Collectors.toList()); + + return CreateProductResponse.builder() + .productId(product.getId()) + .company(product.getProduct()) + .brand(product.getBrand()) + .brandImages(brandImages) + .product(product.getProduct()) + .characteristic(product.getCharacteristic()) + .productImages(productImages) + .genders(genders) + .ages(ages) + .ranges(ranges) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/backend/soullive_a/dto/response/GenderResponse.java b/src/main/java/com/backend/soullive_a/dto/response/GenderResponse.java new file mode 100644 index 0000000..528225d --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/response/GenderResponse.java @@ -0,0 +1,9 @@ +package com.backend.soullive_a.dto.response; + +import com.backend.soullive_a.constant.GenderType; + +public record GenderResponse ( + Long genderId, + GenderType gender +){ +} diff --git a/src/main/java/com/backend/soullive_a/dto/response/ProductImageResponse.java b/src/main/java/com/backend/soullive_a/dto/response/ProductImageResponse.java new file mode 100644 index 0000000..4f5887e --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/response/ProductImageResponse.java @@ -0,0 +1,7 @@ +package com.backend.soullive_a.dto.response; + +public record ProductImageResponse( + Long productImageId, + String productImage +) { +} diff --git a/src/main/java/com/backend/soullive_a/dto/response/RangeResponse.java b/src/main/java/com/backend/soullive_a/dto/response/RangeResponse.java new file mode 100644 index 0000000..033c7f2 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/dto/response/RangeResponse.java @@ -0,0 +1,7 @@ +package com.backend.soullive_a.dto.response; + +public record RangeResponse( + Long rangeId, + String range +) { +} diff --git a/src/main/java/com/backend/soullive_a/repository/AgeRepository.java b/src/main/java/com/backend/soullive_a/repository/AgeRepository.java new file mode 100644 index 0000000..1ed8b96 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/AgeRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.entity.Age; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface AgeRepository extends JpaRepository { + List findAllByProductId(Long productId); +} \ No newline at end of file diff --git a/src/main/java/com/backend/soullive_a/repository/BrandImageRepository.java b/src/main/java/com/backend/soullive_a/repository/BrandImageRepository.java new file mode 100644 index 0000000..1205189 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/BrandImageRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.entity.BrandImage; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface BrandImageRepository extends JpaRepository { + List findAllByProductId(Long productId); +} diff --git a/src/main/java/com/backend/soullive_a/repository/GenderRepository.java b/src/main/java/com/backend/soullive_a/repository/GenderRepository.java new file mode 100644 index 0000000..b059aca --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/GenderRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.entity.Gender; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface GenderRepository extends JpaRepository { + List findAllByProductId(Long productId); +} \ No newline at end of file diff --git a/src/main/java/com/backend/soullive_a/repository/ProductImageRepository.java b/src/main/java/com/backend/soullive_a/repository/ProductImageRepository.java new file mode 100644 index 0000000..a61d09f --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/ProductImageRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.entity.ProductImage; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface ProductImageRepository extends JpaRepository { + List findAllByProductId(Long productId); +} \ No newline at end of file diff --git a/src/main/java/com/backend/soullive_a/repository/ProductRepository.java b/src/main/java/com/backend/soullive_a/repository/ProductRepository.java new file mode 100644 index 0000000..cf45a3c --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/ProductRepository.java @@ -0,0 +1,9 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.entity.Product; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ProductRepository extends JpaRepository { +} diff --git a/src/main/java/com/backend/soullive_a/repository/RangeRepository.java b/src/main/java/com/backend/soullive_a/repository/RangeRepository.java new file mode 100644 index 0000000..e286147 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/repository/RangeRepository.java @@ -0,0 +1,12 @@ +package com.backend.soullive_a.repository; + +import com.backend.soullive_a.entity.Range; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface RangeRepository extends JpaRepository { + List findAllByProductId(Long productId); +} \ No newline at end of file diff --git a/src/main/java/com/backend/soullive_a/service/ProductService.java b/src/main/java/com/backend/soullive_a/service/ProductService.java new file mode 100644 index 0000000..3860829 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/service/ProductService.java @@ -0,0 +1,9 @@ +package com.backend.soullive_a.service; + +import com.backend.soullive_a.dto.request.CreateProductRequest; +import com.backend.soullive_a.dto.response.CreateProductResponse; + +public interface ProductService { + CreateProductResponse createProduct(CreateProductRequest request); + CreateProductResponse getProduct(Long id); +} diff --git a/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java b/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java new file mode 100644 index 0000000..0552877 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java @@ -0,0 +1,107 @@ +package com.backend.soullive_a.service.impl; + +import com.backend.soullive_a.constant.AgeType; +import com.backend.soullive_a.constant.GenderType; +import com.backend.soullive_a.dto.request.CreateProductRequest; +import com.backend.soullive_a.dto.response.CreateProductResponse; +import com.backend.soullive_a.entity.*; +import com.backend.soullive_a.repository.*; +import com.backend.soullive_a.service.ProductService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class ProductServiceImpl implements ProductService { + + private final ProductRepository productRepository; + private final BrandImageRepository brandImageRepository; + private final ProductImageRepository productImageRepository; + private final GenderRepository genderRepository; + private final AgeRepository ageRepository; + private final RangeRepository rangeRepository; + + @Override + @Transactional + public CreateProductResponse createProduct(CreateProductRequest request){ + log.info("productservice 들어옴"); + Product product = Product.builder() + .company(request.company()) + .brand(request.brand()) + .product(request.product()) + .characteristic(request.characteristic()) + .build(); + productRepository.save(product); + + List brandImages = new ArrayList<>(); + for (String image : request.brandImage()) { + BrandImage brandImage = BrandImage.builder() + .product(product) + .brandImage(image) + .build(); + brandImages.add(brandImage); + brandImageRepository.save(brandImage); + } + + List productImages = new ArrayList<>(); + for (String image : request.productImage()) { + ProductImage productImage = ProductImage.builder() + .product(product) + .productImage(image) + .build(); + productImages.add(productImage); + productImageRepository.save(productImage); + } + + List genders = new ArrayList<>(); + for (GenderType genderType : request.gender()) { + Gender gender = Gender.builder() + .product(product) + .gender(genderType) + .build(); + genders.add(gender); + genderRepository.save(gender); + } + + List ages = new ArrayList<>(); + for (AgeType ageType : request.age()) { + Age age = Age.builder() + .product(product) + .age(ageType) + .build(); + ages.add(age); + ageRepository.save(age); + } + + List ranges = new ArrayList<>(); + for (String rangeType : request.range()) { + Range range = Range.builder() + .product(product) + .range(rangeType) + .build(); + ranges.add(range); + rangeRepository.save(range); + } + return CreateProductResponse.fromProduct(product, brandImages, productImages, genders, ages, ranges); + } + + @Override + @Transactional + public CreateProductResponse getProduct(Long productId) { + Product product=productRepository.findById(productId) + .orElseThrow(); + List brandImages = brandImageRepository.findAllByProductId(productId); + List productImages = productImageRepository.findAllByProductId(productId); + List genders = genderRepository.findAllByProductId(productId); + List ages = ageRepository.findAllByProductId(productId); + List ranges=rangeRepository.findAllByProductId(productId); + return CreateProductResponse.fromProduct(product, brandImages, productImages, genders, ages, ranges); + } +} From 37da8d210e013a293f0a73c255da2c602671128d Mon Sep 17 00:00:00 2001 From: Somin Yun Date: Mon, 4 Mar 2024 11:54:24 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20#16=20=EB=AA=A8=EB=93=A0=20product?= =?UTF-8?q?=20get=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProductController.java | 26 +++++++++++---- ...ductResponse.java => ProductResponse.java} | 6 ++-- .../soullive_a/service/ProductService.java | 11 +++++-- .../service/impl/ProductServiceImpl.java | 32 ++++++++++++++----- 4 files changed, 54 insertions(+), 21 deletions(-) rename src/main/java/com/backend/soullive_a/dto/response/{CreateProductResponse.java => ProductResponse.java} (94%) diff --git a/src/main/java/com/backend/soullive_a/controller/ProductController.java b/src/main/java/com/backend/soullive_a/controller/ProductController.java index 9319250..b62a026 100644 --- a/src/main/java/com/backend/soullive_a/controller/ProductController.java +++ b/src/main/java/com/backend/soullive_a/controller/ProductController.java @@ -1,7 +1,7 @@ package com.backend.soullive_a.controller; import com.backend.soullive_a.dto.request.CreateProductRequest; -import com.backend.soullive_a.dto.response.CreateProductResponse; +import com.backend.soullive_a.dto.response.ProductResponse; import com.backend.soullive_a.exception.base.BaseResponse; import com.backend.soullive_a.service.ProductService; import jakarta.validation.Valid; @@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import java.util.List; + @Slf4j @RestController @RequestMapping("/product") @@ -18,23 +20,33 @@ public class ProductController { private final ProductService productService; @PostMapping("") - public BaseResponse createProduct( + public BaseResponse createProduct( @RequestBody @Valid CreateProductRequest createProductRequest ) { - return BaseResponse.builder() + return BaseResponse.builder() .isSuccess(true) .code(200) - .message("광고 상품을 등록했습니다") + .message("광고 상품을 등록했습니다.") .data(productService.createProduct(createProductRequest)) .build(); } + @GetMapping() + public BaseResponse> getAllProduct() { + return BaseResponse.>builder() + .isSuccess(true) + .code(200) + .message("모든 광고 상품을 불러왔습니다.") + .data(productService.getAllProduct()) + .build(); + } + @GetMapping("/{id}") - public BaseResponse getProduct(@PathVariable Long id) { - return BaseResponse.builder() + public BaseResponse getProduct(@PathVariable Long id) { + return BaseResponse.builder() .isSuccess(true) .code(200) - .message("productId = " + id + " 광고 상품을 불러옵니다") + .message("productId = " + id + " 광고 상품을 불러왔습니다.") .data(productService.getProduct(id)) .build(); } diff --git a/src/main/java/com/backend/soullive_a/dto/response/CreateProductResponse.java b/src/main/java/com/backend/soullive_a/dto/response/ProductResponse.java similarity index 94% rename from src/main/java/com/backend/soullive_a/dto/response/CreateProductResponse.java rename to src/main/java/com/backend/soullive_a/dto/response/ProductResponse.java index ccb1e4a..45505f1 100644 --- a/src/main/java/com/backend/soullive_a/dto/response/CreateProductResponse.java +++ b/src/main/java/com/backend/soullive_a/dto/response/ProductResponse.java @@ -7,7 +7,7 @@ import java.util.stream.Collectors; @Builder -public record CreateProductResponse( +public record ProductResponse( Long productId, String company, String brand, @@ -19,7 +19,7 @@ public record CreateProductResponse( List ages, List ranges ) { - public static CreateProductResponse fromProduct( + public static ProductResponse fromProduct( Product product, List brandImage, List productImage, @@ -46,7 +46,7 @@ public static CreateProductResponse fromProduct( .map(range -> new RangeResponse(range.getId(), range.getRange())) .collect(Collectors.toList()); - return CreateProductResponse.builder() + return ProductResponse.builder() .productId(product.getId()) .company(product.getProduct()) .brand(product.getBrand()) diff --git a/src/main/java/com/backend/soullive_a/service/ProductService.java b/src/main/java/com/backend/soullive_a/service/ProductService.java index 3860829..49f6616 100644 --- a/src/main/java/com/backend/soullive_a/service/ProductService.java +++ b/src/main/java/com/backend/soullive_a/service/ProductService.java @@ -1,9 +1,14 @@ package com.backend.soullive_a.service; import com.backend.soullive_a.dto.request.CreateProductRequest; -import com.backend.soullive_a.dto.response.CreateProductResponse; +import com.backend.soullive_a.dto.response.ProductResponse; + +import java.util.List; public interface ProductService { - CreateProductResponse createProduct(CreateProductRequest request); - CreateProductResponse getProduct(Long id); + ProductResponse createProduct(CreateProductRequest request); + + ProductResponse getProduct(Long id); + + List getAllProduct(); } diff --git a/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java b/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java index 0552877..24439c1 100644 --- a/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java @@ -3,7 +3,7 @@ import com.backend.soullive_a.constant.AgeType; import com.backend.soullive_a.constant.GenderType; import com.backend.soullive_a.dto.request.CreateProductRequest; -import com.backend.soullive_a.dto.response.CreateProductResponse; +import com.backend.soullive_a.dto.response.ProductResponse; import com.backend.soullive_a.entity.*; import com.backend.soullive_a.repository.*; import com.backend.soullive_a.service.ProductService; @@ -30,7 +30,7 @@ public class ProductServiceImpl implements ProductService { @Override @Transactional - public CreateProductResponse createProduct(CreateProductRequest request){ + public ProductResponse createProduct(CreateProductRequest request) { log.info("productservice 들어옴"); Product product = Product.builder() .company(request.company()) @@ -89,19 +89,35 @@ public CreateProductResponse createProduct(CreateProductRequest request){ ranges.add(range); rangeRepository.save(range); } - return CreateProductResponse.fromProduct(product, brandImages, productImages, genders, ages, ranges); + return ProductResponse.fromProduct(product, brandImages, productImages, genders, ages, ranges); } @Override @Transactional - public CreateProductResponse getProduct(Long productId) { - Product product=productRepository.findById(productId) + public ProductResponse getProduct(Long productId) { + Product product = productRepository.findById(productId) .orElseThrow(); List brandImages = brandImageRepository.findAllByProductId(productId); List productImages = productImageRepository.findAllByProductId(productId); List genders = genderRepository.findAllByProductId(productId); List ages = ageRepository.findAllByProductId(productId); - List ranges=rangeRepository.findAllByProductId(productId); - return CreateProductResponse.fromProduct(product, brandImages, productImages, genders, ages, ranges); + List ranges = rangeRepository.findAllByProductId(productId); + return ProductResponse.fromProduct(product, brandImages, productImages, genders, ages, ranges); } -} + + @Override + @Transactional + public List getAllProduct() { + List products = productRepository.findAll(); + List productResponses = new ArrayList<>(); + for (Product product : products) { + List brandImages = brandImageRepository.findAllByProductId(product.getId()); + List productImages = productImageRepository.findAllByProductId(product.getId()); + List genders = genderRepository.findAllByProductId(product.getId()); + List ages = ageRepository.findAllByProductId(product.getId()); + List ranges = rangeRepository.findAllByProductId(product.getId()); + productResponses.add(ProductResponse.fromProduct(product, brandImages, productImages, genders, ages, ranges)); + } + return productResponses; + } +} \ No newline at end of file From 9cdff4e57582492479e0a80f9a4deae46b89fbff Mon Sep 17 00:00:00 2001 From: Somin Yun Date: Mon, 4 Mar 2024 12:05:14 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20#16=20=EB=AA=A8=EB=93=A0=20product?= =?UTF-8?q?=20get=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/backend/soullive_a/dto/response/ProductResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backend/soullive_a/dto/response/ProductResponse.java b/src/main/java/com/backend/soullive_a/dto/response/ProductResponse.java index 45505f1..9d9b173 100644 --- a/src/main/java/com/backend/soullive_a/dto/response/ProductResponse.java +++ b/src/main/java/com/backend/soullive_a/dto/response/ProductResponse.java @@ -48,7 +48,7 @@ public static ProductResponse fromProduct( return ProductResponse.builder() .productId(product.getId()) - .company(product.getProduct()) + .company(product.getCompany()) .brand(product.getBrand()) .brandImages(brandImages) .product(product.getProduct()) From 398d27cf3861c8e5389312a74d2f928dda600cbb Mon Sep 17 00:00:00 2001 From: Somin Yun Date: Mon, 4 Mar 2024 19:20:07 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20#16=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/soullive_a/service/impl/ProductServiceImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java b/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java index 24439c1..598702f 100644 --- a/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/backend/soullive_a/service/impl/ProductServiceImpl.java @@ -18,7 +18,6 @@ @Slf4j @Service @RequiredArgsConstructor -@Transactional(readOnly = true) public class ProductServiceImpl implements ProductService { private final ProductRepository productRepository; @@ -31,7 +30,6 @@ public class ProductServiceImpl implements ProductService { @Override @Transactional public ProductResponse createProduct(CreateProductRequest request) { - log.info("productservice 들어옴"); Product product = Product.builder() .company(request.company()) .brand(request.brand()) @@ -93,7 +91,7 @@ public ProductResponse createProduct(CreateProductRequest request) { } @Override - @Transactional + @Transactional(readOnly = true) public ProductResponse getProduct(Long productId) { Product product = productRepository.findById(productId) .orElseThrow(); @@ -106,7 +104,7 @@ public ProductResponse getProduct(Long productId) { } @Override - @Transactional + @Transactional(readOnly = true) public List getAllProduct() { List products = productRepository.findAll(); List productResponses = new ArrayList<>();