mirror of https://github.com/usbharu/Hideout.git
fix: リアクション受信時の重複検査を修正
This commit is contained in:
parent
bed0b84d16
commit
458a1d7717
|
@ -1,5 +1,6 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.reaction
|
package dev.usbharu.hideout.core.domain.model.reaction
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.emoji.Emoji
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@ -13,5 +14,7 @@ interface ReactionRepository {
|
||||||
suspend fun findByPostId(postId: Long): List<Reaction>
|
suspend fun findByPostId(postId: Long): List<Reaction>
|
||||||
suspend fun findByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Reaction?
|
suspend fun findByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Reaction?
|
||||||
suspend fun existByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Boolean
|
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<Reaction>
|
suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List<Reaction>
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.service.id.IdGenerateService
|
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.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.emoji.UnicodeEmoji
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
||||||
|
@ -103,6 +104,37 @@ class ReactionRepositoryImpl(
|
||||||
}.empty().not()
|
}.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<Reaction> = query {
|
override suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List<Reaction> = query {
|
||||||
return@query Reactions.leftJoin(CustomEmojis)
|
return@query Reactions.leftJoin(CustomEmojis)
|
||||||
.select { Reactions.postId eq postId and (Reactions.actorId eq actorId) }
|
.select { Reactions.postId eq postId and (Reactions.actorId eq actorId) }
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ReactionServiceImpl(
|
||||||
actorId: Long,
|
actorId: Long,
|
||||||
postId: Long
|
postId: Long
|
||||||
) {
|
) {
|
||||||
if (reactionRepository.existByPostIdAndActorIdAndEmojiId(postId, actorId, 0).not()) {
|
if (reactionRepository.existByPostIdAndActorIdAndEmoji(postId, actorId, emoji).not()) {
|
||||||
try {
|
try {
|
||||||
reactionRepository.save(
|
reactionRepository.save(
|
||||||
Reaction(reactionRepository.generateId(), emoji, postId, actorId)
|
Reaction(reactionRepository.generateId(), emoji, postId, actorId)
|
||||||
|
|
Loading…
Reference in New Issue