From 59047a0432e1e39b7fc5cdac6312852e93866792 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Thu, 15 Feb 2024 21:18:36 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EB=8D=94=EB=AF=B8=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=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 --- .../petqua/common/config/DataInitializer.kt | 396 ++++++++---------- .../presentation/product/dto/ProductDtos.kt | 6 +- 2 files changed, 167 insertions(+), 235 deletions(-) diff --git a/src/main/kotlin/com/petqua/common/config/DataInitializer.kt b/src/main/kotlin/com/petqua/common/config/DataInitializer.kt index 33bb3584..68162569 100644 --- a/src/main/kotlin/com/petqua/common/config/DataInitializer.kt +++ b/src/main/kotlin/com/petqua/common/config/DataInitializer.kt @@ -5,6 +5,8 @@ import com.petqua.domain.announcement.AnnouncementRepository import com.petqua.domain.auth.Authority.MEMBER import com.petqua.domain.banner.Banner import com.petqua.domain.banner.BannerRepository +import com.petqua.domain.keyword.ProductKeyword +import com.petqua.domain.keyword.ProductKeywordRepository import com.petqua.domain.member.Member import com.petqua.domain.member.MemberRepository import com.petqua.domain.product.Product @@ -16,18 +18,13 @@ import com.petqua.domain.product.category.Category import com.petqua.domain.product.category.CategoryRepository import com.petqua.domain.product.category.Family import com.petqua.domain.product.category.Species -import com.petqua.domain.product.detail.DifficultyLevel.EASY -import com.petqua.domain.product.detail.DifficultyLevel.HARD import com.petqua.domain.product.detail.DifficultyLevel.NORMAL -import com.petqua.domain.product.detail.OptimalTankSize.TANK1 import com.petqua.domain.product.detail.OptimalTankSize.TANK2 -import com.petqua.domain.product.detail.OptimalTankSize.TANK3 import com.petqua.domain.product.detail.OptimalTemperature import com.petqua.domain.product.detail.ProductImage import com.petqua.domain.product.detail.ProductImageRepository import com.petqua.domain.product.detail.ProductInfo import com.petqua.domain.product.detail.ProductInfoRepository -import com.petqua.domain.product.detail.Temperament.AGGRESSIVE import com.petqua.domain.product.detail.Temperament.PEACEFUL import com.petqua.domain.product.option.ProductOption import com.petqua.domain.product.option.ProductOptionRepository @@ -65,277 +62,129 @@ class DataInitializer( private val productImageRepository: ProductImageRepository, private val productOptionRepository: ProductOptionRepository, private val wishProductRepository: WishProductRepository, + private val productKeywordRepository: ProductKeywordRepository, ) { @EventListener(ApplicationReadyEvent::class) @Transactional fun setUpData() { // member - val member = memberRepository.save( - Member( - oauthId = "oauthId", - oauthServerNumber = 1, - authority = MEMBER, - ) - ) + val member = saveMember() // announcement - val announcement1 = Announcement( - title = "[공지] 펫쿠아 프론트엔드 개발자 구인 중!", - linkUrl = "https://team.petqua.co.kr/" - ) - val announcement2 = Announcement( - title = "[공지] 펫쿠아 복지 추가 GPT4 지원 예정", - linkUrl = "https://team.petqua.co.kr/" - ) - val announcement3 = Announcement( - title = "[공지] 펫쿠아 개발팀 copilot 적극 활용", - linkUrl = "https://team.petqua.co.kr/" - ) - announcementRepository.saveAll(listOf(announcement1, announcement2, announcement3)) + saveAnnouncements() // banner - val banner1 = Banner( - imageUrl = "https://docs.petqua.co.kr/banners/b08f14d5ac00721b.jpg", - linkUrl = "https://team.petqua.co.kr/" - ) - val banner2 = Banner( - imageUrl = "https://docs.petqua.co.kr/banners/announcement1.jpg", - linkUrl = "https://team.petqua.co.kr/" - ) - val banner3 = Banner( - imageUrl = "https://docs.petqua.co.kr/banners/announcement2.jpg", - linkUrl = "https://team.petqua.co.kr/" - ) - val banner4 = Banner( - imageUrl = "https://docs.petqua.co.kr/banners/announcement3.jpg", - linkUrl = "https://team.petqua.co.kr/" - ) - bannerRepository.saveAll(listOf(banner1, banner2, banner3, banner4)) + saveBanners() - // store - val store1 = Store(name = "니모를 찾아서") - val store2 = Store(name = "제주 미영이네 식당") - storeRepository.saveAll(listOf(store1, store2)) - - // category - val category1 = Category(family = Family("송사리과"), species = Species("고정구피")) - val category2 = Category(family = Family("송사리과"), species = Species("팬시구피")) - categoryRepository.saveAll(listOf(category1, category2)) - - // product - val product1 = Product( - name = "니모", - categoryId = category1.id, - price = BigDecimal.valueOf(30000L).setScale(2), - storeId = store1.id, - discountRate = 10, - discountPrice = BigDecimal(27000L).setScale(2), - wishCount = WishCount(3), - reviewCount = 10, - reviewTotalScore = 50, - thumbnailUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail1.jpeg", - description = "https://www.goldmoonaqua.com/web/upload/NNEditor/20221226/copy-1672038777-guppy_EC958CEBB984EB85B8ED9280EBA088EB939C_02.png", - canDeliverSafely = false, - canDeliverCommonly = true, - canPickUp = false, - ) - val product2 = Product( - name = "참고등어", - categoryId = category2.id, - price = BigDecimal.valueOf(20000L).setScale(2), - storeId = store1.id, - discountRate = 10, - discountPrice = BigDecimal(18000L).setScale(2), - wishCount = WishCount(5), - reviewCount = 3, - reviewTotalScore = 15, - thumbnailUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail2.jpeg", - description = "https://shop-phinf.pstatic.net/20231116_59/1700105133758mQSba_JPEG/%EC%B9%A8%EC%B0%A9%ED%95%9C%ED%9B%84%EB%93%9C_%EC%83%81%EC%84%B8_1.jpg?type=w860", - canDeliverSafely = true, - canDeliverCommonly = false, - canPickUp = true, - ) - val product3 = Product( - name = "니모를 찾아서 세트", - categoryId = category1.id, - price = BigDecimal.valueOf(80000L).setScale(2), - storeId = store1.id, - discountRate = 50, - discountPrice = BigDecimal(40000L).setScale(2), - wishCount = WishCount(100), - reviewCount = 50, - reviewTotalScore = 250, - thumbnailUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail3.jpeg", - description = "https://store.img11.co.kr/68636870/cf26fe1a-98d5-486b-a79a-9dbfade97fb6_1690335864752.jpg", - canDeliverSafely = false, - canDeliverCommonly = true, - canPickUp = true, - ) - productRepository.saveAll(listOf(product1, product2, product3)) - saveProducts(store1.id, category1.id, member.id) - - // productRecommendation - val productRecommendation1 = ProductRecommendation(productId = product3.id) - recommendationRepository.saveAll(listOf(productRecommendation1)) + // others + saveCommerceData(member.id) + } - // productOption - productOptionRepository.saveAll( - listOf( - ProductOption( - productId = product1.id, - sex = MALE, - additionalPrice = BigDecimal.ZERO - ), - ProductOption( - productId = product2.id, - sex = FEMALE, - additionalPrice = BigDecimal.ZERO - ), - ProductOption( - productId = product3.id, - sex = HERMAPHRODITE, - additionalPrice = BigDecimal.ZERO - ), + private fun saveMember(): Member { + return memberRepository.save( + Member( + oauthId = "oauthId", + oauthServerNumber = 1, + authority = MEMBER, ) ) + } - //productImage - productImageRepository.saveAll( + private fun saveAnnouncements() { + announcementRepository.saveAll( listOf( - ProductImage( - productId = product1.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail1.jpeg" - ), - ProductImage( - productId = product1.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail1.jpeg" + Announcement( + title = "[공지] 펫쿠아 프론트엔드 개발자 구인 중!", + linkUrl = "https://team.petqua.co.kr/" ), - ProductImage( - productId = product1.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail1.jpeg" + Announcement( + title = "[공지] 펫쿠아 복지 추가 GPT4 지원 예정", + linkUrl = "https://team.petqua.co.kr/" ), - ProductImage( - productId = product1.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail1.jpeg" - ), - ProductImage( - productId = product1.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail1.jpeg" - ), - ProductImage( - productId = product2.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail2.jpeg" - ), - ProductImage( - productId = product2.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail2.jpeg" - ), - ProductImage( - productId = product2.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail2.jpeg" - ), - ProductImage( - productId = product3.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail3.jpeg" - ), - ProductImage( - productId = product3.id, - imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail3.jpeg" + Announcement( + title = "[공지] 펫쿠아 개발팀 copilot 적극 활용", + linkUrl = "https://team.petqua.co.kr/" ), ) ) + } - // productInfo - productInfoRepository.saveAll( + private fun saveBanners() { + bannerRepository.saveAll( listOf( - ProductInfo( - productId = product1.id, - categoryId = category1.id, - optimalTemperature = OptimalTemperature(22, 25), - difficultyLevel = EASY, - optimalTankSize = TANK1, - temperament = AGGRESSIVE + Banner( + imageUrl = "https://docs.petqua.co.kr/banners/b08f14d5ac00721b.jpg", + linkUrl = "https://team.petqua.co.kr/" ), - ProductInfo( - productId = product2.id, - categoryId = category2.id, - optimalTemperature = OptimalTemperature(22, 25), - difficultyLevel = HARD, - optimalTankSize = TANK3, - temperament = PEACEFUL + Banner( + imageUrl = "https://docs.petqua.co.kr/banners/announcement1.jpg", + linkUrl = "https://team.petqua.co.kr/" ), - ProductInfo( - productId = product3.id, - categoryId = category2.id, - optimalTemperature = OptimalTemperature(22, 25), - difficultyLevel = NORMAL, - optimalTankSize = TANK2, - temperament = PEACEFUL - ) - ) - ) - - // productReview - val reviews = productReviewRepository.saveAll( - listOf( - ProductReview( - productId = product1.id, - memberId = member.id, - content = "좋아요", - score = 5, - hasPhotos = true - ), - ProductReview( - productId = product1.id, - memberId = member.id, - content = "조금 좋아요", - score = 4, - hasPhotos = false + Banner( + imageUrl = "https://docs.petqua.co.kr/banners/announcement2.jpg", + linkUrl = "https://team.petqua.co.kr/" ), - ProductReview( - productId = product1.id, - memberId = member.id, - content = "약간 좋아요", - score = 3, - hasPhotos = false + Banner( + imageUrl = "https://docs.petqua.co.kr/banners/announcement3.jpg", + linkUrl = "https://team.petqua.co.kr/" ), ) ) - reviews.find { it.hasPhotos }?.let { - productReviewImageRepository.saveAll( - listOf( - ProductReviewImage(imageUrl = "https://docs.petqua.co.kr/reviews/1.jpeg", productReviewId = it.id), - ProductReviewImage(imageUrl = "https://docs.petqua.co.kr/reviews/2.jpeg", productReviewId = it.id), - ProductReviewImage(imageUrl = "https://docs.petqua.co.kr/reviews/3.jpeg", productReviewId = it.id), - ) - ) - } } - private fun saveProducts(storeId: Long, categoryId: Long, memberId: Long) { + private fun saveCommerceData(memberId: Long) { + // store + val store = Store(name = "상점1") + storeRepository.saveAll(listOf(store)) + + // category + val category1 = Category(family = Family("송사리과"), species = Species("고정구피")) + val category2 = Category(family = Family("송사리과"), species = Species("팬시구피")) + categoryRepository.saveAll(listOf(category1, category2)) + + // products val products = (1..100).map { + val categoryId = when { + (it % 2) == 0 -> category1.id + else -> category2.id + } + val canDeliverSafely = when { + (it % 4) == 0 -> true + else -> false + } + val canDeliverCommonly = when { + (it % 5) == 0 -> true + else -> false + } + val canPickUp = when { + (it % 2) == 0 -> true + else -> false + } + val reviewCount = (1..5).random() + Product( - name = "니모를 찾아서 세트$it", + name = "상품$it", categoryId = categoryId, price = BigDecimal.valueOf(80000L).setScale(2), - storeId = storeId, + storeId = store.id, discountRate = 50, discountPrice = BigDecimal(40000L).setScale(2), wishCount = WishCount(100), - reviewCount = 50, - reviewTotalScore = 250, + reviewCount = reviewCount, + reviewTotalScore = (1..reviewCount).sum(), thumbnailUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail3.jpeg", - description = "니모를 찾아서 주연 조연", - canDeliverSafely = true, - canDeliverCommonly = true, - canPickUp = true, + description = "https://www.goldmoonaqua.com/web/upload/NNEditor/20221226/copy-1672038777-guppy_EC958CEBB984EB85B8ED9280EBA088EB939C_02.png", + canDeliverSafely = canDeliverSafely, + canDeliverCommonly = canDeliverCommonly, + canPickUp = canPickUp, ) } productRepository.saveAll(products) + // wishProducts val wishProducts = products.filter { - (it.id % 2).toInt() == 0 + (it.id % 11).toInt() == 0 }.map { WishProduct( productId = it.id, @@ -343,5 +192,88 @@ class DataInitializer( ) } wishProductRepository.saveAll(wishProducts) + + // productKeyword + val productKeywords = products.filter { + (it.id % 9).toInt() == 0 + }.map { + ProductKeyword( + productId = it.id, + word = "상품" + ) + } + productKeywordRepository.saveAll(productKeywords) + + // productRecommendation + val productRecommendations = products.filter { + (it.id % 10).toInt() == 0 + }.map { + ProductRecommendation(productId = it.id) + } + recommendationRepository.saveAll(productRecommendations) + + // productOption + val productOptions = products.map { + val sex = when { + (it.id % 3).toInt() == 0 -> MALE + (it.id % 7).toInt() == 0 -> HERMAPHRODITE + else -> FEMALE + } + ProductOption( + productId = it.id, + sex = sex, + additionalPrice = BigDecimal.ZERO + ) + } + productOptionRepository.saveAll(productOptions) + + // productInfo + val productInfos = products.map { + ProductInfo( + productId = it.id, + categoryId = it.categoryId, + optimalTemperature = OptimalTemperature(22, 25), + difficultyLevel = NORMAL, + optimalTankSize = TANK2, + temperament = PEACEFUL + ) + } + productInfoRepository.saveAll(productInfos) + + // productImage + val productImages = products.map { + ProductImage( + productId = it.id, + imageUrl = "https://docs.petqua.co.kr/products/thumbnails/thumbnail3.jpeg" + ) + } + productImageRepository.saveAll(productImages) + + // review + val productReviews = products.flatMap { product -> + val hasPhotos = (product.id % 2).toInt() == 0 + + (1..product.wishCount.value).map { + ProductReview( + productId = product.id, + memberId = memberId, + content = "좋아요 ${product.name}", + score = it, + hasPhotos = hasPhotos + ) + } + } + productReviewRepository.saveAll(productReviews) + + // reviewImages + val productReviewImages = productReviews.filter { + it.hasPhotos + }.map { + ProductReviewImage( + imageUrl = "https://docs.petqua.co.kr/banners/announcement1.jpg", + productReviewId = it.id + ) + } + productReviewImageRepository.saveAll(productReviewImages) } } diff --git a/src/main/kotlin/com/petqua/presentation/product/dto/ProductDtos.kt b/src/main/kotlin/com/petqua/presentation/product/dto/ProductDtos.kt index cd57bfc7..223953f9 100644 --- a/src/main/kotlin/com/petqua/presentation/product/dto/ProductDtos.kt +++ b/src/main/kotlin/com/petqua/presentation/product/dto/ProductDtos.kt @@ -5,8 +5,8 @@ import com.petqua.application.product.dto.ProductReadQuery import com.petqua.application.product.dto.ProductSearchQuery import com.petqua.common.domain.dto.DEFAULT_LAST_VIEWED_ID import com.petqua.common.domain.dto.PAGING_LIMIT_CEILING -import com.petqua.domain.delivery.DeliveryMethod import com.petqua.domain.auth.LoginMemberOrGuest +import com.petqua.domain.delivery.DeliveryMethod import com.petqua.domain.product.ProductSourceType import com.petqua.domain.product.Sorter import io.swagger.v3.oas.annotations.media.Schema @@ -98,8 +98,8 @@ data class ProductSearchRequest( data class ProductKeywordRequest( @Schema( - description = "마지막으로 조회한 상품의 Id", - example = "1" + description = "검색어", + example = "상" ) val word: String,