From c3f484fd5b06bf900c8a4c533fe3684e1eca1f23 Mon Sep 17 00:00:00 2001 From: San Kim Date: Mon, 30 Sep 2024 23:06:53 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20AuthCode=20Id=20=EB=A6=AC?= =?UTF-8?q?=ED=8E=99=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/auth/vo/command/AuthCodeCommand.kt | 4 ++-- .../auth/port/outbound/AuthCodeSmsSenderSpy.kt | 5 ++--- .../kotlin/com/threedays/domain/auth/entity/AuthCode.kt | 8 +++++--- .../domain/auth/repository/AuthCodeRepository.kt | 5 ++--- .../domain/auth/repository/AuthCodeRepositorySpy.kt | 7 +++---- .../com/threedays/redis/auth/AuthCodeRedisAdapter.kt | 5 ++--- .../kotlin/com/threedays/redis/auth/AuthCodeRedisHash.kt | 3 +-- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt b/application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt index 09e50ac..c05eec7 100644 --- a/application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt +++ b/application/src/main/kotlin/com/threedays/application/auth/vo/command/AuthCodeCommand.kt @@ -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 { @@ -11,7 +11,7 @@ sealed class AuthCodeCommand { ) : AuthCodeCommand() data class Verify( - val id: AuthCodeId, + val id: AuthCode.Id, val code: String, ) diff --git a/application/src/testFixtures/kotlin/com/threedays/application/auth/port/outbound/AuthCodeSmsSenderSpy.kt b/application/src/testFixtures/kotlin/com/threedays/application/auth/port/outbound/AuthCodeSmsSenderSpy.kt index 80b4f87..24aff4f 100644 --- a/application/src/testFixtures/kotlin/com/threedays/application/auth/port/outbound/AuthCodeSmsSenderSpy.kt +++ b/application/src/testFixtures/kotlin/com/threedays/application/auth/port/outbound/AuthCodeSmsSenderSpy.kt @@ -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() + private val sentAuthCodes = ConcurrentHashMap() override fun send(authCode: AuthCode) { sentAuthCodes[authCode.id] = authCode } - fun find(id: AuthCodeId): AuthCode? { + fun find(id: AuthCode.Id): AuthCode? { return sentAuthCodes[id] } diff --git a/domain/src/main/kotlin/com/threedays/domain/auth/entity/AuthCode.kt b/domain/src/main/kotlin/com/threedays/domain/auth/entity/AuthCode.kt index ef50669..46ad52c 100644 --- a/domain/src/main/kotlin/com/threedays/domain/auth/entity/AuthCode.kt +++ b/domain/src/main/kotlin/com/threedays/domain/auth/entity/AuthCode.kt @@ -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() { +) : AggregateRoot() { + + data class Id(override val value: UUID) : UUIDTypeId(value) @JvmInline value class Code(val value: String) { diff --git a/domain/src/main/kotlin/com/threedays/domain/auth/repository/AuthCodeRepository.kt b/domain/src/main/kotlin/com/threedays/domain/auth/repository/AuthCodeRepository.kt index d0b10a9..62d674e 100644 --- a/domain/src/main/kotlin/com/threedays/domain/auth/repository/AuthCodeRepository.kt +++ b/domain/src/main/kotlin/com/threedays/domain/auth/repository/AuthCodeRepository.kt @@ -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 { +interface AuthCodeRepository : Repository { - 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") } diff --git a/domain/src/testFixtures/kotlin/com/threedays/domain/auth/repository/AuthCodeRepositorySpy.kt b/domain/src/testFixtures/kotlin/com/threedays/domain/auth/repository/AuthCodeRepositorySpy.kt index f27f50a..57f1287 100644 --- a/domain/src/testFixtures/kotlin/com/threedays/domain/auth/repository/AuthCodeRepositorySpy.kt +++ b/domain/src/testFixtures/kotlin/com/threedays/domain/auth/repository/AuthCodeRepositorySpy.kt @@ -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() + private val authCodes = mutableMapOf() 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) } diff --git a/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisAdapter.kt b/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisAdapter.kt index 536b59e..8909c3c 100644 --- a/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisAdapter.kt +++ b/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisAdapter.kt @@ -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 @@ -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()) } diff --git a/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisHash.kt b/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisHash.kt index bb77e5d..9ff6899 100644 --- a/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisHash.kt +++ b/infrastructure/redis/src/main/kotlin/com/threedays/redis/auth/AuthCodeRedisHash.kt @@ -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 @@ -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,