From adf1dfc1f325fa4103824cf62bcaf1ddca1b8589 Mon Sep 17 00:00:00 2001 From: usbharu Date: Sun, 11 May 2025 23:09:25 +0900 Subject: [PATCH 1/4] feat: post content auto truncate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Postのcontentとtextを自動で制限文字数内に切り取るように --- .../core/domain/model/post/PostContent.kt | 40 ++++++++++++++++- .../core/domain/model/post/PostContentTest.kt | 44 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt index 9f6b2db7..28944d80 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt @@ -18,11 +18,49 @@ package dev.usbharu.hideout.core.domain.model.post import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiId -data class PostContent(val text: String, val content: String, val emojiIds: List) { +class PostContent { + + val text: String + val content: String + val emojiIds: List + + constructor(text: String, content: String, emojiIds: List) { + this.text = text.take(TEXT_LENGTH) + this.content = content.take(CONTENT_LENGTH) + this.emojiIds = emojiIds.distinct() + } companion object { val empty = PostContent("", "", emptyList()) const val CONTENT_LENGTH = 5000 const val TEXT_LENGTH = 3000 } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as PostContent + + if (text != other.text) return false + if (content != other.content) return false + if (emojiIds != other.emojiIds) return false + + return true + } + + override fun hashCode(): Int { + var result = text.hashCode() + result = 31 * result + content.hashCode() + result = 31 * result + emojiIds.hashCode() + return result + } + + override fun toString(): String { + return "PostContent(" + + "text='$text', " + + "content='$content', " + + "emojiIds=$emojiIds" + + ")" + } } diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt new file mode 100644 index 00000000..e0da8111 --- /dev/null +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt @@ -0,0 +1,44 @@ +package dev.usbharu.hideout.core.domain.model.post + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class PostContentTest { + @Test + fun textがtext_lengthを超える場合は切り取られる() { + val postContent = PostContent( + "a".repeat(PostContent.TEXT_LENGTH + 1), + "b".repeat(PostContent.CONTENT_LENGTH), + emptyList() + ) + + assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) + assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) + } + + @Test + fun contentがcontent_lengthを超える場合は切り取られる() { + val postContent = PostContent( + "a".repeat(PostContent.TEXT_LENGTH), + "b".repeat(PostContent.CONTENT_LENGTH + 1), + emptyList() + ) + + assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) + assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) + } + + @Test + fun textとcontentがtext_lengthとcontent_lengthを超えない場合は変わらない() { + val postContent = PostContent( + "a".repeat(PostContent.TEXT_LENGTH), + "b".repeat(PostContent.CONTENT_LENGTH), + emptyList() + ) + + assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) + assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) + } + + +} \ No newline at end of file From 3c604abe37e0ed573fda5cdf1990dc975a926d74 Mon Sep 17 00:00:00 2001 From: usbharu Date: Sun, 11 May 2025 23:59:06 +0900 Subject: [PATCH 2/4] feat: persistence truncation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Postが切り詰められたかを永続化するように --- .../hideout/core/domain/model/post/Post.kt | 7 +- .../core/domain/model/post/PostContent.kt | 2 + .../exposed/PostResultRowMapper.kt | 3 +- .../ExposedPostRepository.kt | 5 +- .../resources/db/migration/V1__Init_DB.sql | 33 +- .../core/domain/model/post/PostContentTest.kt | 32 +- .../core/domain/model/post/TestPostFactory.kt | 4 +- .../ExposedPostRepositoryTest.kt | 544 ++---------------- .../ExposedReactionRepositoryTest.kt | 6 +- .../src/test/kotlin/utils/DbSetupUtil.kt | 27 + 10 files changed, 119 insertions(+), 544 deletions(-) create mode 100644 hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index db5f2732..8e8cd76f 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -46,6 +46,7 @@ class Post( visibleActors: Set, hide: Boolean, moveTo: PostId?, + val wasTruncated: Boolean, ) : DomainEventStorable() { val actorId = actorId @@ -235,7 +236,8 @@ class Post( mediaIds = mediaIds, visibleActors = visibleActors, hide = hide, - moveTo = moveTo + moveTo = moveTo, + wasTruncated = wasTruncated ) } @@ -310,7 +312,8 @@ class Post( mediaIds = mediaIds, visibleActors = visibleActors, hide = hide, - moveTo = moveTo + moveTo = moveTo, + wasTruncated = content.wasTruncated ) post.addDomainEvent(PostDomainEventFactory(post).createEvent(PostEvent.CREATE)) return post diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt index 28944d80..eb421ebd 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt @@ -23,8 +23,10 @@ class PostContent { val text: String val content: String val emojiIds: List + val wasTruncated: Boolean constructor(text: String, content: String, emojiIds: List) { + wasTruncated = text.length > TEXT_LENGTH || content.length > CONTENT_LENGTH this.text = text.take(TEXT_LENGTH) this.content = content.take(CONTENT_LENGTH) this.emojiIds = emojiIds.distinct() diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt index fccc7166..2d8dd4ca 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt @@ -44,7 +44,8 @@ class PostResultRowMapper : ResultRowMapper { mediaIds = emptyList(), visibleActors = emptySet(), hide = resultRow[Posts.hide], - moveTo = resultRow[Posts.moveTo]?.let { PostId(it) } + moveTo = resultRow[Posts.moveTo]?.let { PostId(it) }, + wasTruncated = resultRow[Posts.wasTruncated] ) } } diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt index a65b6155..dd3b5914 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt @@ -39,6 +39,7 @@ import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.sensitive import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.text import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.url import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.visibility +import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts.wasTruncated import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList @@ -123,6 +124,7 @@ class ExposedPostRepository( this[deleted] = it.deleted this[hide] = it.hide this[moveTo] = it.moveTo?.id + this[wasTruncated] = it.wasTruncated } val mediaIds = posts.flatMap { post -> post.mediaIds.map { post.id.id to it.id } } val postsIds = posts.map { it.id.id } @@ -296,10 +298,11 @@ object Posts : Table("posts") { val repostId = long("repost_id").references(id).nullable() val replyId = long("reply_id").references(id).nullable() val sensitive = bool("sensitive") - val apId = varchar("ap_id", 1000) + val apId = varchar("ap_id", 1000).uniqueIndex() val deleted = bool("deleted") val hide = bool("hide") val moveTo = long("move_to").references(id).nullable() + val wasTruncated = bool("was_truncated").default(false).clientDefault { false } override val primaryKey: PrimaryKey = PrimaryKey(id) } diff --git a/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql b/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql index 38395744..8ce6c211 100644 --- a/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql +++ b/hideout/hideout-core/src/main/resources/db/migration/V1__Init_DB.sql @@ -149,22 +149,23 @@ alter table actors create table if not exists posts ( - id bigint primary key, - actor_id bigint not null, - instance_id bigint not null, - overview varchar(100) null, - content varchar(5000) not null, - text varchar(3000) not null, - created_at timestamp not null, - visibility varchar(100) not null, - url varchar(500) not null, - repost_id bigint null, - reply_id bigint null, - "sensitive" boolean default false not null, - ap_id varchar(100) not null unique, - deleted boolean default false not null, - hide boolean default false not null, - move_to bigint default null null + id bigint primary key, + actor_id bigint not null, + instance_id bigint not null, + overview varchar(100) null, + content varchar(5000) not null, + text varchar(3000) not null, + created_at timestamp not null, + visibility varchar(100) not null, + url varchar(500) not null, + repost_id bigint null, + reply_id bigint null, + "sensitive" boolean default false not null, + ap_id varchar(100) not null unique, + deleted boolean default false not null, + hide boolean default false not null, + move_to bigint default null null, + was_truncated boolean default false not null ); alter table posts add constraint fk_posts_instance_id__id foreign key (instance_id) references instance (id) on delete cascade on update cascade; diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt index e0da8111..327e91ef 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContentTest.kt @@ -1,44 +1,48 @@ package dev.usbharu.hideout.core.domain.model.post -import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test class PostContentTest { @Test - fun textがtext_lengthを超える場合は切り取られる() { + fun textがtext_lengthを超える場合は切り取られてwasTruncatedがtrue() { val postContent = PostContent( "a".repeat(PostContent.TEXT_LENGTH + 1), "b".repeat(PostContent.CONTENT_LENGTH), emptyList() ) - assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) - assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) - } - - @Test - fun contentがcontent_lengthを超える場合は切り取られる() { - val postContent = PostContent( - "a".repeat(PostContent.TEXT_LENGTH), - "b".repeat(PostContent.CONTENT_LENGTH + 1), - emptyList() - ) + assertTrue(postContent.wasTruncated) assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) } @Test - fun textとcontentがtext_lengthとcontent_lengthを超えない場合は変わらない() { + fun textがtext_lengthを超えない場合は変わらずwasTruncatedがfalse() { val postContent = PostContent( "a".repeat(PostContent.TEXT_LENGTH), "b".repeat(PostContent.CONTENT_LENGTH), emptyList() ) + assertFalse(postContent.wasTruncated) + assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) } + @Test + fun contentがcontent_lengthを超える場合は切り取られてwasTruncatedがtrue() { + val postContent = PostContent( + "a".repeat(PostContent.TEXT_LENGTH), + "b".repeat(PostContent.CONTENT_LENGTH + 1), + emptyList() + ) + assertTrue(postContent.wasTruncated) + + assertEquals(postContent.text, "a".repeat(PostContent.TEXT_LENGTH)) + assertEquals(postContent.content, "b".repeat(PostContent.CONTENT_LENGTH)) + } } \ No newline at end of file diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt index 47b7e9e9..c6cb48c8 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/TestPostFactory.kt @@ -31,6 +31,7 @@ object TestPostFactory { hide: Boolean = false, moveTo: Long? = null, emojiIds: List = emptyList(), + wasTruncated: Boolean = false, ): Post { return Post( PostId(id), @@ -49,7 +50,8 @@ object TestPostFactory { mediaIds = mediaIds.map { MediaId(it) }, visibleActors = visibleActors.map { ActorId(it) }.toSet(), hide = hide, - moveTo = moveTo?.let { PostId(it) } + moveTo = moveTo?.let { PostId(it) }, + wasTruncated = wasTruncated ) } diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt index 527212c2..6a726113 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepositoryTest.kt @@ -270,7 +270,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { "http://localhost:8081/users/a/posts/1832779994749734912", false, false, - null + null, + false ) } }.launch() @@ -329,7 +330,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { "http://localhost:8081/users/a/posts/1832779994749734912", false, false, - null + null, + false ) } insertInto(PostsMedia.tableName) { @@ -364,7 +366,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { deleted = false, mediaIds = listOf(MediaId(2)), visibleActors = setOf(ActorId(4)), - hide = false, moveTo = null + hide = false, + moveTo = null, + wasTruncated = false ) assertNotNull(actual) @@ -398,60 +402,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1832779978794602496, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1832779978794602496, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1832779978794602496, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -467,60 +420,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 2, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2, 2) + postsValues(3) } }.launch() @@ -536,65 +438,16 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() val findAllById = repository.findByActorId(ActorId(1), Page.of(maxId = 3)) + findAllById.forEach(::println) + assertThat(findAllById) .hasSize(2) @@ -608,60 +461,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -680,60 +482,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -752,60 +503,9 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(2) + postsValues(3) } }.launch() @@ -823,24 +523,7 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1832779978794602496, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) + postsValues(1) } insertInto(PostsMedia.tableName) { columns(PostsMedia.columns) @@ -884,78 +567,10 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 2, - 2, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-02T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/18327739994749734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/18327793994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "UNLISTED", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) - values( - 4, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-04T00:00:00Z")), - "FOLLOWERS", - "http://localhost:8081/users/a/posts/1832773999474947343912", - null, - null, - false, - "http://localhost:8081/users/a/posts/1832779399474937349312", - false, - false, - 2 - ) + postsValues(1) + postsValues(2, 2) + postsValues(3, 2) + postsValues(4) } }.launch() @@ -975,42 +590,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "UNLISTED", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(3) } insertInto(PostsMedia.tableName) { columns(PostsMedia.columns) @@ -1087,42 +668,8 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) - values( - 3, - 1, - 1832779642545639424, - "", - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-03T00:00:00Z")), - "UNLISTED", - "http://localhost:8081/users/a/posts/183277399947494734912", - null, - null, - false, - "http://localhost:8081/users/a/posts/183277939947493734912", - false, - false, - 2 - ) + postsValues(1) + postsValues(3) } insertInto(PostsMedia.tableName) { columns(PostsMedia.columns) @@ -1168,24 +715,7 @@ class ExposedPostRepositoryTest : AbstractRepositoryTest(Posts) { execute(disableReferenceIntegrityConstraints) insertInto("public.posts") { columns(Posts.columns) - values( - 1, - 1, - 1832779642545639424, - null, - "

test

", - "test", - Timestamp.from(Instant.parse("2020-01-01T00:00:00Z")), - "PUBLIC", - "http://localhost:8081/users/a/posts/1832779994749734912", - 2, - 2, - false, - "http://localhost:8081/users/a/posts/1832779994749734912", - false, - false, - null - ) + postsValues(1) } }.launch() diff --git a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt index ab8c59c6..9620c63f 100644 --- a/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt +++ b/hideout/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedReactionRepositoryTest.kt @@ -56,7 +56,8 @@ class ExposedReactionRepositoryTest : AbstractRepositoryTest(Reactions) { "https://example.com", false, false, - null + null, + false ) } insertInto("public.actors") { @@ -141,7 +142,8 @@ class ExposedReactionRepositoryTest : AbstractRepositoryTest(Reactions) { "https://example.com", false, false, - null + null, + false ) } insertInto("public.actors") { diff --git a/hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt b/hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt new file mode 100644 index 00000000..0b542fb9 --- /dev/null +++ b/hideout/hideout-core/src/test/kotlin/utils/DbSetupUtil.kt @@ -0,0 +1,27 @@ +package utils + +import com.ninja_squad.dbsetup.operation.Insert +import java.sql.Timestamp +import java.time.Instant + +fun Insert.Builder.postsValues(index: Long = 1, actor: Long = 1) { + values( + index, + actor, + 1832779642545639424, + null, + "

test

", + "test", + Timestamp.from(Instant.parse("2020-01-01T00:00:00Z").plusSeconds(index.toLong())), + "PUBLIC", + "http://localhost:8081/users/a/posts/1832779994749734912", + 2, + 2, + false, + "http://localhost:8081/users/a/posts/1832779994749734912$index", + false, + false, + null, + false + ) +} \ No newline at end of file From c88ff0b3fe50ad2f3ee414b5cd038cf777086c0d Mon Sep 17 00:00:00 2001 From: usbharu Date: Mon, 12 May 2025 00:12:57 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E6=AD=A3=E5=B8=B8=E3=81=AB=E6=B0=B8?= =?UTF-8?q?=E7=B6=9A=E5=8C=96=E3=81=95=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/core/domain/model/post/PostContent.kt | 9 +++++++-- .../exposedrepository/ExposedPostRepository.kt | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt index eb421ebd..86986c8d 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt @@ -44,6 +44,7 @@ class PostContent { other as PostContent + if (wasTruncated != other.wasTruncated) return false if (text != other.text) return false if (content != other.content) return false if (emojiIds != other.emojiIds) return false @@ -52,7 +53,8 @@ class PostContent { } override fun hashCode(): Int { - var result = text.hashCode() + var result = wasTruncated.hashCode() + result = 31 * result + text.hashCode() result = 31 * result + content.hashCode() result = 31 * result + emojiIds.hashCode() return result @@ -62,7 +64,10 @@ class PostContent { return "PostContent(" + "text='$text', " + "content='$content', " + - "emojiIds=$emojiIds" + + "emojiIds=$emojiIds, " + + "wasTruncated=$wasTruncated" + ")" } + + } diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt index dd3b5914..2525fc19 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt @@ -75,6 +75,7 @@ class ExposedPostRepository( it[deleted] = post.deleted it[hide] = post.hide it[moveTo] = post.moveTo?.id + it[wasTruncated] = post.wasTruncated } PostsMedia.deleteWhere { postId eq post.id.id From 516147252b1bac84f36b4a08a408b9f57cc3590d Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 11 May 2025 15:20:44 +0000 Subject: [PATCH 4/4] style: fix lint (CI) --- .../hideout/core/domain/model/post/PostContent.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt index 86986c8d..23cddb01 100644 --- a/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt +++ b/hideout/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostContent.kt @@ -62,12 +62,10 @@ class PostContent { override fun toString(): String { return "PostContent(" + - "text='$text', " + - "content='$content', " + - "emojiIds=$emojiIds, " + - "wasTruncated=$wasTruncated" + - ")" + "text='$text', " + + "content='$content', " + + "emojiIds=$emojiIds, " + + "wasTruncated=$wasTruncated" + + ")" } - - }