Skip to content

Commit

Permalink
fix: 상품 옵션 더미 데이터 추가 로직 변경 (#104)
Browse files Browse the repository at this point in the history
* fix: 상품 옵션 더미 데이터 추가 로직 변경

* test: 출력 테스트 삭제

* feat: 스웨거 간단히 추가
  • Loading branch information
Combi153 authored Feb 26, 2024
1 parent e091746 commit 8682c10
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
32 changes: 18 additions & 14 deletions src/main/kotlin/com/petqua/common/config/DataInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.petqua.domain.product.detail.info.OptimalTemperature
import com.petqua.domain.product.detail.info.ProductInfo
import com.petqua.domain.product.detail.info.ProductInfoRepository
import com.petqua.domain.product.detail.info.Temperament.PEACEFUL
import com.petqua.domain.product.option.ProductOption
import com.petqua.domain.product.option.ProductOptionRepository
import com.petqua.domain.product.option.Sex.FEMALE
import com.petqua.domain.product.option.Sex.HERMAPHRODITE
Expand All @@ -45,13 +46,13 @@ import com.petqua.domain.recommendation.ProductRecommendation
import com.petqua.domain.recommendation.ProductRecommendationRepository
import com.petqua.domain.store.Store
import com.petqua.domain.store.StoreRepository
import java.math.BigDecimal
import kotlin.random.Random
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.annotation.Profile
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import java.math.BigDecimal
import kotlin.random.Random

@Component
@Profile("local", "prod")
Expand Down Expand Up @@ -171,18 +172,6 @@ class DataInitializer(
}
val reviewCount = (1..5).random()

val sex = when {
(it % 3) == 0 -> MALE
(it % 7) == 0 -> FEMALE
else -> HERMAPHRODITE
}
// val productOption = productOptionRepository.save(
// ProductOption(
// sex = sex,
// additionalPrice = BigDecimal.ZERO
// )
// )

val productInfo = productInfoRepository.save(
ProductInfo(
categoryId = categoryId,
Expand Down Expand Up @@ -224,6 +213,21 @@ class DataInitializer(
}
productRepository.saveAll(products)

val productOptions = products.map {
val sex = when {
(it.id % 3).toInt() == 0 -> MALE
(it.id % 7).toInt() == 0 -> FEMALE
else -> HERMAPHRODITE
}

ProductOption(
productId = it.id,
sex = sex,
additionalPrice = BigDecimal.ZERO,
)
}
productOptionRepository.saveAll(productOptions)

// wishProducts
val wishProducts = products.filter {
(it.id % 11).toInt() == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ package com.petqua.presentation.order

import com.petqua.application.order.OrderService
import com.petqua.application.order.dto.SaveOrderResponse
import com.petqua.common.config.ACCESS_TOKEN_SECURITY_SCHEME_KEY
import com.petqua.domain.auth.Auth
import com.petqua.domain.auth.LoginMember
import com.petqua.presentation.order.dto.SaveOrderRequest
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Tag(name = "Order", description = "주문 관련 API 명세")
@SecurityRequirement(name = ACCESS_TOKEN_SECURITY_SCHEME_KEY)
@RequestMapping("/orders")
@RestController
class OrderController(
private val orderService: OrderService,
) {

@Operation(summary = "주문 생성 API", description = "주문을 생성합니다")
@ApiResponse(responseCode = "200", description = "주문 생성 성공")
@PostMapping
fun save(
@Auth loginMember: LoginMember,
Expand Down
9 changes: 1 addition & 8 deletions src/test/kotlin/com/petqua/domain/product/ProductTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.petqua.domain.product

import com.petqua.domain.order.OrderNumber
import com.petqua.test.fixture.product
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

class ProductTest : BehaviorSpec({

Expand All @@ -24,9 +22,4 @@ class ProductTest : BehaviorSpec({
}


}) {
@Test
fun test() {
println(OrderNumber.generate().value)
}
}
})

0 comments on commit 8682c10

Please sign in to comment.