From 458a1d771753de5dde8466aba90531cfa2f13f08 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:35:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=83=AA=E3=82=A2=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E5=8F=97=E4=BF=A1=E6=99=82=E3=81=AE=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E6=A4=9C=E6=9F=BB=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/reaction/ReactionRepository.kt | 3 ++ .../ReactionRepositoryImpl.kt | 32 +++++++++++++++++++ .../service/reaction/ReactionServiceImpl.kt | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt index 0b6183b5..8005bbd2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.domain.model.reaction +import dev.usbharu.hideout.core.domain.model.emoji.Emoji import org.springframework.stereotype.Repository @Repository @@ -13,5 +14,7 @@ interface ReactionRepository { suspend fun findByPostId(postId: Long): List suspend fun findByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Reaction? suspend fun existByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Boolean + suspend fun existByPostIdAndActorIdAndUnicodeEmoji(postId: Long, actorId: Long, unicodeEmoji: String): Boolean + suspend fun existByPostIdAndActorIdAndEmoji(postId: Long, actorId: Long, emoji: Emoji): Boolean suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt index 2c4274b7..6847ab14 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt @@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository import dev.usbharu.hideout.application.service.id.IdGenerateService import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji +import dev.usbharu.hideout.core.domain.model.emoji.Emoji import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji import dev.usbharu.hideout.core.domain.model.reaction.Reaction import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository @@ -103,6 +104,37 @@ class ReactionRepositoryImpl( }.empty().not() } + override suspend fun existByPostIdAndActorIdAndUnicodeEmoji( + postId: Long, + actorId: Long, + unicodeEmoji: String + ): Boolean = query { + return@query Reactions.select { + Reactions.postId + .eq(postId) + .and(Reactions.actorId.eq(actorId)) + .and(Reactions.unicodeEmoji.eq(unicodeEmoji)) + }.empty().not() + } + + override suspend fun existByPostIdAndActorIdAndEmoji(postId: Long, actorId: Long, emoji: Emoji): Boolean = query { + val query = Reactions.select { + Reactions.postId + .eq(postId) + .and(Reactions.actorId.eq(actorId)) + } + + + if (emoji is UnicodeEmoji) { + query.andWhere { Reactions.unicodeEmoji eq emoji.name } + } else { + emoji as CustomEmoji + query.andWhere { Reactions.customEmojiId eq emoji.id } + } + + return@query query.empty().not() + } + override suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List = query { return@query Reactions.leftJoin(CustomEmojis) .select { Reactions.postId eq postId and (Reactions.actorId eq actorId) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt index daf38ca3..0d623846 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt @@ -19,7 +19,7 @@ class ReactionServiceImpl( actorId: Long, postId: Long ) { - if (reactionRepository.existByPostIdAndActorIdAndEmojiId(postId, actorId, 0).not()) { + if (reactionRepository.existByPostIdAndActorIdAndEmoji(postId, actorId, emoji).not()) { try { reactionRepository.save( Reaction(reactionRepository.generateId(), emoji, postId, actorId)