-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: 결제 정보를 조회한다 #40
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
Open
inpink
wants to merge
2
commits into
develop
Choose a base branch
from
inpink/payment-core-domain
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...yment-core/adapter/src/main/kotlin/app/payment/core/adapter/inbound/GetPaymentResponse.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package app.payment.core.adapter.inbound | ||
|
|
||
| import app.payment.core.domain.Payment | ||
| import app.payment.core.domain.PaymentMethod | ||
| import app.payment.core.domain.PaymentStatus | ||
| import java.math.BigDecimal | ||
| import java.time.OffsetDateTime | ||
|
|
||
| data class GetPaymentResponse( | ||
| val id: Long, | ||
| val orderId: String, | ||
| val userId: Long, | ||
| val amount: BigDecimal, | ||
| val method: PaymentMethod, | ||
| val status: PaymentStatus, | ||
| val transactionId: String?, | ||
| val paidAt: OffsetDateTime?, | ||
| val createdAt: OffsetDateTime, | ||
| val updatedAt: OffsetDateTime | ||
| ) { | ||
| companion object { | ||
| fun from(payment: Payment): GetPaymentResponse { | ||
| return GetPaymentResponse( | ||
| id = payment.id, | ||
| orderId = payment.orderId, | ||
| userId = payment.userId, | ||
| amount = payment.amount, | ||
| method = payment.method, | ||
| status = payment.status, | ||
| transactionId = payment.transactionId, | ||
| paidAt = payment.paidAt, | ||
| createdAt = payment.createdAt, | ||
| updatedAt = payment.updatedAt | ||
| ) | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...ment-core/adapter/src/main/kotlin/app/payment/core/adapter/inbound/GetPaymentsResponse.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package app.payment.core.adapter.inbound | ||
|
|
||
| import app.payment.core.domain.Payment | ||
|
|
||
| data class GetPaymentsResponse( | ||
| val payments: List<GetPaymentResponse>, | ||
| val count: Int | ||
| ) { | ||
| companion object { | ||
| fun from(payments: List<Payment>): GetPaymentsResponse { | ||
| return GetPaymentsResponse( | ||
| payments = payments.map { GetPaymentResponse.from(it) }, | ||
| count = payments.size | ||
| ) | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...ayment-core/adapter/src/main/kotlin/app/payment/core/adapter/inbound/PaymentController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package app.payment.core.adapter.inbound | ||
|
|
||
| import app.payment.core.application.port.inbound.PaymentUseCase | ||
| import org.springframework.web.bind.annotation.* | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/payments") | ||
| class PaymentController( | ||
| private val paymentUseCase: PaymentUseCase | ||
| ) { | ||
|
|
||
| @GetMapping("/{id}") | ||
| fun getPayment(@PathVariable id: Long): GetPaymentResponse { | ||
| val payment = paymentUseCase.getPayment(id) | ||
| return GetPaymentResponse.from(payment) | ||
| } | ||
| } | ||
77 changes: 77 additions & 0 deletions
77
...ayment-core/adapter/src/main/kotlin/app/payment/core/adapter/outbound/PaymentJpaEntity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package app.payment.core.adapter.outbound | ||
|
|
||
| import app.payment.core.domain.Payment | ||
| import app.payment.core.domain.PaymentMethod | ||
| import app.payment.core.domain.PaymentStatus | ||
| import app.payment.core.domain.PgProvider | ||
| import jakarta.persistence.Column | ||
| import jakarta.persistence.Entity | ||
| import jakarta.persistence.EnumType | ||
| import jakarta.persistence.Enumerated | ||
| import jakarta.persistence.GeneratedValue | ||
| import jakarta.persistence.GenerationType | ||
| import jakarta.persistence.Id | ||
| import jakarta.persistence.Table | ||
| import java.math.BigDecimal | ||
| import java.time.OffsetDateTime | ||
|
|
||
| @Entity | ||
| @Table(name = "payments") | ||
| class PaymentJpaEntity( | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| val id: Long = 0, | ||
|
|
||
| @Column(name = "order_id", nullable = false, unique = true) | ||
| val orderId: String, | ||
|
|
||
| @Column(name = "user_id", nullable = false) | ||
| val userId: Long, | ||
|
|
||
| @Column(nullable = false, precision = 19, scale = 2) | ||
| val amount: BigDecimal, | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| val method: PaymentMethod, | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| val pgProvider: PgProvider, | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| val status: PaymentStatus, | ||
|
|
||
| @Column(name = "transaction_id") | ||
| val transactionId: String? = null, | ||
|
|
||
| @Column(name = "pg_transaction_id") | ||
| val pgTransactionId: String? = null, | ||
|
|
||
| @Column(name = "paid_at") | ||
| val paidAt: OffsetDateTime? = null, | ||
|
|
||
| @Column(name = "created_at", nullable = false) | ||
| val createdAt: OffsetDateTime = OffsetDateTime.now(), | ||
|
|
||
| @Column(name = "updated_at", nullable = false) | ||
| val updatedAt: OffsetDateTime = OffsetDateTime.now() | ||
| ) { | ||
| fun toDomain(): Payment { | ||
| return Payment( | ||
| id = id, | ||
| orderId = orderId, | ||
| userId = userId, | ||
| amount = amount, | ||
| method = method, | ||
| pgProvider = pgProvider, | ||
| status = status, | ||
| transactionId = transactionId, | ||
| pgTransactionId = pgTransactionId, | ||
| paidAt = paidAt, | ||
| createdAt = createdAt, | ||
| updatedAt = updatedAt | ||
| ) | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
...nt-core/adapter/src/main/kotlin/app/payment/core/adapter/outbound/PaymentJpaRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package app.payment.core.adapter.outbound | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository | ||
| import org.springframework.data.jpa.repository.Query | ||
|
|
||
| interface PaymentJpaRepository : JpaRepository<PaymentJpaEntity, Long> { | ||
| } |
16 changes: 16 additions & 0 deletions
16
...yment-core/adapter/src/main/kotlin/app/payment/core/adapter/outbound/PaymentReaderImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package app.payment.core.adapter.outbound | ||
|
|
||
| import app.payment.core.application.port.outbound.PaymentReader | ||
| import app.payment.core.domain.Payment | ||
| import org.springframework.data.repository.findByIdOrNull | ||
| import org.springframework.stereotype.Component | ||
|
|
||
| @Component | ||
| class PaymentReaderImpl( | ||
| private val paymentJpaRepository: PaymentJpaRepository | ||
| ) : PaymentReader { | ||
|
|
||
| override fun findById(id: Long): Payment? { | ||
| return paymentJpaRepository.findByIdOrNull(id)?.toDomain() | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
...e/application/src/main/kotlin/app/payment/core/application/port/inbound/PaymentUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package app.payment.core.application.port.inbound | ||
|
|
||
| import app.payment.core.domain.Payment | ||
|
|
||
| interface PaymentUseCase { | ||
| fun getPayment(paymentId: Long): Payment | ||
| } | ||
|
Comment on lines
+5
to
+7
Member
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. 약간 네이밍의 문제같긴 한데, PaymentUseCase/PaymentService는 여기에 관련 기능을 몰아서 넣을지 궁금합니다. 만약 아니라면 Find 등의 행위가 나타나면 좋을것같아요/ 저번 Voucher에 제가 이부분에 대해 언급을 안했나 보네요.. |
||
7 changes: 7 additions & 0 deletions
7
...e/application/src/main/kotlin/app/payment/core/application/port/outbound/PaymentReader.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package app.payment.core.application.port.outbound | ||
|
|
||
| import app.payment.core.domain.Payment | ||
|
|
||
| interface PaymentReader { | ||
| fun findById(id: Long): Payment? | ||
| } |
19 changes: 19 additions & 0 deletions
19
...t-core/application/src/main/kotlin/app/payment/core/application/service/PaymentService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package app.payment.core.application.service | ||
|
|
||
| import app.payment.core.application.port.inbound.PaymentUseCase | ||
| import app.payment.core.application.port.outbound.PaymentReader | ||
| import app.payment.core.domain.Payment | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
|
|
||
| @Service | ||
| @Transactional(readOnly = true) | ||
| class PaymentService( | ||
| private val paymentReader: PaymentReader | ||
| ) : PaymentUseCase { | ||
|
|
||
| override fun getPayment(paymentId: Long): Payment { | ||
| return paymentReader.findById(paymentId) | ||
| ?: throw NoSuchElementException("Payment not found with id: $paymentId") | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
payment/payment-core/domain/src/main/kotlin/app/payment/core/domain/Payment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package app.payment.core.domain | ||
|
|
||
| import java.math.BigDecimal | ||
| import java.time.OffsetDateTime | ||
|
|
||
| class Payment( | ||
| val id: Long, | ||
| val orderId: String, | ||
| val userId: Long, | ||
| val amount: BigDecimal, | ||
| val method: PaymentMethod, | ||
| val pgProvider: PgProvider, | ||
| val status: PaymentStatus, | ||
| val transactionId: String?, | ||
| val pgTransactionId: String?, | ||
| val paidAt: OffsetDateTime?, | ||
| val createdAt: OffsetDateTime, | ||
| val updatedAt: OffsetDateTime | ||
| ) { | ||
| } |
10 changes: 10 additions & 0 deletions
10
payment/payment-core/domain/src/main/kotlin/app/payment/core/domain/PaymentMethod.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package app.payment.core.domain | ||
|
|
||
| enum class PaymentMethod { | ||
| CREDIT_CARD, | ||
| BANK_TRANSFER, | ||
| VIRTUAL_ACCOUNT, | ||
| MOBILE, | ||
| EASY_PAY, | ||
| GIFT_CERTIFICATE, | ||
| } |
10 changes: 10 additions & 0 deletions
10
payment/payment-core/domain/src/main/kotlin/app/payment/core/domain/PaymentStatus.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package app.payment.core.domain | ||
|
|
||
| enum class PaymentStatus { | ||
| READY, | ||
| PAY_PENDING, | ||
| PAID, | ||
| PARTIAL_CANCELLED, | ||
| CANCELLED, | ||
| FAILED, | ||
| } |
6 changes: 6 additions & 0 deletions
6
payment/payment-core/domain/src/main/kotlin/app/payment/core/domain/PgProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package app.payment.core.domain | ||
|
|
||
| enum class PgProvider { | ||
| TOSS_PAYMENTS, | ||
| KAKAO_PAY, | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
404 에러 처리를 확인하세요.
존재하지 않는 결제 ID에 대한 요청 시 적절한 HTTP 상태 코드(404 Not Found)가 반환되는지 확인이 필요합니다.
paymentUseCase.getPayment(id)에서 예외가 발생할 때 이를 처리하는 글로벌 exception handler가 구현되어 있는지 검증하세요.다음 스크립트로 exception handler 구현을 확인하세요:
🏁 Script executed:
Length of output: 26
🏁 Script executed:
Length of output: 389
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 2406
🏁 Script executed:
Length of output: 2968
글로벌 exception handler를 구현하여 404 응답을 처리하세요.
검증 결과, 존재하지 않는 결제 ID 요청 시 404 에러가 제대로 처리되지 않고 있습니다.
paymentUseCase.getPayment(id)(PaymentService.kt:15-17)는 결제를 찾지 못할 때NoSuchElementException을 발생시킵니다.@RestControllerAdvice를 통해
NoSuchElementException을 HTTP 404 상태 코드로 매핑하는 글로벌 exception handler를 구현하세요.🤖 Prompt for AI Agents