Skip to content
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

[#3] 테스트 코드 작성 및 API 명세 자동화 #5

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ spring:
uri: lb://USER
predicates:
- Path=/users/**
- id: product
- id: item
uri: lb://USER
predicates:
- Path=/products/**
- Path=/items/**
- id: cart
uri: lb://USER
predicates:
- Path=/carts/**
- id: order
uri: lb://USER
predicates:
Expand All @@ -31,3 +35,12 @@ spring:
uri: lb://PAYMENT
predicates:
- Path=/payments/**
- Path=/v2/toss/**
- id: checkout
uri: lb://PAYMENT
predicates:
- Path=/checkout/**
- id: wallet
uri: lb://PAYMENT
predicates:
- Path=/wallets/**
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ applicationVersion=0.0.1
projectGroup=com.justcommerce

kotlinVersion=1.9.25
kotestVersion=5.7.2
kotestExtensionsSpring=1.3.0
asciidoctorJvmConvertVersion=3.3.2
springBootVersion=3.3.4
springDependencyManagementVersion=1.1.6
springCloudDependenciesVersion=2023.0.3
12 changes: 11 additions & 1 deletion payment/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
application
kotlin("jvm")
kotlin("plugin.spring")
kotlin("plugin.jpa")
id("org.springframework.boot")
id("io.spring.dependency-management")
}

// application {
// mainClass.set("com.justcommerce.PaymentApplication")
// }

val kotestVersion: String by project
val springCloudDependenciesVersion: String by project
val kotestExtensionsSpring: String by project
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
Expand All @@ -19,10 +27,12 @@ dependencies {

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest.extensions:kotest-extensions-spring:$kotestExtensionsSpring")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

val springCloudDependenciesVersion: String by project
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$springCloudDependenciesVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.justcommerce.payment
package com.justcommerce

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.justcommerce.common.util

import java.util.UUID

object IdempotencyCreator {

fun create(data: Any): String {
return UUID.nameUUIDFromBytes(data.toString().toByteArray()).toString()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.justcommerce.payment.controller

import com.justcommerce.payment.controller.request.CheckoutRequest
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping

@Controller
@RequestMapping("/checkout")
class CheckoutController {

@GetMapping
fun checkoutPage(request: CheckoutRequest, model: Model): String {
// TODO CheckoutRequest 정보를 기반으로 Payment 정보 (Payment 1 : PaymentOrder N 관계) DB 저장
val orderId = 1
val amount = 1000

model.apply {
this.addAttribute("orderId", orderId)
this.addAttribute("amount", amount)
}
return "/widget/checkout"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.justcommerce.payment.controller

import com.justcommerce.payment.controller.request.TossPaymentConfirmRequest
import com.justcommerce.payment.controller.response.TossPaymentConfirmResponse
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

@RestController
@RequestMapping("/v2/toss")
class PaymentController {

@PostMapping("/confirm/widget")
fun confirm(@RequestBody request: TossPaymentConfirmRequest): TossPaymentConfirmResponse {
// TODO
// 1. 결제 승인 데이터 검증
// 2. 결제 상태 업데이트
// 3. 결제 승인 https://api.tosspayments.com/v1/payments/confirm 전송
// 4. 결제 승인 실패 시 결제 승인 재요청 전략 수립 필요
// 5. 결제 상태 업데이트 (성공이라면 장부와 판매자 지갑에도 업데이트 필요)

return TossPaymentConfirmResponse("OK", "")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.justcommerce.payment.controller.request

import com.justcommerce.common.util.IdempotencyCreator
import java.time.LocalDateTime

data class CheckoutRequest (
val cartId: Long,
val buyerId: Long,
val productIds: List<String>
) {
val idempotencyKey: String = IdempotencyCreator.create(this)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.justcommerce.payment.controller.request

data class TossPaymentConfirmRequest (
val paymentKey: String,
val orderId: String,
val amount: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.justcommerce.payment.controller.response

data class TossPaymentConfirmResponse (
val status: String,
val failure: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.justcommerce.payment.domain

enum class TransactionType (val describe: String) {
DEBIT("차변"), CREDIT("대변")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.justcommerce.wallet.controller

import com.justcommerce.wallet.controller.request.WalletTransactionCreateRequest
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

@RestController
@RequestMapping("/wallets")
class WalletController {

@PostMapping("/{userId}")
fun createTransaction(@RequestBody request: WalletTransactionCreateRequest) {
// TODO 판매자의 지갑에 판매 금액을 저장한다. (Wallet 1 : Wallet Transactions N)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.justcommerce.wallet.controller.request

import com.justcommerce.payment.domain.TransactionType

data class WalletTransactionCreateRequest (
val userId: Long,
val amount: Long,
val type: TransactionType
)
Loading
Loading