mirror of https://github.com/usbharu/Hideout.git
feat: 投稿に絵文字データを使えるように
This commit is contained in:
parent
cf52ebfd12
commit
0607fe2bc5
|
@ -17,7 +17,8 @@ data class Post private constructor(
|
|||
val sensitive: Boolean = false,
|
||||
val apId: String = url,
|
||||
val mediaIds: List<Long> = emptyList(),
|
||||
val delted: Boolean = false
|
||||
val delted: Boolean = false,
|
||||
val emojiIds: List<Long> = emptyList()
|
||||
) {
|
||||
|
||||
@Component
|
||||
|
@ -35,7 +36,8 @@ data class Post private constructor(
|
|||
replyId: Long? = null,
|
||||
sensitive: Boolean = false,
|
||||
apId: String = url,
|
||||
mediaIds: List<Long> = emptyList()
|
||||
mediaIds: List<Long> = emptyList(),
|
||||
emojiIds: List<Long> = emptyList()
|
||||
): Post {
|
||||
require(id >= 0) { "id must be greater than or equal to 0." }
|
||||
|
||||
|
@ -74,7 +76,8 @@ data class Post private constructor(
|
|||
sensitive = sensitive,
|
||||
apId = apId,
|
||||
mediaIds = mediaIds,
|
||||
delted = false
|
||||
delted = false,
|
||||
emojiIds = emojiIds
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import dev.usbharu.hideout.application.infrastructure.exposed.QueryMapper
|
|||
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Posts
|
||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.PostsEmojis
|
||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.PostsMedia
|
||||
import org.jetbrains.exposed.sql.Query
|
||||
import org.springframework.stereotype.Component
|
||||
|
@ -15,7 +16,9 @@ class PostQueryMapper(private val postResultRowMapper: ResultRowMapper<Post>) :
|
|||
.map { it.value }
|
||||
.map {
|
||||
it.first().let(postResultRowMapper::map)
|
||||
.copy(mediaIds = it.mapNotNull { resultRow -> resultRow.getOrNull(PostsMedia.mediaId) })
|
||||
.copy(
|
||||
mediaIds = it.mapNotNull { resultRow -> resultRow.getOrNull(PostsMedia.mediaId) },
|
||||
emojiIds = it.mapNotNull { resultRow -> resultRow.getOrNull(PostsEmojis.emojiId) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,14 +41,25 @@ class PostRepositoryImpl(
|
|||
this[PostsMedia.postId] = post.id
|
||||
this[PostsMedia.mediaId] = it
|
||||
}
|
||||
PostsEmojis.batchInsert(post.emojiIds) {
|
||||
this[PostsEmojis.postId] = post.id
|
||||
this[PostsEmojis.emojiId] = it
|
||||
}
|
||||
} else {
|
||||
PostsMedia.deleteWhere {
|
||||
postId eq post.id
|
||||
}
|
||||
PostsEmojis.deleteWhere {
|
||||
postId eq post.id
|
||||
}
|
||||
PostsMedia.batchInsert(post.mediaIds) {
|
||||
this[PostsMedia.postId] = post.id
|
||||
this[PostsMedia.mediaId] = it
|
||||
}
|
||||
PostsEmojis.batchInsert(post.emojiIds) {
|
||||
this[PostsEmojis.postId] = post.id
|
||||
this[PostsEmojis.emojiId] = it
|
||||
}
|
||||
Posts.update({ Posts.id eq post.id }) {
|
||||
it[actorId] = post.actorId
|
||||
it[overview] = post.overview
|
||||
|
@ -67,21 +78,27 @@ class PostRepositoryImpl(
|
|||
}
|
||||
|
||||
override suspend fun findById(id: Long): Post? = query {
|
||||
return@query Posts.leftJoin(PostsMedia)
|
||||
return@query Posts
|
||||
.leftJoin(PostsMedia)
|
||||
.leftJoin(PostsEmojis)
|
||||
.select { Posts.id eq id }
|
||||
.let(postQueryMapper::map)
|
||||
.singleOrNull()
|
||||
}
|
||||
|
||||
override suspend fun findByUrl(url: String): Post? = query {
|
||||
return@query Posts.leftJoin(PostsMedia)
|
||||
return@query Posts
|
||||
.leftJoin(PostsMedia)
|
||||
.leftJoin(PostsEmojis)
|
||||
.select { Posts.url eq url }
|
||||
.let(postQueryMapper::map)
|
||||
.singleOrNull()
|
||||
}
|
||||
|
||||
override suspend fun findByApId(apId: String): Post? = query {
|
||||
return@query Posts.leftJoin(PostsMedia)
|
||||
return@query Posts
|
||||
.leftJoin(PostsMedia)
|
||||
.leftJoin(PostsEmojis)
|
||||
.select { Posts.apId eq apId }
|
||||
.let(postQueryMapper::map)
|
||||
.singleOrNull()
|
||||
|
@ -92,7 +109,10 @@ class PostRepositoryImpl(
|
|||
}
|
||||
|
||||
override suspend fun findByActorId(actorId: Long): List<Post> = query {
|
||||
return@query Posts.select { Posts.actorId eq actorId }.let(postQueryMapper::map)
|
||||
return@query Posts
|
||||
.leftJoin(PostsMedia)
|
||||
.leftJoin(PostsEmojis)
|
||||
.select { Posts.actorId eq actorId }.let(postQueryMapper::map)
|
||||
}
|
||||
|
||||
override suspend fun delete(id: Long): Unit = query {
|
||||
|
@ -125,3 +145,9 @@ object PostsMedia : Table("posts_media") {
|
|||
val mediaId = long("media_id").references(Media.id, ReferenceOption.CASCADE, ReferenceOption.CASCADE)
|
||||
override val primaryKey = PrimaryKey(postId, mediaId)
|
||||
}
|
||||
|
||||
object PostsEmojis : Table("posts_emojis") {
|
||||
val postId = long("post_id").references(Posts.id)
|
||||
val emojiId = long("emoji_id").references(Posts.id)
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(postId, emojiId)
|
||||
}
|
||||
|
|
|
@ -117,6 +117,19 @@ alter table posts_media
|
|||
add constraint fk_posts_media_post_id__id foreign key (post_id) references posts (id) on delete cascade on update cascade;
|
||||
alter table posts_media
|
||||
add constraint fk_posts_media_media_id__id foreign key (media_id) references media (id) on delete cascade on update cascade;
|
||||
|
||||
create table if not exists posts_emojis
|
||||
(
|
||||
post_id bigint not null,
|
||||
emoji_id bigint not null,
|
||||
constraint pk_postsemoji primary key (post_id, emoji_id)
|
||||
);
|
||||
|
||||
alter table posts_emojis
|
||||
add constraint fk_posts_emojis_post_id__id foreign key (post_id) references posts (id) on delete cascade on update cascade;
|
||||
alter table posts_emojis
|
||||
add constraint fk_posts_emojis_emoji_id__id foreign key (emoji_id) references emojis (id) on delete cascade on update cascade;
|
||||
|
||||
create table if not exists reactions
|
||||
(
|
||||
id bigserial primary key,
|
||||
|
|
Loading…
Reference in New Issue