From 7427030f0090cd0f960f2a10d11158467a0121ba Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:32:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8D=E8=A6=81=E3=81=AB=E3=81=AA?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=82=B3=E3=83=B3=E3=83=95=E3=82=A3=E3=82=B0?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/config/Config.kt | 13 -- .../domain/model/hideout/entity/Post.kt | 60 --------- .../domain/model/hideout/entity/User.kt | 120 ------------------ .../service/ap/APNoteServiceImplTest.kt | 3 +- .../ap/APReceiveFollowServiceImplTest.kt | 3 +- .../hideout/service/user/UserServiceTest.kt | 3 +- 6 files changed, 3 insertions(+), 199 deletions(-) delete mode 100644 src/main/kotlin/dev/usbharu/hideout/config/Config.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/config/Config.kt b/src/main/kotlin/dev/usbharu/hideout/config/Config.kt deleted file mode 100644 index 011754f1..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/config/Config.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.usbharu.hideout.config - -@Deprecated("Config is deprecated") -object Config { - var configData: ConfigData = ConfigData() -} - -@Deprecated("Config is deprecated") -data class ConfigData( - val url: String = "", - val domain: String = url.substringAfter("://").substringBeforeLast(":"), - val characterLimit: CharacterLimit = CharacterLimit() -) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/Post.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/Post.kt index d500c2cd..7bffa75e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/Post.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/Post.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.domain.model.hideout.entity import dev.usbharu.hideout.config.CharacterLimit -import dev.usbharu.hideout.config.Config import org.springframework.stereotype.Component data class Post private constructor( @@ -18,65 +17,6 @@ data class Post private constructor( val apId: String = url, val mediaIds: List = emptyList() ) { - companion object { - @Suppress("FunctionMinLength", "LongParameterList") - @Deprecated("Static builder is deprecated") - fun of( - id: Long, - userId: Long, - overview: String? = null, - text: String, - createdAt: Long, - visibility: Visibility, - url: String, - repostId: Long? = null, - replyId: Long? = null, - sensitive: Boolean = false, - apId: String = url, - mediaIds: List = emptyList() - ): Post { - val characterLimit = Config.configData.characterLimit - - require(id >= 0) { "id must be greater than or equal to 0." } - - require(userId >= 0) { "userId must be greater than or equal to 0." } - - val limitedOverview = if ((overview?.length ?: 0) >= characterLimit.post.overview) { - overview?.substring(0, characterLimit.post.overview) - } else { - overview - } - - val limitedText = if (text.length >= characterLimit.post.text) { - text.substring(0, characterLimit.post.text) - } else { - text - } - - require(url.isNotBlank()) { "url must contain non-blank characters" } - require(url.length <= characterLimit.general.url) { - "url must not exceed ${characterLimit.general.url} characters." - } - - require((repostId ?: 0) >= 0) { "repostId must be greater then or equal to 0." } - require((replyId ?: 0) >= 0) { "replyId must be greater then or equal to 0." } - - return Post( - id = id, - userId = userId, - overview = limitedOverview, - text = limitedText, - createdAt = createdAt, - visibility = visibility, - url = url, - repostId = repostId, - replyId = replyId, - sensitive = sensitive, - apId = apId, - mediaIds = mediaIds - ) - } - } @Component class PostBuilder(private val characterLimit: CharacterLimit) { diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt index 38eb81a2..302a3c1e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt @@ -2,7 +2,6 @@ package dev.usbharu.hideout.domain.model.hideout.entity import dev.usbharu.hideout.config.ApplicationConfig import dev.usbharu.hideout.config.CharacterLimit -import dev.usbharu.hideout.config.Config import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import java.time.Instant @@ -30,125 +29,6 @@ data class User private constructor( " privateKey=$privateKey, createdAt=$createdAt, keyId='$keyId', followers=$followers," + " following=$following)" - companion object { - - private val logger = LoggerFactory.getLogger(User::class.java) - - @Suppress("LongParameterList", "FunctionMinLength", "LongMethod") - fun of( - id: Long, - name: String, - domain: String, - screenName: String, - description: String, - password: String? = null, - inbox: String, - outbox: String, - url: String, - publicKey: String, - privateKey: String? = null, - createdAt: Instant, - keyId: String, - following: String? = null, - followers: String? = null - ): User { - val characterLimit = Config.configData.characterLimit - - // idは0未満ではいけない - require(id >= 0) { "id must be greater than or equal to 0." } - - // nameは空文字以外を含める必要がある - require(name.isNotBlank()) { "name must contain non-blank characters." } - - // nameは指定された長さ以下である必要がある - val limitedName = if (name.length >= characterLimit.account.id) { - logger.warn("name must not exceed ${characterLimit.account.id} characters.") - name.substring(0, characterLimit.account.id) - } else { - name - } - - // domainは空文字以外を含める必要がある - require(domain.isNotBlank()) { "domain must contain non-blank characters." } - - // domainは指定された長さ以下である必要がある - require(domain.length <= characterLimit.general.domain) { - "domain must not exceed ${characterLimit.general.domain} characters." - } - - // screenNameは空文字以外を含める必要がある - require(screenName.isNotBlank()) { "screenName must contain non-blank characters." } - - // screenNameは指定された長さ以下である必要がある - val limitedScreenName = if (screenName.length >= characterLimit.account.name) { - logger.warn("screenName must not exceed ${characterLimit.account.name} characters.") - screenName.substring(0, characterLimit.account.name) - } else { - screenName - } - - // descriptionは指定された長さ以下である必要がある - val limitedDescription = if (description.length >= characterLimit.account.description) { - logger.warn("description must not exceed ${characterLimit.account.description} characters.") - description.substring(0, characterLimit.account.description) - } else { - description - } - - // ローカルユーザーはpasswordとprivateKeyをnullにしてはいけない - if (domain == Config.configData.domain) { - requireNotNull(password) { "password and privateKey must not be null for local users." } - requireNotNull(privateKey) { "password and privateKey must not be null for local users." } - } - - // urlは空文字以外を含める必要がある - require(url.isNotBlank()) { "url must contain non-blank characters." } - - // urlは指定された長さ以下である必要がある - require(url.length <= characterLimit.general.url) { - "url must not exceed ${characterLimit.general.url} characters." - } - - // inboxは空文字以外を含める必要がある - require(inbox.isNotBlank()) { "inbox must contain non-blank characters." } - - // inboxは指定された長さ以下である必要がある - require(inbox.length <= characterLimit.general.url) { - "inbox must not exceed ${characterLimit.general.url} characters." - } - - // outboxは空文字以外を含める必要がある - require(outbox.isNotBlank()) { "outbox must contain non-blank characters." } - - // outboxは指定された長さ以下である必要がある - require(outbox.length <= characterLimit.general.url) { - "outbox must not exceed ${characterLimit.general.url} characters." - } - - require(keyId.isNotBlank()) { - "keyId must contain non-blank characters." - } - - return User( - id = id, - name = limitedName, - domain = domain, - screenName = limitedScreenName, - description = limitedDescription, - password = password, - inbox = inbox, - outbox = outbox, - url = url, - publicKey = publicKey, - privateKey = privateKey, - createdAt = createdAt, - keyId = keyId, - followers = followers, - following = following - ) - } - } - @Component class UserBuilder(private val characterLimit: CharacterLimit, private val applicationConfig: ApplicationConfig) { private val logger = LoggerFactory.getLogger(UserBuilder::class.java) diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt index 1c007f3e..bc9ab9c6 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt @@ -3,8 +3,6 @@ package dev.usbharu.hideout.service.ap -import dev.usbharu.hideout.config.Config -import dev.usbharu.hideout.config.ConfigData import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.domain.model.hideout.entity.Visibility @@ -23,6 +21,7 @@ import org.junit.jupiter.api.Test import org.mockito.Mockito.anyLong import org.mockito.Mockito.eq import org.mockito.kotlin.* +import org.springframework.boot.context.config.ConfigData import utils.JsonObjectMapper.objectMapper import utils.TestApplicationConfig.testApplicationConfig import java.time.Instant diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt index e786f016..89ac6dc2 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt @@ -3,8 +3,6 @@ package dev.usbharu.hideout.service.ap -import dev.usbharu.hideout.config.Config -import dev.usbharu.hideout.config.ConfigData import dev.usbharu.hideout.domain.model.ap.Follow import dev.usbharu.hideout.domain.model.ap.Image import dev.usbharu.hideout.domain.model.ap.Key @@ -23,6 +21,7 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* +import org.springframework.boot.context.config.ConfigData import utils.JsonObjectMapper.objectMapper import utils.TestTransaction import java.time.Instant diff --git a/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt index 26e4ebf8..357dcbfb 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt @@ -2,8 +2,6 @@ package dev.usbharu.hideout.service.user -import dev.usbharu.hideout.config.Config -import dev.usbharu.hideout.config.ConfigData import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto import dev.usbharu.hideout.domain.model.hideout.dto.UserCreateDto import dev.usbharu.hideout.repository.UserRepository @@ -12,6 +10,7 @@ import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* +import org.springframework.boot.context.config.ConfigData import utils.TestApplicationConfig.testApplicationConfig import java.security.KeyPairGenerator import kotlin.test.assertEquals