diff --git a/src/main/generated/org/store/clothstar/category/domain/QCategory.java b/src/main/generated/org/store/clothstar/category/domain/QCategory.java deleted file mode 100644 index 2d3570a3..00000000 --- a/src/main/generated/org/store/clothstar/category/domain/QCategory.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.store.clothstar.category.domain; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; - - -/** - * QCategory is a Querydsl query type for Category - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QCategory extends EntityPathBase { - - private static final long serialVersionUID = 543350353L; - - public static final QCategory category = new QCategory("category"); - - public final NumberPath categoryId = createNumber("categoryId", Long.class); - - public final StringPath categoryType = createString("categoryType"); - - public QCategory(String variable) { - super(Category.class, forVariable(variable)); - } - - public QCategory(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QCategory(PathMetadata metadata) { - super(Category.class, metadata); - } - -} - diff --git a/src/main/generated/org/store/clothstar/category/entity/QCategoryEntity.java b/src/main/generated/org/store/clothstar/category/entity/QCategoryEntity.java deleted file mode 100644 index a7bf46b9..00000000 --- a/src/main/generated/org/store/clothstar/category/entity/QCategoryEntity.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.store.clothstar.category.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; - - -/** - * QCategoryEntity is a Querydsl query type for CategoryEntity - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QCategoryEntity extends EntityPathBase { - - private static final long serialVersionUID = -1059070827L; - - public static final QCategoryEntity categoryEntity = new QCategoryEntity("categoryEntity"); - - public final NumberPath categoryId = createNumber("categoryId", Long.class); - - public final StringPath categoryType = createString("categoryType"); - - public QCategoryEntity(String variable) { - super(CategoryEntity.class, forVariable(variable)); - } - - public QCategoryEntity(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QCategoryEntity(PathMetadata metadata) { - super(CategoryEntity.class, metadata); - } - -} - diff --git a/src/main/generated/org/store/clothstar/common/entity/QBaseEntity.java b/src/main/generated/org/store/clothstar/common/entity/QBaseEntity.java deleted file mode 100644 index 51167df4..00000000 --- a/src/main/generated/org/store/clothstar/common/entity/QBaseEntity.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.store.clothstar.common.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; - - -/** - * QBaseEntity is a Querydsl query type for BaseEntity - */ -@Generated("com.querydsl.codegen.DefaultSupertypeSerializer") -public class QBaseEntity extends EntityPathBase { - - private static final long serialVersionUID = 20937749L; - - public static final QBaseEntity baseEntity = new QBaseEntity("baseEntity"); - - public final DateTimePath createdAt = createDateTime("createdAt", java.time.LocalDateTime.class); - - public final DateTimePath deletedAt = createDateTime("deletedAt", java.time.LocalDateTime.class); - - public final DateTimePath updatedAt = createDateTime("updatedAt", java.time.LocalDateTime.class); - - public QBaseEntity(String variable) { - super(BaseEntity.class, forVariable(variable)); - } - - public QBaseEntity(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QBaseEntity(PathMetadata metadata) { - super(BaseEntity.class, metadata); - } - -} - diff --git a/src/main/generated/org/store/clothstar/common/entity/QBaseTimeEntity.java b/src/main/generated/org/store/clothstar/common/entity/QBaseTimeEntity.java deleted file mode 100644 index b83109a6..00000000 --- a/src/main/generated/org/store/clothstar/common/entity/QBaseTimeEntity.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.store.clothstar.common.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; - - -/** - * QBaseTimeEntity is a Querydsl query type for BaseTimeEntity - */ -@Generated("com.querydsl.codegen.DefaultSupertypeSerializer") -public class QBaseTimeEntity extends EntityPathBase { - - private static final long serialVersionUID = -1914223550L; - - public static final QBaseTimeEntity baseTimeEntity = new QBaseTimeEntity("baseTimeEntity"); - - public final DateTimePath createdAt = createDateTime("createdAt", java.time.LocalDateTime.class); - - public final DateTimePath deletedAt = createDateTime("deletedAt", java.time.LocalDateTime.class); - - public final DateTimePath modifiedAt = createDateTime("modifiedAt", java.time.LocalDateTime.class); - - public QBaseTimeEntity(String variable) { - super(BaseTimeEntity.class, forVariable(variable)); - } - - public QBaseTimeEntity(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QBaseTimeEntity(PathMetadata metadata) { - super(BaseTimeEntity.class, metadata); - } - -} - diff --git a/src/main/generated/org/store/clothstar/member/entity/QAddressEntity.java b/src/main/generated/org/store/clothstar/member/entity/QAddressEntity.java deleted file mode 100644 index 2c75b905..00000000 --- a/src/main/generated/org/store/clothstar/member/entity/QAddressEntity.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.store.clothstar.member.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.PathInits; - - -/** - * QAddressEntity is a Querydsl query type for AddressEntity - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QAddressEntity extends EntityPathBase { - - private static final long serialVersionUID = -1178876409L; - - private static final PathInits INITS = PathInits.DIRECT2; - - public static final QAddressEntity addressEntity = new QAddressEntity("addressEntity"); - - public final StringPath addressBasic = createString("addressBasic"); - - public final StringPath addressDetail = createString("addressDetail"); - - public final NumberPath addressId = createNumber("addressId", Long.class); - - public final BooleanPath defaultAddress = createBoolean("defaultAddress"); - - public final StringPath deliveryRequest = createString("deliveryRequest"); - - public final QMemberEntity member; - - public final StringPath receiverName = createString("receiverName"); - - public final StringPath telNo = createString("telNo"); - - public final StringPath zipNo = createString("zipNo"); - - public QAddressEntity(String variable) { - this(AddressEntity.class, forVariable(variable), INITS); - } - - public QAddressEntity(Path path) { - this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); - } - - public QAddressEntity(PathMetadata metadata) { - this(metadata, PathInits.getFor(metadata, INITS)); - } - - public QAddressEntity(PathMetadata metadata, PathInits inits) { - this(AddressEntity.class, metadata, inits); - } - - public QAddressEntity(Class type, PathMetadata metadata, PathInits inits) { - super(type, metadata, inits); - this.member = inits.isInitialized("member") ? new QMemberEntity(forProperty("member")) : null; - } - -} - diff --git a/src/main/generated/org/store/clothstar/member/entity/QMemberEntity.java b/src/main/generated/org/store/clothstar/member/entity/QMemberEntity.java deleted file mode 100644 index dc976415..00000000 --- a/src/main/generated/org/store/clothstar/member/entity/QMemberEntity.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.store.clothstar.member.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; - - -/** - * QMemberEntity is a Querydsl query type for MemberEntity - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QMemberEntity extends EntityPathBase { - - private static final long serialVersionUID = 175373325L; - - public static final QMemberEntity memberEntity = new QMemberEntity("memberEntity"); - - public final org.store.clothstar.common.entity.QBaseEntity _super = new org.store.clothstar.common.entity.QBaseEntity(this); - - //inherited - public final DateTimePath createdAt = _super.createdAt; - - //inherited - public final DateTimePath deletedAt = _super.deletedAt; - - public final StringPath email = createString("email"); - - public final EnumPath grade = createEnum("grade", org.store.clothstar.member.domain.MemberGrade.class); - - public final NumberPath memberId = createNumber("memberId", Long.class); - - public final StringPath name = createString("name"); - - public final StringPath password = createString("password"); - - public final NumberPath point = createNumber("point", Integer.class); - - public final EnumPath role = createEnum("role", org.store.clothstar.member.domain.MemberRole.class); - - public final StringPath telNo = createString("telNo"); - - public final NumberPath totalPaymentPrice = createNumber("totalPaymentPrice", Integer.class); - - //inherited - public final DateTimePath updatedAt = _super.updatedAt; - - public QMemberEntity(String variable) { - super(MemberEntity.class, forVariable(variable)); - } - - public QMemberEntity(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QMemberEntity(PathMetadata metadata) { - super(MemberEntity.class, metadata); - } - -} - diff --git a/src/main/generated/org/store/clothstar/member/entity/QSellerEntity.java b/src/main/generated/org/store/clothstar/member/entity/QSellerEntity.java deleted file mode 100644 index f59ba59f..00000000 --- a/src/main/generated/org/store/clothstar/member/entity/QSellerEntity.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.store.clothstar.member.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.PathInits; - - -/** - * QSellerEntity is a Querydsl query type for SellerEntity - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QSellerEntity extends EntityPathBase { - - private static final long serialVersionUID = 251707698L; - - private static final PathInits INITS = PathInits.DIRECT2; - - public static final QSellerEntity sellerEntity = new QSellerEntity("sellerEntity"); - - public final org.store.clothstar.common.entity.QBaseEntity _super = new org.store.clothstar.common.entity.QBaseEntity(this); - - public final StringPath bizNo = createString("bizNo"); - - public final StringPath brandName = createString("brandName"); - - //inherited - public final DateTimePath createdAt = _super.createdAt; - - //inherited - public final DateTimePath deletedAt = _super.deletedAt; - - public final QMemberEntity member; - - public final NumberPath memberId = createNumber("memberId", Long.class); - - public final NumberPath totalSellPrice = createNumber("totalSellPrice", Integer.class); - - //inherited - public final DateTimePath updatedAt = _super.updatedAt; - - public QSellerEntity(String variable) { - this(SellerEntity.class, forVariable(variable), INITS); - } - - public QSellerEntity(Path path) { - this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); - } - - public QSellerEntity(PathMetadata metadata) { - this(metadata, PathInits.getFor(metadata, INITS)); - } - - public QSellerEntity(PathMetadata metadata, PathInits inits) { - this(SellerEntity.class, metadata, inits); - } - - public QSellerEntity(Class type, PathMetadata metadata, PathInits inits) { - super(type, metadata, inits); - this.member = inits.isInitialized("member") ? new QMemberEntity(forProperty("member")) : null; - } - -} - diff --git a/src/main/generated/org/store/clothstar/order/entity/QOrderEntity.java b/src/main/generated/org/store/clothstar/order/entity/QOrderEntity.java index da40f2d3..4daf95dc 100644 --- a/src/main/generated/org/store/clothstar/order/entity/QOrderEntity.java +++ b/src/main/generated/org/store/clothstar/order/entity/QOrderEntity.java @@ -28,6 +28,8 @@ public class QOrderEntity extends EntityPathBase { public final org.store.clothstar.member.entity.QMemberEntity member; + public final ListPath orderDetails = this.createList("orderDetails", org.store.clothstar.orderDetail.entity.OrderDetailEntity.class, org.store.clothstar.orderDetail.entity.QOrderDetailEntity.class, PathInits.DIRECT2); + public final NumberPath orderId = createNumber("orderId", Long.class); public final EnumPath paymentMethod = createEnum("paymentMethod", org.store.clothstar.order.type.PaymentMethod.class); diff --git a/src/main/generated/org/store/clothstar/orderDetail/entity/QOrderDetailEntity.java b/src/main/generated/org/store/clothstar/orderDetail/entity/QOrderDetailEntity.java deleted file mode 100644 index c23726c6..00000000 --- a/src/main/generated/org/store/clothstar/orderDetail/entity/QOrderDetailEntity.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.store.clothstar.orderDetail.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.PathInits; - - -/** - * QOrderDetailEntity is a Querydsl query type for OrderDetailEntity - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QOrderDetailEntity extends EntityPathBase { - - private static final long serialVersionUID = 2101270815L; - - private static final PathInits INITS = PathInits.DIRECT2; - - public static final QOrderDetailEntity orderDetailEntity = new QOrderDetailEntity("orderDetailEntity"); - - public final StringPath brandName = createString("brandName"); - - public final NumberPath fixedPrice = createNumber("fixedPrice", Integer.class); - - public final StringPath name = createString("name"); - - public final NumberPath oneKindTotalPrice = createNumber("oneKindTotalPrice", Integer.class); - - public final StringPath optionName = createString("optionName"); - - public final org.store.clothstar.order.entity.QOrderEntity order; - - public final NumberPath orderDetailId = createNumber("orderDetailId", Long.class); - - public final org.store.clothstar.product.entity.QProductEntity product; - - public final org.store.clothstar.productLine.entity.QProductLineEntity productLine; - - public final NumberPath quantity = createNumber("quantity", Integer.class); - - public final NumberPath stock = createNumber("stock", Long.class); - - public QOrderDetailEntity(String variable) { - this(OrderDetailEntity.class, forVariable(variable), INITS); - } - - public QOrderDetailEntity(Path path) { - this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); - } - - public QOrderDetailEntity(PathMetadata metadata) { - this(metadata, PathInits.getFor(metadata, INITS)); - } - - public QOrderDetailEntity(PathMetadata metadata, PathInits inits) { - this(OrderDetailEntity.class, metadata, inits); - } - - public QOrderDetailEntity(Class type, PathMetadata metadata, PathInits inits) { - super(type, metadata, inits); - this.order = inits.isInitialized("order") ? new org.store.clothstar.order.entity.QOrderEntity(forProperty("order"), inits.get("order")) : null; - this.product = inits.isInitialized("product") ? new org.store.clothstar.product.entity.QProductEntity(forProperty("product"), inits.get("product")) : null; - this.productLine = inits.isInitialized("productLine") ? new org.store.clothstar.productLine.entity.QProductLineEntity(forProperty("productLine"), inits.get("productLine")) : null; - } - -} - diff --git a/src/main/generated/org/store/clothstar/product/entity/QProductEntity.java b/src/main/generated/org/store/clothstar/product/entity/QProductEntity.java deleted file mode 100644 index b81495e1..00000000 --- a/src/main/generated/org/store/clothstar/product/entity/QProductEntity.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.store.clothstar.product.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.PathInits; - - -/** - * QProductEntity is a Querydsl query type for ProductEntity - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QProductEntity extends EntityPathBase { - - private static final long serialVersionUID = 494935583L; - - private static final PathInits INITS = PathInits.DIRECT2; - - public static final QProductEntity productEntity = new QProductEntity("productEntity"); - - public final NumberPath extraCharge = createNumber("extraCharge", Integer.class); - - public final StringPath name = createString("name"); - - public final NumberPath productId = createNumber("productId", Long.class); - - public final org.store.clothstar.productLine.entity.QProductLineEntity productLine; - - public final NumberPath stock = createNumber("stock", Long.class); - - public QProductEntity(String variable) { - this(ProductEntity.class, forVariable(variable), INITS); - } - - public QProductEntity(Path path) { - this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); - } - - public QProductEntity(PathMetadata metadata) { - this(metadata, PathInits.getFor(metadata, INITS)); - } - - public QProductEntity(PathMetadata metadata, PathInits inits) { - this(ProductEntity.class, metadata, inits); - } - - public QProductEntity(Class type, PathMetadata metadata, PathInits inits) { - super(type, metadata, inits); - this.productLine = inits.isInitialized("productLine") ? new org.store.clothstar.productLine.entity.QProductLineEntity(forProperty("productLine"), inits.get("productLine")) : null; - } - -} - diff --git a/src/main/generated/org/store/clothstar/productLine/dto/response/QProductLineWithProductsJPAResponse.java b/src/main/generated/org/store/clothstar/productLine/dto/response/QProductLineWithProductsJPAResponse.java deleted file mode 100644 index 2e25095a..00000000 --- a/src/main/generated/org/store/clothstar/productLine/dto/response/QProductLineWithProductsJPAResponse.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.store.clothstar.productLine.dto.response; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.ConstructorExpression; -import javax.annotation.processing.Generated; - -/** - * org.store.clothstar.productLine.dto.response.QProductLineWithProductsJPAResponse is a Querydsl Projection type for ProductLineWithProductsJPAResponse - */ -@Generated("com.querydsl.codegen.DefaultProjectionSerializer") -public class QProductLineWithProductsJPAResponse extends ConstructorExpression { - - private static final long serialVersionUID = -438244439L; - - public QProductLineWithProductsJPAResponse(com.querydsl.core.types.Expression productLine, com.querydsl.core.types.Expression category, com.querydsl.core.types.Expression seller, com.querydsl.core.types.Expression member, com.querydsl.core.types.Expression totalStock) { - super(ProductLineWithProductsJPAResponse.class, new Class[]{org.store.clothstar.productLine.entity.ProductLineEntity.class, org.store.clothstar.category.domain.Category.class, org.store.clothstar.member.entity.SellerEntity.class, org.store.clothstar.member.entity.MemberEntity.class, long.class}, productLine, category, seller, member, totalStock); - } - -} - diff --git a/src/main/generated/org/store/clothstar/productLine/entity/QProductLineEntity.java b/src/main/generated/org/store/clothstar/productLine/entity/QProductLineEntity.java deleted file mode 100644 index 85a170f2..00000000 --- a/src/main/generated/org/store/clothstar/productLine/entity/QProductLineEntity.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.store.clothstar.productLine.entity; - -import static com.querydsl.core.types.PathMetadataFactory.*; - -import com.querydsl.core.types.dsl.*; - -import com.querydsl.core.types.PathMetadata; -import javax.annotation.processing.Generated; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.PathInits; - - -/** - * QProductLineEntity is a Querydsl query type for ProductLineEntity - */ -@Generated("com.querydsl.codegen.DefaultEntitySerializer") -public class QProductLineEntity extends EntityPathBase { - - private static final long serialVersionUID = 755215007L; - - private static final PathInits INITS = PathInits.DIRECT2; - - public static final QProductLineEntity productLineEntity = new QProductLineEntity("productLineEntity"); - - public final org.store.clothstar.common.entity.QBaseTimeEntity _super = new org.store.clothstar.common.entity.QBaseTimeEntity(this); - - public final org.store.clothstar.category.domain.QCategory category; - - public final StringPath content = createString("content"); - - //inherited - public final DateTimePath createdAt = _super.createdAt; - - //inherited - public final DateTimePath deletedAt = _super.deletedAt; - - //inherited - public final DateTimePath modifiedAt = _super.modifiedAt; - - public final StringPath name = createString("name"); - - public final NumberPath price = createNumber("price", Integer.class); - - public final NumberPath productLineId = createNumber("productLineId", Long.class); - - public final ListPath products = this.createList("products", org.store.clothstar.product.entity.ProductEntity.class, org.store.clothstar.product.entity.QProductEntity.class, PathInits.DIRECT2); - - public final NumberPath saleCount = createNumber("saleCount", Long.class); - - public final org.store.clothstar.member.entity.QSellerEntity seller; - - public final EnumPath status = createEnum("status", org.store.clothstar.productLine.domain.type.ProductLineStatus.class); - - public final NumberPath totalStock = createNumber("totalStock", Long.class); - - public QProductLineEntity(String variable) { - this(ProductLineEntity.class, forVariable(variable), INITS); - } - - public QProductLineEntity(Path path) { - this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS)); - } - - public QProductLineEntity(PathMetadata metadata) { - this(metadata, PathInits.getFor(metadata, INITS)); - } - - public QProductLineEntity(PathMetadata metadata, PathInits inits) { - this(ProductLineEntity.class, metadata, inits); - } - - public QProductLineEntity(Class type, PathMetadata metadata, PathInits inits) { - super(type, metadata, inits); - this.category = inits.isInitialized("category") ? new org.store.clothstar.category.domain.QCategory(forProperty("category")) : null; - this.seller = inits.isInitialized("seller") ? new org.store.clothstar.member.entity.QSellerEntity(forProperty("seller"), inits.get("seller")) : null; - } - -} - diff --git a/src/main/java/org/store/clothstar/Application.java b/src/main/java/org/store/clothstar/Application.java index 28a5719e..3a05c7ff 100644 --- a/src/main/java/org/store/clothstar/Application.java +++ b/src/main/java/org/store/clothstar/Application.java @@ -2,9 +2,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; //@EnableJpaAuditing @SpringBootApplication +@EnableJpaRepositories(basePackages = "org.store.clothstar") public class Application { public static void main(String[] args) { diff --git a/src/main/java/org/store/clothstar/common/config/RepositoryConfig.java b/src/main/java/org/store/clothstar/common/config/RepositoryConfig.java new file mode 100644 index 00000000..ef0d7ef0 --- /dev/null +++ b/src/main/java/org/store/clothstar/common/config/RepositoryConfig.java @@ -0,0 +1,59 @@ +package org.store.clothstar.common.config; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.store.clothstar.category.repository.CategoryJpaRepository; +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.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; + +@Slf4j +@Configuration +@RequiredArgsConstructor +public class RepositoryConfig { + + @Bean +// @Primary + @ConditionalOnProperty(name = "app.repository.type", havingValue = "jpa", matchIfMissing = true) + public ProductLineRepository jpaProductLineRepository(CategoryJpaRepository categoryJpaRepository, + SellerRepository sellerRepository, + ProductLineJPARepository productLineJPARepository, + ProductJPARepository productJPARepository) { + log.info("Configuring ProductLine JPA repository"); + return new ProductLineJPARepositoryAdapter(categoryJpaRepository, sellerRepository, productLineJPARepository, productJPARepository); + } + + @Bean + @Primary + @ConditionalOnProperty(name = "app.repository.type", havingValue = "mybatis") + public ProductLineRepository mybatisProductLineRepository(SqlSessionTemplate sqlSessionTemplate) { + log.info("Configuring ProductLine MyBatis repository"); + return sqlSessionTemplate.getMapper(ProductLineMybatisRepository.class); + } + @Bean +// @Primary + @ConditionalOnProperty(name = "app.repository.type", havingValue = "jpa", matchIfMissing = true) + 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 ProductRepository mybatisProductRepository(SqlSessionTemplate sqlSessionTemplate) { + log.info("Configuring Product MyBatis repository"); + return sqlSessionTemplate.getMapper(ProductMybatisRepository.class); + } +} diff --git a/src/main/java/org/store/clothstar/common/entity/BaseTimeEntity.java b/src/main/java/org/store/clothstar/common/entity/BaseTimeEntity.java index 647de30d..a4cd0583 100644 --- a/src/main/java/org/store/clothstar/common/entity/BaseTimeEntity.java +++ b/src/main/java/org/store/clothstar/common/entity/BaseTimeEntity.java @@ -29,6 +29,10 @@ public class BaseTimeEntity { @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private LocalDateTime deletedAt; // 삭제일시 + protected void setModifiedAt(LocalDateTime modifiedAt) { + this.modifiedAt = modifiedAt; + } + protected void setDeletedAt(LocalDateTime deletedAt) { this.deletedAt = deletedAt; } 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/domain/Product.java b/src/main/java/org/store/clothstar/product/domain/Product.java index 69687be3..c541f514 100644 --- a/src/main/java/org/store/clothstar/product/domain/Product.java +++ b/src/main/java/org/store/clothstar/product/domain/Product.java @@ -1,7 +1,10 @@ package org.store.clothstar.product.domain; import lombok.*; +import org.store.clothstar.orderDetail.entity.OrderDetailEntity; import org.store.clothstar.product.dto.request.UpdateProductRequest; +import org.store.clothstar.product.dto.response.ProductResponse; +import org.store.clothstar.product.entity.ProductEntity; @Builder @Getter @@ -28,4 +31,14 @@ public void updateStock(long stock) { public void restoreStock(int quantity) { this.stock += quantity; } + + public static Product from(ProductEntity productEntity) { + return Product.builder() + .productId(productEntity.getProductId()) + .productLineId(productEntity.getProductLine().getProductLineId()) + .name(productEntity.getName()) + .extraCharge(productEntity.getExtraCharge()) + .stock(productEntity.getStock()) + .build(); + } } diff --git a/src/main/java/org/store/clothstar/product/entity/ProductEntity.java b/src/main/java/org/store/clothstar/product/entity/ProductEntity.java index bcbabcca..0228b891 100644 --- a/src/main/java/org/store/clothstar/product/entity/ProductEntity.java +++ b/src/main/java/org/store/clothstar/product/entity/ProductEntity.java @@ -5,6 +5,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; +import org.store.clothstar.product.domain.Product; import org.store.clothstar.product.dto.request.UpdateProductRequest; import org.store.clothstar.productLine.entity.ProductLineEntity; @@ -13,6 +15,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@BatchSize(size = 100) @Table(name = "product") public class ProductEntity { @Id @@ -23,8 +26,11 @@ public class ProductEntity { @JoinColumn(name = "product_line_id", nullable = false) // @JsonManagedReference private ProductLineEntity productLine; + private String name; + private int extraCharge; + private Long stock; public void updateOption(UpdateProductRequest updateProductRequest) { @@ -33,8 +39,32 @@ public void updateOption(UpdateProductRequest updateProductRequest) { this.stock = updateProductRequest.getStock(); } + public void updateOption(Product pro) { + this.name = pro.getName(); + this.extraCharge = pro.getExtraCharge(); + this.stock = pro.getStock(); + } + public void updateStock(long stock) { this.stock = stock; + checkAndUpdateProductLineStatus(); + } + + // ϰ ¸ ϴ ޼ + public void reduceStock(int quantity) { + if (this.stock >= quantity) { + this.stock -= quantity; + checkAndUpdateProductLineStatus(); + } else { + throw new IllegalArgumentException("Insufficient stock"); + } + } + + // ProductLine Ʈ ޼ + private void checkAndUpdateProductLineStatus() { + if (productLine != null) { + productLine.checkAndUpdateStatus(); + } } public void restoreStock(int quantity) { diff --git a/src/main/java/org/store/clothstar/product/repository/ProductJPARepository.java b/src/main/java/org/store/clothstar/product/repository/ProductJPARepository.java index f1c592dd..aada334b 100644 --- a/src/main/java/org/store/clothstar/product/repository/ProductJPARepository.java +++ b/src/main/java/org/store/clothstar/product/repository/ProductJPARepository.java @@ -2,8 +2,13 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import org.store.clothstar.product.domain.Product; import org.store.clothstar.product.entity.ProductEntity; +import java.util.List; + @Repository public interface ProductJPARepository extends JpaRepository, ProductRepositoryCustom { + + List findAllByProductId(Long productId); } diff --git a/src/main/java/org/store/clothstar/product/repository/ProductJPARepositoryAdapter.java b/src/main/java/org/store/clothstar/product/repository/ProductJPARepositoryAdapter.java new file mode 100644 index 00000000..739456b6 --- /dev/null +++ b/src/main/java/org/store/clothstar/product/repository/ProductJPARepositoryAdapter.java @@ -0,0 +1,74 @@ +package org.store.clothstar.product.repository; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Repository; +import org.springframework.web.server.ResponseStatusException; +import org.store.clothstar.product.domain.Product; +import org.store.clothstar.product.entity.ProductEntity; +import org.store.clothstar.productLine.entity.ProductLineEntity; +import org.store.clothstar.productLine.repository.ProductLineJPARepository; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@Repository +@RequiredArgsConstructor +public class ProductJPARepositoryAdapter implements ProductRepository { + + private final ProductJPARepository productJPARepository; + private final ProductLineJPARepository productLineJPARepository; + + public List selectAllProductByProductLineId(Long productId) { + return productJPARepository.findAllByProductId(productId) + .stream() + .map(Product::from) + .collect(Collectors.toList()); + } + + @Override + public Optional selectByProductId(Long productId) { + return productJPARepository.findById(productId) + .map(Product::from); + } + + @Override + public int save(Product product) { + ProductEntity productEntity = convertToProductEntity(product); + productJPARepository.save(productEntity); + return 1; + } + + @Override + public int updateProduct(Product product) { + ProductEntity productEntity = productJPARepository.findById(product.getProductId()) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found with id: " + product.getProductLineId())); + + productEntity.updateOption(product); + + return 1; + } + + @Override + public int deleteProduct(Long productId) { + ProductEntity productEntity = productJPARepository.findById(productId) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found with id: " + productId)); + + productJPARepository.delete(productEntity); + return 0; + } + + private ProductEntity convertToProductEntity(Product product) { + ProductLineEntity productLine = productLineJPARepository.findById(product.getProductLineId()) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "ProductLine not found with id: " + product.getProductLineId())); + + return ProductEntity.builder() + .productId(product.getProductId()) + .productLine(productLine) + .name(product.getName()) + .extraCharge(product.getExtraCharge()) + .stock(product.getStock()) + .build(); + } +} diff --git a/src/main/java/org/store/clothstar/product/repository/ProductMybatisRepository.java b/src/main/java/org/store/clothstar/product/repository/ProductMybatisRepository.java new file mode 100644 index 00000000..f69a8624 --- /dev/null +++ b/src/main/java/org/store/clothstar/product/repository/ProductMybatisRepository.java @@ -0,0 +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; + +@Mapper +public interface ProductMybatisRepository extends ProductRepository { + + 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 456d046d..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,25 +1,19 @@ package org.store.clothstar.product.repository; -import org.apache.ibatis.annotations.Mapper; import org.store.clothstar.product.domain.Product; -import org.store.clothstar.productLine.dto.response.ProductLineWithProductsResponse; import java.util.List; import java.util.Optional; -@Mapper public interface ProductRepository { - List selectAllProducts(); + 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/productLine/domain/ProductLine.java b/src/main/java/org/store/clothstar/productLine/domain/ProductLine.java index d2ad84c8..17482e96 100644 --- a/src/main/java/org/store/clothstar/productLine/domain/ProductLine.java +++ b/src/main/java/org/store/clothstar/productLine/domain/ProductLine.java @@ -1,10 +1,14 @@ package org.store.clothstar.productLine.domain; import lombok.*; +import org.store.clothstar.product.domain.Product; +import org.store.clothstar.product.entity.ProductEntity; import org.store.clothstar.productLine.domain.type.ProductLineStatus; import org.store.clothstar.productLine.dto.request.UpdateProductLineRequest; +import org.store.clothstar.productLine.entity.ProductLineEntity; import java.time.LocalDateTime; +import java.util.List; @Builder @Getter @@ -42,4 +46,29 @@ public void changeProductStatus(ProductLineStatus productLineStatus) { public void setDeletedAt() { this.deletedAt = LocalDateTime.now(); } + + public static ProductLine from(ProductLineEntity productLine) { + List products = productLine.getProducts(); + + Long totalStock = 0L; + for (ProductEntity product : products) { + totalStock += product.getStock(); + } + + return ProductLine.builder() + .productLineId(productLine.getProductLineId()) + .memberId(productLine.getSeller().getMemberId()) + .categoryId(productLine.getCategory().getCategoryId()) + .name(productLine.getName()) + .content(productLine.getContent()) + .price(productLine.getPrice()) + .totalStock(totalStock) + .status(productLine.getStatus()) + .saleCount(productLine.getSaleCount()) + .createdAt(productLine.getCreatedAt()) + .deletedAt(productLine.getDeletedAt()) + .brandName(productLine.getSeller().getBrandName()) + .biz_no(productLine.getSeller().getBizNo()) + .build(); + } } \ No newline at end of file diff --git a/src/main/java/org/store/clothstar/productLine/dto/request/CreateProductLineRequest.java b/src/main/java/org/store/clothstar/productLine/dto/request/CreateProductLineRequest.java index 6dfe10d2..167b72d9 100644 --- a/src/main/java/org/store/clothstar/productLine/dto/request/CreateProductLineRequest.java +++ b/src/main/java/org/store/clothstar/productLine/dto/request/CreateProductLineRequest.java @@ -64,7 +64,7 @@ public ProductLineEntity toProductLineEntity(Long memberId, SellerEntity seller, .name(name) .content(content) .price(price) - .totalStock(0L) +// .totalStock(0L) .status(status) .saleCount(0L) .build(); diff --git a/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsJPAResponse.java b/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsJPAResponse.java index 9043a990..77086bbe 100644 --- a/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsJPAResponse.java +++ b/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsJPAResponse.java @@ -15,6 +15,7 @@ import org.store.clothstar.productLine.entity.ProductLineEntity; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; @Builder @@ -41,6 +42,34 @@ public class ProductLineWithProductsJPAResponse { private LocalDateTime modifiedAt; // private LocalDateTime deletedAt; +// @QueryProjection +// public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, Category category, SellerEntity seller, MemberEntity member, Long totalStock) { +// this.productLineId = productLine.getProductLineId(); +// this.category = CategoryResponse.from(category); +// this.name = productLine.getName(); +// this.price = productLine.getPrice(); +// this.totalStock = totalStock; +// this.status = productLine.getStatus(); +// this.productList = productLine.getProducts() +// .stream() +// .map(ProductResponse::from) +// .toList(); +//// this.productList = productLine.getProducts(); +// this.saleCount = productLine.getSaleCount(); +// this.member = MemberSimpleResponse.from(member); +// this.seller = SellerSimpleResponse.from(seller); +// this.createdAt = productLine.getCreatedAt(); +// this.modifiedAt = productLine.getModifiedAt(); +//// this.deletedAt = productLine.getDeletedAt(); +// } + + // 추가된 생성자 + // 추가된 생성자 + public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, Category category, SellerEntity seller, MemberEntity member, Long totalStock, List productList) { + this(productLine, category, seller, member, totalStock); + this.productList = productList != null ? productList : new ArrayList<>(); + } + @QueryProjection public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, Category category, SellerEntity seller, MemberEntity member, Long totalStock) { this.productLineId = productLine.getProductLineId(); @@ -49,16 +78,12 @@ public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, Categor this.price = productLine.getPrice(); this.totalStock = totalStock; this.status = productLine.getStatus(); - this.productList = productLine.getProducts() - .stream() - .map(ProductResponse::from) - .toList(); -// this.productList = productLine.getProducts(); this.saleCount = productLine.getSaleCount(); this.member = MemberSimpleResponse.from(member); this.seller = SellerSimpleResponse.from(seller); this.createdAt = productLine.getCreatedAt(); this.modifiedAt = productLine.getModifiedAt(); -// this.deletedAt = productLine.getDeletedAt(); + this.productList = new ArrayList<>(); } + } diff --git a/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsResponse.java b/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsResponse.java index 592a1ac1..b99ee2b6 100644 --- a/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsResponse.java +++ b/src/main/java/org/store/clothstar/productLine/dto/response/ProductLineWithProductsResponse.java @@ -2,10 +2,13 @@ import lombok.*; import org.store.clothstar.product.domain.Product; +import org.store.clothstar.product.dto.response.ProductResponse; import org.store.clothstar.productLine.domain.type.ProductLineStatus; import java.time.LocalDateTime; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; @Builder @Getter @@ -28,4 +31,38 @@ public class ProductLineWithProductsResponse { private String brandName; private String biz_no; private List productList; + + public static ProductLineWithProductsResponse from(ProductLineWithProductsJPAResponse response) { + return ProductLineWithProductsResponse.builder() + .productLineId(response.getProductLineId()) + .memberId(response.getMember().getMemberId()) + .categoryId(response.getCategory().getCategoryId()) + .name(response.getName()) + .content(response.getContent()) + .price(response.getPrice()) + .totalStock(response.getTotalStock()) + .status(response.getStatus()) + .saleCount(response.getSaleCount()) + .createdAt(response.getCreatedAt()) + .modifiedAt(response.getModifiedAt()) + .brandName(response.getSeller().getBrandName()) + .biz_no(response.getSeller().getBizNo()) + .productList(convertToProductList(response.getProductList())) + .build(); + } + + private static List convertToProductList(List productResponses) { + if (productResponses == null) { + return Collections.emptyList(); + } + return productResponses.stream() + .map(pr -> Product.builder() + .productId(pr.getProductId()) + .productLineId(pr.getProductLineId()) + .name(pr.getName()) + .extraCharge(pr.getExtraCharge()) + .stock(pr.getStock()) + .build()) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/org/store/clothstar/productLine/entity/ProductLineEntity.java b/src/main/java/org/store/clothstar/productLine/entity/ProductLineEntity.java index e59fc491..62df4f9b 100644 --- a/src/main/java/org/store/clothstar/productLine/entity/ProductLineEntity.java +++ b/src/main/java/org/store/clothstar/productLine/entity/ProductLineEntity.java @@ -6,10 +6,12 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; import org.store.clothstar.category.domain.Category; import org.store.clothstar.common.entity.BaseTimeEntity; import org.store.clothstar.member.entity.SellerEntity; import org.store.clothstar.product.entity.ProductEntity; +import org.store.clothstar.productLine.domain.ProductLine; import org.store.clothstar.productLine.domain.type.ProductLineStatus; import org.store.clothstar.productLine.dto.request.UpdateProductLineRequest; @@ -20,6 +22,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@BatchSize(size = 100) @Entity(name = "product_line") //@Table(name = "product_line") public class ProductLineEntity extends BaseTimeEntity { @@ -42,7 +45,7 @@ public class ProductLineEntity extends BaseTimeEntity { private int price; - private Long totalStock; +// private Long totalStock; @Enumerated(EnumType.STRING) private ProductLineStatus status; @@ -61,10 +64,31 @@ public void updateProductLine(UpdateProductLineRequest updateProductLineRequest) this.status = updateProductLineRequest.getStatus(); } + public void updateProductLine(ProductLine productLine) { + this.name = productLine.getName(); + this.content = productLine.getContent(); + this.price = productLine.getPrice(); + this.status = productLine.getStatus(); + this.setModifiedAt(LocalDateTime.now()); + } + public void changeProductStatus(ProductLineStatus productLineStatus) { this.status = productLineStatus; } + // 상품 전체 재고 계산 + public long calculateTotalStock() { + return products.stream().mapToLong(ProductEntity::getStock).sum(); + } + + // 상품 전체 재고 확인 및 상태 업데이트 + public void checkAndUpdateStatus() { + long totalStock = calculateTotalStock(); + if (totalStock == 0 && this.status != ProductLineStatus.SOLD_OUT) { + this.status = ProductLineStatus.SOLD_OUT; + } + } + public void delete() { this.setDeletedAt(LocalDateTime.now()); } diff --git a/src/main/java/org/store/clothstar/productLine/repository/ProductLineJPARepository.java b/src/main/java/org/store/clothstar/productLine/repository/ProductLineJPARepository.java index d7d4fe84..f2565da4 100644 --- a/src/main/java/org/store/clothstar/productLine/repository/ProductLineJPARepository.java +++ b/src/main/java/org/store/clothstar/productLine/repository/ProductLineJPARepository.java @@ -1,7 +1,14 @@ package org.store.clothstar.productLine.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import org.store.clothstar.productLine.domain.type.ProductLineStatus; import org.store.clothstar.productLine.entity.ProductLineEntity; +import java.util.List; + +@Repository public interface ProductLineJPARepository extends JpaRepository, ProductLineRepositoryCustom { + + List findByDeletedAtIsNullAndStatusNotIn(List statuses); } diff --git a/src/main/java/org/store/clothstar/productLine/repository/ProductLineMybatisRepository.java b/src/main/java/org/store/clothstar/productLine/repository/ProductLineMybatisRepository.java index c1e10178..e59253ff 100644 --- a/src/main/java/org/store/clothstar/productLine/repository/ProductLineMybatisRepository.java +++ b/src/main/java/org/store/clothstar/productLine/repository/ProductLineMybatisRepository.java @@ -8,7 +8,7 @@ import java.util.Optional; @Mapper -public interface ProductLineMybatisRepository { +public interface ProductLineMybatisRepository extends ProductLineRepository { List selectAllProductLinesNotDeleted(); diff --git a/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepository.java b/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepository.java index ee51de9b..38429a7d 100644 --- a/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepository.java +++ b/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepository.java @@ -1,18 +1,22 @@ package org.store.clothstar.productLine.repository; -import org.springframework.stereotype.Repository; import org.store.clothstar.productLine.domain.ProductLine; import org.store.clothstar.productLine.dto.response.ProductLineWithProductsResponse; import java.util.List; import java.util.Optional; -@Repository public interface ProductLineRepository { List selectAllProductLinesNotDeleted(); Optional selectByProductLineId(Long productId); - Optional findProductLineWithOptionsById(Long productId); + Optional selectProductLineWithOptions(Long productId); + + int save(ProductLine productLine); + + int updateProductLine(ProductLine productLine); + + int setDeletedAt(ProductLine productLine); } diff --git a/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepositoryCustomImpl.java b/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepositoryCustomImpl.java index 60abbc78..17237481 100644 --- a/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepositoryCustomImpl.java +++ b/src/main/java/org/store/clothstar/productLine/repository/ProductLineRepositoryCustomImpl.java @@ -1,5 +1,6 @@ package org.store.clothstar.productLine.repository; +import com.querydsl.core.Tuple; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.NumberExpression; import com.querydsl.jpa.impl.JPAQuery; @@ -10,17 +11,22 @@ import org.springframework.data.domain.Sort; import org.springframework.data.support.PageableExecutionUtils; import org.springframework.stereotype.Repository; +import org.store.clothstar.category.domain.Category; import org.store.clothstar.category.domain.QCategory; +import org.store.clothstar.member.entity.MemberEntity; import org.store.clothstar.member.entity.QMemberEntity; import org.store.clothstar.member.entity.QSellerEntity; +import org.store.clothstar.member.entity.SellerEntity; +import org.store.clothstar.product.dto.response.ProductResponse; +import org.store.clothstar.product.entity.ProductEntity; import org.store.clothstar.product.entity.QProductEntity; import org.store.clothstar.productLine.dto.response.ProductLineWithProductsJPAResponse; import org.store.clothstar.productLine.dto.response.QProductLineWithProductsJPAResponse; +import org.store.clothstar.productLine.entity.ProductLineEntity; import org.store.clothstar.productLine.entity.QProductLineEntity; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; +import java.util.stream.Collectors; @Repository @RequiredArgsConstructor @@ -34,7 +40,7 @@ public class ProductLineRepositoryCustomImpl implements ProductLineRepositoryCus QSellerEntity qSeller = QSellerEntity.sellerEntity; QMemberEntity qMember = QMemberEntity.memberEntity; - +/* @Override public Page getProductLinesWithOptions(Pageable pageable) { @@ -46,7 +52,7 @@ public Page getProductLinesWithOptions(Pagea .from(qProductLine) .innerJoin(qProductLine.seller, qSeller) .innerJoin(qSeller.member, qMember) - .leftJoin(qProductLine.products, qProduct) + .leftJoin(qProductLine.products, qProduct).fetchJoin() // .innerJoin(qProduct).on() .where(qProductLine.deletedAt.isNull()) .orderBy(orderSpecifiers.toArray(new OrderSpecifier[0])) @@ -63,20 +69,85 @@ public Page getProductLinesWithOptions(Pagea return PageableExecutionUtils.getPage(content, pageable, totalCount::fetchOne); } + */ + + public Page getProductLinesWithOptions(Pageable pageable) { + List> orderSpecifiers = getOrderSpecifiers(pageable.getSort()); + + List results = jpaQueryFactory + .selectDistinct(qProductLine, qCategory, qSeller, qMember, qProduct) + .from(qProductLine) + .innerJoin(qProductLine.seller, qSeller).fetchJoin() + .innerJoin(qSeller.member, qMember).fetchJoin() + .leftJoin(qProductLine.products, qProduct).fetchJoin() + .leftJoin(qProductLine.category, qCategory).fetchJoin() + .where(qProductLine.deletedAt.isNull()) + .orderBy(orderSpecifiers.toArray(new OrderSpecifier[0])) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + Map productLineMap = new HashMap<>(); + for (Tuple tuple : results) { + ProductLineEntity productLine = tuple.get(qProductLine); + Category category = tuple.get(qCategory); + SellerEntity seller = tuple.get(qSeller); + MemberEntity member = tuple.get(qMember); + ProductEntity product = tuple.get(qProduct); + + ProductLineWithProductsJPAResponse response = productLineMap.computeIfAbsent(productLine.getProductLineId(), + id -> new ProductLineWithProductsJPAResponse(productLine, category, seller, member, productLine.getProducts().stream().mapToLong(ProductEntity::getStock).sum())); + + if (product != null) { + response.getProductList().add(ProductResponse.from(product)); + } + } + + + List content = new ArrayList<>(productLineMap.values()); + + JPAQuery totalCount = jpaQueryFactory + .select(qProductLine.count()) + .from(qProductLine) + .where(qProductLine.deletedAt.isNull()); + + return PageableExecutionUtils.getPage(content, pageable, totalCount::fetchOne); + } + @Override public Optional findProductLineWithOptionsById(Long productLineId) { - NumberExpression totalStockExpression = qProduct.stock.sum(); - return Optional.ofNullable(jpaQueryFactory - .select(new QProductLineWithProductsJPAResponse(qProductLine, qCategory, qSeller, qMember, totalStockExpression)) + ProductLineWithProductsJPAResponse result = jpaQueryFactory + .select(new QProductLineWithProductsJPAResponse( + qProductLine, + qCategory, + qSeller, + qMember, + totalStockExpression + )) .from(qProductLine) - .innerJoin(qProductLine.seller) - .innerJoin(qSeller.member) - .innerJoin(qProductLine.products, qProduct) + .innerJoin(qProductLine.seller, qSeller) + .innerJoin(qSeller.member, qMember) + .innerJoin(qProductLine.category, qCategory) + .leftJoin(qProductLine.products, qProduct) .where(qProductLine.productLineId.eq(productLineId) .and(qProductLine.deletedAt.isNull())) - .fetchOne()); + .groupBy(qProductLine.productLineId, qCategory, qSeller, qMember) + .fetchOne(); + + if (result != null) { + List products = jpaQueryFactory + .selectFrom(qProduct) + .where(qProduct.productLine.productLineId.eq(productLineId)) + .fetch(); + + result.setProductList(products.stream() + .map(ProductResponse::from) + .collect(Collectors.toList())); + } + + return Optional.ofNullable(result); } private List> getOrderSpecifiers(Sort sort) { diff --git a/src/main/java/org/store/clothstar/productLine/repository/adapter/ProductLineJPARepositoryAdapter.java b/src/main/java/org/store/clothstar/productLine/repository/adapter/ProductLineJPARepositoryAdapter.java index 0f31a337..9e739301 100644 --- a/src/main/java/org/store/clothstar/productLine/repository/adapter/ProductLineJPARepositoryAdapter.java +++ b/src/main/java/org/store/clothstar/productLine/repository/adapter/ProductLineJPARepositoryAdapter.java @@ -2,35 +2,105 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Repository; +import org.springframework.web.server.ResponseStatusException; +import org.store.clothstar.category.domain.Category; +import org.store.clothstar.category.repository.CategoryJpaRepository; +import org.store.clothstar.member.entity.SellerEntity; +import org.store.clothstar.member.repository.SellerRepository; +import org.store.clothstar.product.entity.ProductEntity; +import org.store.clothstar.product.repository.ProductJPARepository; import org.store.clothstar.productLine.domain.ProductLine; +import org.store.clothstar.productLine.domain.type.ProductLineStatus; import org.store.clothstar.productLine.dto.response.ProductLineWithProductsResponse; +import org.store.clothstar.productLine.entity.ProductLineEntity; import org.store.clothstar.productLine.repository.ProductLineJPARepository; import org.store.clothstar.productLine.repository.ProductLineRepository; +import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Slf4j @Repository @RequiredArgsConstructor public class ProductLineJPARepositoryAdapter implements ProductLineRepository { + private final CategoryJpaRepository categoryJpaRepository; + private final SellerRepository sellerJpaRepository; private final ProductLineJPARepository productLineJPARepository; + private final ProductJPARepository productJPARepository; @Override public List selectAllProductLinesNotDeleted() { - return null; + return productLineJPARepository.findByDeletedAtIsNullAndStatusNotIn( + Arrays.asList(ProductLineStatus.HIDDEN, ProductLineStatus.DISCONTINUED)) + .stream() + .map(ProductLine::from) + .collect(Collectors.toList()); } @Override public Optional selectByProductLineId(Long productId) { - return Optional.empty(); + return productLineJPARepository.findById(productId) + .map(ProductLine::from); } @Override - public Optional findProductLineWithOptionsById(Long productId) { - return Optional.empty(); + public Optional selectProductLineWithOptions(Long productId) { + return productLineJPARepository.findProductLineWithOptionsById(productId) + .map(ProductLineWithProductsResponse::from); + } + + @Override + public int save(ProductLine productLine) { + ProductLineEntity productLineEntity = convertToProductLineEntity(productLine); + productLineJPARepository.save(productLineEntity); + return 1; + } + + @Override + public int updateProductLine(ProductLine productLine) { + ProductLineEntity productLineEntity = productLineJPARepository.findById(productLine.getProductLineId()) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "ProductLine not found with id: " + productLine.getProductLineId())); + + productLineEntity.updateProductLine(productLine); + + return 1; + } + + @Override + public int setDeletedAt(ProductLine productLine) { + ProductLineEntity productLineEntity = productLineJPARepository.findById(productLine.getProductLineId()) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "ProductLine not found with id: " + productLine.getProductLineId())); + + productLineEntity.delete(); + return 1; + } + + ProductLineEntity convertToProductLineEntity(ProductLine productLine) { + SellerEntity seller = sellerJpaRepository.findById(productLine.getMemberId()) + .orElseThrow(() -> new IllegalArgumentException("Member not found with id: " + productLine.getMemberId())); + + Category category = categoryJpaRepository.findById(productLine.getCategoryId()) + .orElseThrow(() -> new IllegalArgumentException("Category not found with id: " + productLine.getCategoryId())); + + List productEntities = productJPARepository.findAllByProductId(productLine.getProductLineId()); + + + return ProductLineEntity.builder() + .productLineId(productLine.getProductLineId()) + .seller(seller) + .category(category) + .name(productLine.getName()) + .content(productLine.getContent()) + .price(productLine.getPrice()) + .status(productLine.getStatus()) + .saleCount(productLine.getSaleCount()) + .products(productEntities) + .build(); } } diff --git a/src/main/java/org/store/clothstar/productLine/service/ProductLineService.java b/src/main/java/org/store/clothstar/productLine/service/ProductLineService.java index 7a8a5f07..e226eb6a 100644 --- a/src/main/java/org/store/clothstar/productLine/service/ProductLineService.java +++ b/src/main/java/org/store/clothstar/productLine/service/ProductLineService.java @@ -12,7 +12,7 @@ import org.store.clothstar.productLine.dto.request.UpdateProductLineRequest; import org.store.clothstar.productLine.dto.response.ProductLineResponse; import org.store.clothstar.productLine.dto.response.ProductLineWithProductsResponse; -import org.store.clothstar.productLine.repository.ProductLineMybatisRepository; +import org.store.clothstar.productLine.repository.ProductLineRepository; import java.util.List; import java.util.Optional; @@ -23,24 +23,24 @@ @RequiredArgsConstructor public class ProductLineService { - private final ProductLineMybatisRepository productLineMybatisRepository; + private final ProductLineRepository productLineRepository; @Transactional(readOnly = true) public List getAllProductLines() { - return productLineMybatisRepository.selectAllProductLinesNotDeleted().stream() + return productLineRepository.selectAllProductLinesNotDeleted().stream() .map(ProductLineResponse::from) .collect(Collectors.toList()); } @Transactional(readOnly = true) public Optional getProductLine(Long productLineId) { - return productLineMybatisRepository.selectByProductLineId(productLineId) + return productLineRepository.selectByProductLineId(productLineId) .map(ProductLineResponse::from); } @Transactional(readOnly = true) public ProductLineWithProductsResponse getProductLineWithProducts(Long productLineId) { - ProductLineWithProductsResponse productLineWithProducts = productLineMybatisRepository.selectProductLineWithOptions(productLineId) + ProductLineWithProductsResponse productLineWithProducts = productLineRepository.selectProductLineWithOptions(productLineId) .orElseThrow(() -> new ResponseStatusException( HttpStatus.BAD_REQUEST, "productLineId :" + productLineId + "인 상품 및 옵션 정보를 찾을 수 없습니다.")); @@ -60,32 +60,32 @@ public ProductLineWithProductsResponse getProductLineWithProducts(Long productLi public Long createProductLine(CreateProductLineRequest createProductLineRequest) { Long memberId = 1L; ProductLine product = createProductLineRequest.toProductLine(memberId); - productLineMybatisRepository.save(product); + productLineRepository.save(product); return product.getProductLineId(); } @Transactional public void updateProductLine(Long productLineId, UpdateProductLineRequest updateProductLineRequest) { - ProductLine productLine = productLineMybatisRepository.selectByProductLineId(productLineId) + ProductLine productLine = productLineRepository.selectByProductLineId(productLineId) .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "상품 정보를 찾을 수 없습니다.")); productLine.updateProductLine(updateProductLineRequest); - productLineMybatisRepository.updateProductLine(productLine); + productLineRepository.updateProductLine(productLine); } @Transactional public void setDeletedAt(Long productId) { - ProductLine productLine = productLineMybatisRepository.selectByProductLineId(productId) + ProductLine productLine = productLineRepository.selectByProductLineId(productId) .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "상품 정보를 찾을 수 없습니다.")); productLine.setDeletedAt(); - ProductLine prodcutLine = productLineMybatisRepository.selectByProductLineId(productId) + ProductLine prodcutLine = productLineRepository.selectByProductLineId(productId) .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "상품 정보를 찾을 수 없습니다.")); prodcutLine.setDeletedAt(); - productLineMybatisRepository.setDeletedAt(prodcutLine); + productLineRepository.setDeletedAt(prodcutLine); } } \ No newline at end of file diff --git a/src/main/resources/application-db.yml b/src/main/resources/application-db.yml index 46624a6b..9bca0a19 100644 --- a/src/main/resources/application-db.yml +++ b/src/main/resources/application-db.yml @@ -11,6 +11,9 @@ # init: # mode: always +app: + repository: + type: mybatis mybatis: mapper-locations: classpath:/mappers/**.xml config-location: classpath:/config/mybatis-config.xml @@ -96,6 +99,10 @@ spring: jpa: show-sql: true database-platform: H2 + properties: + hibernate: + format_sql: true + default_batch_fetch_size: 100 # hibernate: # ddl-auto: create @@ -131,5 +138,9 @@ spring: jpa: show-sql: true database-platform: org.hibernate.dialect.MySQLDialect + properties: + hibernate: + format_sql: true + default_batch_fetch_size: 100 # hibernate: # ddl-auto: create \ No newline at end of file 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"> - +