Skip to content

Commit

Permalink
♻️ AuthCode Id 리펙터링
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW committed Sep 30, 2024
1 parent 8b41609 commit c3f484f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.threedays.application.auth.vo.command

import com.threedays.domain.auth.vo.AuthCodeId
import com.threedays.domain.auth.entity.AuthCode
import com.threedays.domain.support.common.ClientOS

sealed class AuthCodeCommand {
Expand All @@ -11,7 +11,7 @@ sealed class AuthCodeCommand {
) : AuthCodeCommand()

data class Verify(
val id: AuthCodeId,
val id: AuthCode.Id,
val code: String,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.threedays.application.auth.port.outbound

import com.threedays.domain.auth.entity.AuthCode
import com.threedays.domain.auth.vo.AuthCodeId
import java.util.concurrent.ConcurrentHashMap

class AuthCodeSmsSenderSpy : AuthCodeSmsSender {

private val sentAuthCodes = ConcurrentHashMap<AuthCodeId, AuthCode>()
private val sentAuthCodes = ConcurrentHashMap<AuthCode.Id, AuthCode>()

override fun send(authCode: AuthCode) {
sentAuthCodes[authCode.id] = authCode
}

fun find(id: AuthCodeId): AuthCode? {
fun find(id: AuthCode.Id): AuthCode? {
return sentAuthCodes[id]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.threedays.domain.auth.entity

import com.threedays.domain.auth.exception.AuthException
import com.threedays.domain.auth.vo.AuthCodeId
import com.threedays.domain.auth.vo.PhoneNumber
import com.threedays.domain.support.common.ClientOS
import com.threedays.support.common.base.domain.AggregateRoot
import com.threedays.support.common.base.domain.UUIDTypeId
import java.time.LocalDateTime
import java.util.*

data class AuthCode(
override val id: AuthCodeId,
override val id: Id,
val clientOS: ClientOS,
val phoneNumber: PhoneNumber,
val code: Code,
val expireAt: LocalDateTime,
) : AggregateRoot<AuthCode, AuthCodeId>() {
) : AggregateRoot<AuthCode, AuthCode.Id>() {

data class Id(override val value: UUID) : UUIDTypeId(value)

@JvmInline
value class Code(val value: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.threedays.domain.auth.repository

import com.threedays.domain.auth.entity.AuthCode
import com.threedays.domain.auth.vo.AuthCodeId
import com.threedays.support.common.base.domain.Repository
import com.threedays.support.common.exception.NotFoundException

interface AuthCodeRepository : Repository<AuthCode, AuthCodeId> {
interface AuthCodeRepository : Repository<AuthCode, AuthCode.Id> {

fun get(id: AuthCodeId): AuthCode = find(id) ?: throw NotFoundException("AuthCode not found")
fun get(id: AuthCode.Id): AuthCode = find(id) ?: throw NotFoundException("AuthCode not found")

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.threedays.domain.auth.repository

import com.threedays.domain.auth.entity.AuthCode
import com.threedays.domain.auth.vo.AuthCodeId

class AuthCodeRepositorySpy : AuthCodeRepository {

private val authCodes = mutableMapOf<AuthCodeId, AuthCode>()
private val authCodes = mutableMapOf<AuthCode.Id, AuthCode>()

override fun save(root: AuthCode) {
authCodes[root.id] = root
}

override fun find(id: AuthCodeId): AuthCode? {
override fun find(id: AuthCode.Id): AuthCode? {
return authCodes[id]
}

override fun delete(id: AuthCodeId) {
override fun delete(id: AuthCode.Id) {
authCodes.remove(id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.threedays.redis.auth

import com.threedays.domain.auth.entity.AuthCode
import com.threedays.domain.auth.repository.AuthCodeRepository
import com.threedays.domain.auth.vo.AuthCodeId
import org.springframework.stereotype.Component

@Component
Expand All @@ -18,14 +17,14 @@ class AuthCodeRedisAdapter(
}
}

override fun find(id: AuthCodeId): AuthCode? {
override fun find(id: AuthCode.Id): AuthCode? {
return authCodeRedisRepository
.findById(id.value.toString())
.map { it.toDomain() }
.orElse(null)
}

override fun delete(id: AuthCodeId) {
override fun delete(id: AuthCode.Id) {
authCodeRedisRepository.deleteById(id.value.toString())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.threedays.redis.auth

import com.threedays.domain.auth.entity.AuthCode
import com.threedays.domain.auth.vo.AuthCodeId
import com.threedays.domain.auth.vo.PhoneNumber
import com.threedays.domain.support.common.ClientOS
import org.springframework.data.annotation.Id
Expand Down Expand Up @@ -52,7 +51,7 @@ class AuthCodeRedisHash(

fun toDomain(): AuthCode {
return AuthCode(
id = AuthCodeId(UUID.fromString(id)),
id = AuthCode.Id(UUID.fromString(id)),
clientOS = ClientOS.valueOf(clientOS),
phoneNumber = PhoneNumber(phoneNumber),
code = code,
Expand Down

0 comments on commit c3f484f

Please sign in to comment.