feat: contentを永続化するように

This commit is contained in:
usbharu 2024-01-24 16:17:17 +09:00
parent b76e1d19a5
commit d9b1f0dfd7
3 changed files with 13 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package dev.usbharu.hideout.core.domain.model.post
import dev.usbharu.hideout.application.config.CharacterLimit
import dev.usbharu.hideout.core.service.post.PostContentFormatter
import org.springframework.stereotype.Component
import java.time.Instant
@ -23,7 +24,10 @@ data class Post private constructor(
) {
@Component
class PostBuilder(private val characterLimit: CharacterLimit) {
class PostBuilder(
private val characterLimit: CharacterLimit,
private val postContentFormatter: PostContentFormatter
) {
@Suppress("FunctionMinLength", "LongParameterList")
fun of(
id: Long,
@ -56,6 +60,8 @@ data class Post private constructor(
content
}
val (html, content1) = postContentFormatter.format(limitedText)
require(url.isNotBlank()) { "url must contain non-blank characters" }
require(url.length <= characterLimit.general.url) {
"url must not exceed ${characterLimit.general.url} characters."
@ -68,8 +74,8 @@ data class Post private constructor(
id = id,
actorId = actorId,
overview = limitedOverview,
content = content,
text = limitedText,
content = html,
text = content1,
createdAt = createdAt,
visibility = visibility,
url = url,

View File

@ -27,6 +27,7 @@ class PostRepositoryImpl(
it[id] = post.id
it[actorId] = post.actorId
it[overview] = post.overview
it[content] = post.content
it[text] = post.text
it[createdAt] = post.createdAt
it[visibility] = post.visibility.ordinal
@ -63,6 +64,7 @@ class PostRepositoryImpl(
Posts.update({ Posts.id eq post.id }) {
it[actorId] = post.actorId
it[overview] = post.overview
it[content] = post.content
it[text] = post.text
it[createdAt] = post.createdAt
it[visibility] = post.visibility.ordinal
@ -128,6 +130,7 @@ object Posts : Table() {
val id: Column<Long> = long("id")
val actorId: Column<Long> = long("actor_id").references(Actors.id)
val overview: Column<String?> = varchar("overview", 100).nullable()
val content = varchar("content", 5000)
val text: Column<String> = varchar("text", 3000)
val createdAt: Column<Long> = long("created_at")
val visibility: Column<Int> = integer("visibility").default(0)

View File

@ -90,6 +90,7 @@ create table if not exists posts
id bigint primary key,
actor_id bigint not null,
overview varchar(100) null,
content varchar(5000) not null,
text varchar(3000) not null,
created_at bigint not null,
visibility int default 0 not null,