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

refactor: ktlint versioning by kotlin 2.1.0 #19

Merged
merged 1 commit into from
Jan 14, 2025
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
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ max_line_length = 120
# [no-wildcard-imports]
ktlint_no-wildcard-imports = disabled
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_package-name = disabled
ktlint_standard_package-name = disabled

ktlint_function_naming_ignore_when_annotated_with = Composable
10 changes: 7 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ plugins {
kotlin("plugin.jpa") version "2.1.0"
id("org.springframework.boot") version "3.4.1"
id("io.spring.dependency-management") version "1.1.7"
id("org.jlleitschuh.gradle.ktlint") version "12.1.1"
id("org.jlleitschuh.gradle.ktlint") version "12.1.2"
}

ktlint {
version.set("1.5.0")
}

version = "${property("applicationVersion")}"
Expand All @@ -18,7 +22,6 @@ java {

extra["springModulithVersion"] = "1.3.1"


repositories {
mavenCentral()
}
Expand Down Expand Up @@ -70,7 +73,6 @@ dependencyManagement {
}
}


kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xjsr305=strict")
Expand All @@ -85,8 +87,10 @@ tasks.register("addLintPreCommitHook", DefaultTask::class) {
val hooksDir = project.file(".git/hooks")
val scriptDir = project.file("scripts")
val preCommit = scriptDir.resolve("pre-commit")
Runtime.getRuntime().exec("chmod +x .git/hooks/pre-commit")
preCommit.copyTo(hooksDir.resolve("pre-commit"), overwrite = true)
hooksDir.resolve("pre-commit").setExecutable(true)
// chmod +x .git/hooks/pre-commit
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/tech/sipe/fintech/account/Account.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package tech.sipe.fintech.account

class Account {
}
class Account
7 changes: 3 additions & 4 deletions src/main/kotlin/tech/sipe/fintech/account/AccountApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import org.springframework.web.bind.annotation.RestController

@RestController
class AccountApi(
private val accountService: AccountService
private val accountService: AccountService,
) {

@PostMapping("/accounts/registration")
fun register(
@RequestParam memberId: Long
@RequestParam memberId: Long,
) {
accountService.register()
}

@PostMapping("/accounts/cancellation")
fun cancel(
@RequestParam memberId: Long
@RequestParam memberId: Long,
) {
accountService.cancel()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package tech.sipe.fintech.account

class AccountEntity {
}
class AccountEntity
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package tech.sipe.fintech.account

import org.springframework.modulith.ApplicationModule


@ApplicationModule(
type = ApplicationModule.Type.CLOSED,
allowedDependencies = []
allowedDependencies = [],
)
class AccountModuleMetadata
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package tech.sipe.fintech.account

interface AccountRepository {
fun save(account: Account)

fun delete(account: Account)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import org.springframework.stereotype.Service

@Service
class AccountService {

fun register() {
}

fun cancel() {
}
}
}
6 changes: 4 additions & 2 deletions src/main/kotlin/tech/sipe/fintech/common/LoggerUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ fun Any.logInfo(message: String) {
logger.info(message)
}

fun Any.logError(message: String? = null, e: Exception) {
fun Any.logError(
message: String? = null,
e: Exception,
) {
val logger = org.slf4j.LoggerFactory.getLogger(this.javaClass)
logger.error(message ?: e.message ?: e.localizedMessage, e)
}

2 changes: 0 additions & 2 deletions src/main/kotlin/tech/sipe/fintech/payment/Payment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package tech.sipe.fintech.payment

class Payment
{
}
5 changes: 1 addition & 4 deletions src/main/kotlin/tech/sipe/fintech/payment/PaymentApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import org.springframework.web.bind.annotation.RestController

@RestController
class PaymentApi {

@PostMapping("/payments")
fun pay(
@RequestParam memberId: Long
@RequestParam memberId: Long,
) {

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package tech.sipe.fintech.payment

class PaymentEntity {
}
class PaymentEntity
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package tech.sipe.fintech.payment

interface PaymentJpaRepository {
}
interface PaymentJpaRepository
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.springframework.modulith.ApplicationModule

@ApplicationModule(
type = ApplicationModule.Type.CLOSED,
allowedDependencies = []
allowedDependencies = [],
)
class PaymentModuleMetadata
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package tech.sipe.fintech.payment

class PaymentService {
}
class PaymentService
8 changes: 0 additions & 8 deletions src/main/kotlin/tech/sipe/fintech/payment/package-info.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tech.sipe.fintech.transfer
import org.springframework.modulith.ApplicationModule

@ApplicationModule(
allowedDependencies = ["wallet"]
allowedDependencies = ["wallet"],
)
class TransferModuleMetadata {
}
class TransferModuleMetadata
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ package tech.sipe.fintech.transfer.internal

class Transfer(
val id: Long,
val money: Long
) {
}
val money: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,25 @@ import tech.sipe.fintech.wallet.PayWalletApi
@RestController
class TransferApi(
private val transferService: TransferService,
private val payWalletApi: PayWalletApi
private val payWalletApi: PayWalletApi,
) {

@PostMapping("/transfers/charge")
fun charge(
@RequestParam memberId: Long
@RequestParam memberId: Long,
) {
val balance = payWalletApi.getBalance(123)
transferService.charge()
}

@PostMapping("/transfers/withdrawal")
fun withdraw(
@RequestParam memberId: Long
@RequestParam memberId: Long,
) {}

@PostMapping("/transfers")
fun transfer(
@RequestParam memberId: Long
@RequestParam memberId: Long,
) {
transferService.transfer()
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package tech.sipe.fintech.transfer.internal

class TransferEntity {
}
class TransferEntity
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package tech.sipe.fintech.transfer.internal

interface TransferJpaRepository {
}
interface TransferJpaRepository
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package tech.sipe.fintech.transfer.internal

interface TransferRepository
{
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package tech.sipe.fintech.transfer.internal

import org.springframework.stereotype.Service
import tech.sipe.fintech.wallet.internal.domain.Currency
import tech.sipe.fintech.wallet.internal.domain.PayWallet
import tech.sipe.fintech.wallet.internal.domain.WalletStatus
import java.math.BigDecimal


@Service
class TransferService(
) {
class TransferService {
fun charge() {
}
fun transfer() {

fun transfer() {
}
}
12 changes: 10 additions & 2 deletions src/main/kotlin/tech/sipe/fintech/wallet/PayWalletApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ package tech.sipe.fintech.wallet
* @author κΉ€μž¬μ˜ ([email protected])
*/
interface PayWalletApi {
fun charge(amount: Long, payWalletId: Long)
fun pay(amount: Long, payWalletId: Long)
fun charge(
amount: Long,
payWalletId: Long,
)

fun pay(
amount: Long,
payWalletId: Long,
)

fun getBalance(payWalletId: Long): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.springframework.modulith.ApplicationModule

@ApplicationModule(
type = ApplicationModule.Type.CLOSED,
allowedDependencies = []
allowedDependencies = [],
)
class WalletModuleMetadata
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ class PayWallet(
balance: BigDecimal,
val currency: Currency,
) {
companion object {
private const val MINIMUM_CHARGE_AMOUNT = 1000
}

var balance: BigDecimal = balance
private set

private val MINIMUM_CHARGE_AMOUNT = 1000

/**
* μΆ©μ „
*/
fun charge(amount: Long) {
if (amount < MINIMUM_CHARGE_AMOUNT) {
throw IllegalArgumentException("μ΅œμ†Œ μΆ©μ „ κΈˆμ•‘μ€ 1,000μ›μž…λ‹ˆλ‹€.")
}
balance += BigDecimal.valueOf(amount)
balance += BigDecimal.valueOf(amount)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import tech.sipe.fintech.wallet.internal.infra.PayWalletEntity

class PayWalletMapper {
companion object {
fun toDomain(entity: PayWalletEntity): PayWallet {
return PayWallet(
fun toDomain(entity: PayWalletEntity): PayWallet =
PayWallet(
id = entity.id ?: throw DataIntegrityViolationException("Id is null"),
userId = entity.userId,
accountId = entity.accountId,
walletStatus = entity.walletStatus,
balance = entity.balance,
currency = entity.currency
currency = entity.currency,
)
}

fun toEntity(domain: PayWallet) = PayWalletEntity(
userId = domain.userId,
accountId = domain.accountId,
walletStatus = domain.walletStatus,
balance = domain.balance,
currency = domain.currency
)
fun toEntity(domain: PayWallet) =
PayWalletEntity(
userId = domain.userId,
accountId = domain.accountId,
walletStatus = domain.walletStatus,
balance = domain.balance,
currency = domain.currency,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.sipe.fintech.wallet.internal.domain


interface PayWalletRepository {
fun findByUserId(userId: Long): PayWallet

fun save(payWalletEntity: PayWallet): PayWallet
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ package tech.sipe.fintech.wallet.internal.domain
enum class WalletStatus {
ACTIVE,
INACTIVE,
SUSPENDED
SUSPENDED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class PayWalletEntity(
val balance: BigDecimal = BigDecimal.ZERO,
@Enumerated(value = EnumType.STRING)
val currency: Currency,
): BaseEntity()
) : BaseEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package tech.sipe.fintech.wallet.internal.infra

import org.springframework.data.jpa.repository.JpaRepository

interface PayWalletJpaRepository : JpaRepository<PayWalletEntity, Long>{
fun findByUserId(userId: Long) : PayWalletEntity?
interface PayWalletJpaRepository : JpaRepository<PayWalletEntity, Long> {
fun findByUserId(userId: Long): PayWalletEntity?
}
Loading