From e66a124153bb0af6dbee42180edebd8e32f56d2e Mon Sep 17 00:00:00 2001 From: Ogu1208 Date: Tue, 2 Jul 2024 00:30:33 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Product=20Upper=20Naming=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ProductLine 통합테스트 수정 필요 --- .../common/config/RepositoryConfig.java | 17 ++++---- .../product/controller/ProductController.java | 4 +- .../ProductJPARepositoryAdapter.java | 2 +- ...ory.java => ProductMybatisRepository.java} | 9 +++- .../product/repository/ProductRepository.java | 9 +--- .../product/service/ProductService.java | 3 +- src/main/resources/application-db.yml | 2 +- src/main/resources/mappers/ProductMapper.xml | 2 +- .../product/service/ProductServiceTest.java | 26 ++++++------ .../ProductLineControllerIntegrationTest.java | 2 + src/test/resources/application-test-db.yml | 42 +++++++++++++++++++ 11 files changed, 82 insertions(+), 36 deletions(-) rename src/main/java/org/store/clothstar/product/repository/{UpperProductRepository.java => ProductMybatisRepository.java} (54%) create mode 100644 src/test/resources/application-test-db.yml diff --git a/src/main/java/org/store/clothstar/common/config/RepositoryConfig.java b/src/main/java/org/store/clothstar/common/config/RepositoryConfig.java index 183cd481..ef0d7ef0 100644 --- a/src/main/java/org/store/clothstar/common/config/RepositoryConfig.java +++ b/src/main/java/org/store/clothstar/common/config/RepositoryConfig.java @@ -11,9 +11,10 @@ import org.store.clothstar.member.repository.SellerRepository; import org.store.clothstar.product.repository.ProductJPARepository; import org.store.clothstar.product.repository.ProductJPARepositoryAdapter; +import org.store.clothstar.product.repository.ProductMybatisRepository; import org.store.clothstar.product.repository.ProductRepository; -import org.store.clothstar.product.repository.UpperProductRepository; import org.store.clothstar.productLine.repository.ProductLineJPARepository; +import org.store.clothstar.productLine.repository.ProductLineMybatisRepository; import org.store.clothstar.productLine.repository.ProductLineRepository; import org.store.clothstar.productLine.repository.adapter.ProductLineJPARepositoryAdapter; @@ -23,7 +24,7 @@ public class RepositoryConfig { @Bean - @Primary +// @Primary @ConditionalOnProperty(name = "app.repository.type", havingValue = "jpa", matchIfMissing = true) public ProductLineRepository jpaProductLineRepository(CategoryJpaRepository categoryJpaRepository, SellerRepository sellerRepository, @@ -34,23 +35,25 @@ public ProductLineRepository jpaProductLineRepository(CategoryJpaRepository cate } @Bean + @Primary @ConditionalOnProperty(name = "app.repository.type", havingValue = "mybatis") public ProductLineRepository mybatisProductLineRepository(SqlSessionTemplate sqlSessionTemplate) { log.info("Configuring ProductLine MyBatis repository"); - return sqlSessionTemplate.getMapper(ProductLineRepository.class); + return sqlSessionTemplate.getMapper(ProductLineMybatisRepository.class); } @Bean - @Primary +// @Primary @ConditionalOnProperty(name = "app.repository.type", havingValue = "jpa", matchIfMissing = true) - public UpperProductRepository jpaProductRepository(ProductJPARepository productJPARepository, ProductLineJPARepository productLineJPARepository) { + public ProductRepository jpaProductRepository(ProductJPARepository productJPARepository, ProductLineJPARepository productLineJPARepository) { log.info("Configuring Product JPA repository"); return new ProductJPARepositoryAdapter(productJPARepository, productLineJPARepository); } @Bean + @Primary @ConditionalOnProperty(name = "app.repository.type", havingValue = "mybatis") - public UpperProductRepository mybatisProductRepository(SqlSessionTemplate sqlSessionTemplate) { + public ProductRepository mybatisProductRepository(SqlSessionTemplate sqlSessionTemplate) { log.info("Configuring Product MyBatis repository"); - return sqlSessionTemplate.getMapper(ProductRepository.class); + return sqlSessionTemplate.getMapper(ProductMybatisRepository.class); } } diff --git a/src/main/java/org/store/clothstar/product/controller/ProductController.java b/src/main/java/org/store/clothstar/product/controller/ProductController.java index a40fd6e0..06f1cc19 100644 --- a/src/main/java/org/store/clothstar/product/controller/ProductController.java +++ b/src/main/java/org/store/clothstar/product/controller/ProductController.java @@ -12,7 +12,7 @@ import org.store.clothstar.product.dto.request.CreateProductRequest; import org.store.clothstar.product.dto.request.UpdateProductRequest; import org.store.clothstar.product.dto.response.ProductResponse; -import org.store.clothstar.product.repository.ProductRepository; +import org.store.clothstar.product.repository.ProductMybatisRepository; import org.store.clothstar.product.service.ProductService; import java.net.URI; @@ -24,7 +24,7 @@ public class ProductController { private final ProductService productService; - private final ProductRepository productRepository; + private final ProductMybatisRepository productMybatisRepository; /* @Operation(summary = "전체 상품 옵션 조회", description = "상품 Id의 모든 상품 옵션을 조회한다.") diff --git a/src/main/java/org/store/clothstar/product/repository/ProductJPARepositoryAdapter.java b/src/main/java/org/store/clothstar/product/repository/ProductJPARepositoryAdapter.java index 908fe094..739456b6 100644 --- a/src/main/java/org/store/clothstar/product/repository/ProductJPARepositoryAdapter.java +++ b/src/main/java/org/store/clothstar/product/repository/ProductJPARepositoryAdapter.java @@ -15,7 +15,7 @@ @Repository @RequiredArgsConstructor -public class ProductJPARepositoryAdapter implements UpperProductRepository { +public class ProductJPARepositoryAdapter implements ProductRepository { private final ProductJPARepository productJPARepository; private final ProductLineJPARepository productLineJPARepository; diff --git a/src/main/java/org/store/clothstar/product/repository/UpperProductRepository.java b/src/main/java/org/store/clothstar/product/repository/ProductMybatisRepository.java similarity index 54% rename from src/main/java/org/store/clothstar/product/repository/UpperProductRepository.java rename to src/main/java/org/store/clothstar/product/repository/ProductMybatisRepository.java index 6c3f2221..f69a8624 100644 --- a/src/main/java/org/store/clothstar/product/repository/UpperProductRepository.java +++ b/src/main/java/org/store/clothstar/product/repository/ProductMybatisRepository.java @@ -1,19 +1,24 @@ package org.store.clothstar.product.repository; +import org.apache.ibatis.annotations.Mapper; import org.store.clothstar.product.domain.Product; import java.util.List; import java.util.Optional; -public interface UpperProductRepository { +@Mapper +public interface ProductMybatisRepository extends ProductRepository { - List selectAllProductByProductLineId(Long productId); + List selectAllProductsById(Long productId); Optional selectByProductId(Long productId); +// Optional selectProductLineWithOptions(Long productId); + int save(Product product); int updateProduct(Product product); int deleteProduct(Long productId); + } diff --git a/src/main/java/org/store/clothstar/product/repository/ProductRepository.java b/src/main/java/org/store/clothstar/product/repository/ProductRepository.java index 70775665..e1efca24 100644 --- a/src/main/java/org/store/clothstar/product/repository/ProductRepository.java +++ b/src/main/java/org/store/clothstar/product/repository/ProductRepository.java @@ -1,24 +1,19 @@ package org.store.clothstar.product.repository; -import org.apache.ibatis.annotations.Mapper; import org.store.clothstar.product.domain.Product; import java.util.List; import java.util.Optional; -@Mapper -public interface ProductRepository extends UpperProductRepository { +public interface ProductRepository { - List selectAllProductsById(Long productId); + List selectAllProductByProductLineId(Long productId); Optional selectByProductId(Long productId); -// Optional selectProductLineWithOptions(Long productId); - int save(Product product); int updateProduct(Product product); int deleteProduct(Long productId); - } diff --git a/src/main/java/org/store/clothstar/product/service/ProductService.java b/src/main/java/org/store/clothstar/product/service/ProductService.java index 51f4ff62..de3445ac 100644 --- a/src/main/java/org/store/clothstar/product/service/ProductService.java +++ b/src/main/java/org/store/clothstar/product/service/ProductService.java @@ -12,12 +12,11 @@ import org.store.clothstar.product.dto.request.UpdateProductRequest; import org.store.clothstar.product.dto.response.ProductResponse; import org.store.clothstar.product.repository.ProductRepository; -import org.store.clothstar.product.repository.UpperProductRepository; @Service @RequiredArgsConstructor public class ProductService { - private final UpperProductRepository productRepository; + private final ProductRepository productRepository; /* @Transactional(readOnly = true) diff --git a/src/main/resources/application-db.yml b/src/main/resources/application-db.yml index d6dfbe0d..9bca0a19 100644 --- a/src/main/resources/application-db.yml +++ b/src/main/resources/application-db.yml @@ -13,7 +13,7 @@ app: repository: - type: jpa + type: mybatis mybatis: mapper-locations: classpath:/mappers/**.xml config-location: classpath:/config/mybatis-config.xml diff --git a/src/main/resources/mappers/ProductMapper.xml b/src/main/resources/mappers/ProductMapper.xml index 978acd44..155d743e 100644 --- a/src/main/resources/mappers/ProductMapper.xml +++ b/src/main/resources/mappers/ProductMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd"> - +