feat: 不要になったコンフィグを削除

This commit is contained in:
usbharu 2023-10-23 13:32:50 +09:00
parent 2a8eaf09b4
commit 9bef6db051
6 changed files with 3 additions and 199 deletions

View File

@ -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()
)

View File

@ -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<Long> = 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<Long> = 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) {

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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