Skip to content

Commit 5878cc7

Browse files
committed
Model for dialogs state
1 parent 5139d2f commit 5878cc7

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44

55
plugins {
66
kotlin("jvm").version("1.4.32").apply(false)
7+
kotlin("plugin.serialization").version("1.4.32").apply(false)
78
id("com.github.johnrengelman.shadow").version("6.1.0").apply(false)
89
}
910

dialogs/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plugins {
2+
kotlin("jvm")
3+
kotlin("plugin.serialization")
4+
}
5+
6+
dependencies {
7+
implementation(libs.kotlinx.serialization.core)
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package by.jprof.telegram.bot.dialogs.dao
2+
3+
import by.jprof.telegram.bot.dialogs.model.DialogState
4+
5+
interface DialogStateDAO {
6+
suspend fun get(chatId: Long, userId: Long): DialogState?
7+
8+
suspend fun save(entity: DialogState)
9+
10+
suspend fun delete(chatId: Long, userId: Long)
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package by.jprof.telegram.bot.dialogs.model
2+
3+
import by.jprof.telegram.bot.dialogs.model.quizoji.WaitingForQuestion
4+
import kotlinx.serialization.modules.SerializersModule
5+
import kotlinx.serialization.modules.polymorphic
6+
import kotlinx.serialization.modules.subclass
7+
8+
interface DialogState {
9+
companion object {
10+
val serializers = SerializersModule {
11+
polymorphic(DialogState::class) {
12+
subclass(WaitingForQuestion::class)
13+
}
14+
}
15+
}
16+
17+
val chatId: Long
18+
19+
val userId: Long
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package by.jprof.telegram.bot.dialogs.model.quizoji
2+
3+
import by.jprof.telegram.bot.dialogs.model.DialogState
4+
import kotlinx.serialization.SerialName
5+
import kotlinx.serialization.Serializable
6+
7+
@Serializable
8+
@SerialName("WaitingForQuestion")
9+
data class WaitingForQuestion(
10+
override val chatId: Long,
11+
override val userId: Long
12+
) : DialogState

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ awssdk = "2.16.43"
88

99
koin = "3.0.1"
1010

11+
kotlinx-serialization = "1.2.1"
1112
jackson = "2.12.3"
1213

1314
tgbotapi = "0.33.3"
@@ -34,6 +35,7 @@ dynamodb = { group = "software.amazon.awssdk", name = "dynamodb", version.ref =
3435

3536
koin-core = { group = "io.insert-koin", name = "koin-core", version.ref = "koin" }
3637

38+
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
3739
jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jackson" }
3840

3941
tgbotapi-core = { group = "dev.inmo", name = "tgbotapi.core", version.ref = "tgbotapi" }

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ include(":votes")
99
include(":votes:dynamodb")
1010
include(":votes:tgbotapi-extensions")
1111
include(":votes:voting-processor")
12+
include(":dialogs")
1213
include(":core")
1314
include(":jep")
1415
include(":youtube")

0 commit comments

Comments
 (0)