Skip to content

Commit 0425795

Browse files
committed
refactor: Change to refer directly to redis QUZ-109
1 parent 10ac859 commit 0425795

File tree

2 files changed

+24
-2
lines changed
  • game-service

2 files changed

+24
-2
lines changed

game-service/game-domain/src/main/kotlin/com/grepp/quizy/game/domain/game/GameVO.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ data class Players(
164164
if (players.size >= 5) {
165165
throw GameException.GameAlreadyFullException
166166
}
167-
if (players.contains(player)) {
167+
if (players.any { it.user.id == player.user.id }) {
168168
throw GameException.GameAlreadyParticipatedException
169169
}
170170
return Players(players + player)

game-service/game-infra/src/main/kotlin/com/grepp/quizy/game/infra/game/repository/GameRepositoryAdapter.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ package com.grepp.quizy.game.infra.game.repository
33
import com.grepp.quizy.game.domain.game.Game
44
import com.grepp.quizy.game.domain.game.GameRepository
55
import com.grepp.quizy.game.infra.game.entity.GameRedisEntity
6+
import org.springframework.data.redis.core.RedisTemplate
7+
import org.springframework.data.redis.core.ScanOptions
68
import org.springframework.data.repository.findByIdOrNull
79
import org.springframework.stereotype.Repository
810

911
@Repository
1012
class GameRepositoryAdapter(
1113
private val gameRedisRepository: GameRedisRepository,
14+
private val redisTemplate: RedisTemplate<String,String>
1215
) : GameRepository {
1316

1417
override fun save(game: Game): Game {
@@ -22,7 +25,26 @@ class GameRepositoryAdapter(
2225
}
2326

2427
override fun findByInviteCode(code: String): Game? {
25-
return gameRedisRepository.findTopByInviteCode(code)?.toDomain()
28+
val scanner = redisTemplate.connectionFactory
29+
.connection
30+
.scan(
31+
ScanOptions.scanOptions()
32+
.match("game:*")
33+
.count(100)
34+
.build())
35+
36+
while(scanner.hasNext()) {
37+
val key = String(scanner.next())
38+
val inviteCode = redisTemplate.opsForHash<String, String>()
39+
.get(key, "inviteCode")
40+
41+
if(inviteCode == code) {
42+
return gameRedisRepository.findByIdOrNull(key.split(":")[1].toLong())
43+
?.toDomain()
44+
}
45+
}
46+
return null
47+
2648
}
2749

2850
}

0 commit comments

Comments
 (0)