-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 예약 도메인 추가 및 패키지 도메인 일부 변경 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
dfd8a03
4a0d9ef
f02c001
284b2ec
9d8508d
892f0cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| package com.study.core.product.domain | ||
|
|
||
| interface ProductRepository { | ||
|
|
||
| fun findAllByIdIn(productIds: List<Long>): List<Product> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| package com.study.core.product.infrastructure | ||
|
|
||
| import com.study.core.product.domain.Product | ||
| import com.study.core.product.domain.ProductRepository | ||
| import org.springframework.stereotype.Repository | ||
|
|
||
| @Repository | ||
| class ProductRepositoryImpl( | ||
| private val productJpaRepository: ProductJpaRepository | ||
| ) : ProductRepository { | ||
|
|
||
| override fun findAllByIdIn(productIds: List<Long>): List<Product> { | ||
| return productJpaRepository.findAllByIdIn(productIds) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,39 @@ | ||
| package com.study.core.productpackage.application | ||
|
|
||
| import com.study.core.product.domain.Product | ||
| import com.study.core.product.domain.ProductRepository | ||
| import com.study.core.productpackage.application.dto.CreatePackageCommand | ||
| import com.study.core.productpackage.domain.Package | ||
| import com.study.core.productpackage.infrastructure.PackageCommandRepository | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
|
|
||
| /** | ||
| * TODO : 도메인 설계 Merge이후 작업 | ||
| */ | ||
| @Transactional | ||
| @Service | ||
| class PackageCommandService { | ||
| class PackageCommandService( | ||
| private val packageCommandRepository: PackageCommandRepository, | ||
| private val productRepository: ProductRepository, | ||
| ) { | ||
|
|
||
| fun createPackage(): Package { | ||
| TODO() | ||
| fun createPackage(command: CreatePackageCommand): Package { | ||
| val products = findProducts(command.productIds) | ||
| val pkg = Package.createWithTimeSlots( | ||
| name = command.name, | ||
| description = command.description, | ||
| products = products, | ||
| tagNames = command.tagNames, | ||
| slotStartDate = command.slotStartDate, | ||
| slotEndDate = command.slotEndDate, | ||
| slotStartHour = command.slotStartHour, | ||
| slotEndHour = command.slotEndHour | ||
| ) | ||
|
|
||
| return packageCommandRepository.save(pkg) | ||
| } | ||
|
|
||
| private fun findProducts(productIds: List<Long>): List<Product> { | ||
| val products = productRepository.findAllByIdIn(productIds) | ||
| require(products.size == productIds.size) { "One or more products are not found." } | ||
| return products | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.study.core.productpackage.application.dto | ||
|
|
||
| import java.time.LocalDate | ||
|
|
||
| data class CreatePackageCommand( | ||
| val name: String, | ||
| val description: String, | ||
| val slotStartDate: LocalDate, // 패키지 생성 시 예약 시작 가능한 날짜 | ||
| val slotEndDate: LocalDate, // 패키지 생성 시 패키지 마감 날짜 | ||
| val slotStartHour: Int = 9, // 예약 가능한 타임 슬롯 시작 지점 | ||
| val slotEndHour: Int = 16, // 예약 가능한 타임 슬록 마지막 지점 | ||
| val productIds: List<Long> = emptyList(), // 예약에 포함할 패키지 ids | ||
| val tagNames: List<String> = emptyList() // 패키지에 해당하는 tags | ||
| ) |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| package com.study.core.productpackage.infrastructure | ||
|
|
||
| import com.study.core.productpackage.domain.Package | ||
| import org.springframework.stereotype.Repository | ||
|
|
||
| @Repository | ||
| class PackageCommandRepository( | ||
| private val packageJpaRepository: PackageJpaRepository | ||
| ) { | ||
|
|
||
| fun save(pkg: Package): Package = packageJpaRepository.save(pkg) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.study.core.reservation.application | ||
|
|
||
| import com.study.core.reservation.application.dto.CreateReservationCommand | ||
| import com.study.core.reservation.domain.Reservation | ||
| import com.study.core.reservation.domain.ReservationRepository | ||
| import com.study.core.reservation.domain.ReservationSlotRepository | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
|
|
||
| @Transactional | ||
| @Service | ||
| class ReservationCommandService( | ||
| private val reservationRepository: ReservationRepository, | ||
| private val reservationSlotRepository: ReservationSlotRepository | ||
| ) { | ||
|
|
||
| fun createReservation(command: CreateReservationCommand): Reservation { | ||
| val reservationTimeSlot = reservationSlotRepository.findByIdForUpdate(command.reservationSlotId) | ||
| ?: throw IllegalArgumentException("Reservation slot not found: ${command.reservationSlotId}") | ||
| reservationTimeSlot.validateBookingStatusAndPackageValid(command.packageId) | ||
|
|
||
| val reservation = Reservation( | ||
| reservationSlot = reservationTimeSlot, | ||
| userId = command.userId, | ||
| headCount = command.headCount, | ||
| visitDate = reservationTimeSlot.reservationDate, | ||
| visitStartTime = reservationTimeSlot.startTime, | ||
| visitEndTime = reservationTimeSlot.endTime, | ||
| totalPrice = command.totalPrice, | ||
| requestMessage = command.requestMessage | ||
| ).request() | ||
|
|
||
| return reservationRepository.save(reservation) | ||
| } | ||
|
|
||
| fun cancelReservation(reservationId: Long, cancelMessage: String? = null): Reservation { | ||
| val reservation = reservationRepository.findById(reservationId) | ||
| ?: throw IllegalArgumentException("Reservation not found: $reservationId") | ||
| val updated = reservation.cancel(cancelMessage) | ||
| return reservationRepository.save(updated) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.study.core.reservation.application.dto | ||
|
|
||
| import java.math.BigDecimal | ||
|
|
||
| data class CreateReservationCommand( | ||
| val packageId: Long, | ||
| val reservationSlotId: Long, // 예약 가능한 타임슬롯 id | ||
| val userId: Long, | ||
| val headCount: Int, // 인원 수 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인원 수, 예약 요청 메시지는 피그마 상으로는 예약 시에 입력받고 있는 것 같지 않은데 어떤 방식으로 입력받는 건가요?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 그러네요 예약 요청 메시지 같은 게 보통 있어서 관성적으로 추가한 것 같은데 제거하겠습니다. |
||
| val totalPrice: BigDecimal, // 패키지 총액 (반정규화) | ||
| val requestMessage: String? = null // 예약 요청 메시지 | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
시작시간, 종료시간을 상수로 선언하고,
createWithTimeSlots의 slotStartHour, slotEndHour에도 같이 사용하는 건 어떤가요??