Skip to content

Commit 5478c6b

Browse files
authored
Merge pull request #21 from bullet-true/KTB-25-database-migration
KTB-25 migrate to database
2 parents 9f532af + fb8ecab commit 5478c6b

24 files changed

+669
-276
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ repositories {
1515
dependencies {
1616
testImplementation(kotlin("test"))
1717
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
18+
implementation("org.xerial:sqlite-jdbc:3.50.3.0")
1819
}
1920

2021
tasks.test {
@@ -25,5 +26,5 @@ kotlin {
2526
}
2627

2728
application {
28-
mainClass.set("org.example.TelegramKt")
29+
mainClass.set("ru.ifedorov.telegrambot.telegram.TelegramKt")
2930
}

src/main/kotlin/LearnWordsTrainer.kt

Lines changed: 0 additions & 116 deletions
This file was deleted.

src/main/kotlin/Telegram.kt

Lines changed: 0 additions & 127 deletions
This file was deleted.

src/main/kotlin/Main.kt renamed to src/main/kotlin/ru/ifedorov/telegrambot/console/Main.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
package org.example
1+
package ru.ifedorov.telegrambot.console
2+
3+
import ru.ifedorov.telegrambot.data.db.DatabaseConnection
4+
import ru.ifedorov.telegrambot.data.db.DatabaseUserDictionary
5+
import ru.ifedorov.telegrambot.trainer.LearnWordsTrainer
26

37
fun main() {
8+
val chatId = 0L
9+
10+
Runtime.getRuntime().addShutdownHook(Thread {
11+
DatabaseConnection.close()
12+
})
413

514
val trainer = try {
6-
LearnWordsTrainer()
15+
LearnWordsTrainer(DatabaseUserDictionary(chatId))
716
} catch (e: Exception) {
8-
println("Невозможно загрузить словарь. $e")
17+
println("Невозможно подключиться к БД. $e")
918
return
1019
}
1120

1221
while (true) {
1322
println(
1423
"""
15-
Меню:
16-
1 – Учить слова
17-
2 – Статистика
18-
0 – Выход
19-
""".trimIndent()
24+
Меню:
25+
1 – Учить слова
26+
2 – Статистика
27+
0 – Выход
28+
""".trimIndent()
2029
)
2130

2231
when (readln().toIntOrNull()) {
@@ -50,11 +59,4 @@ fun main() {
5059
else -> println("Введите число 1, 2 или 0")
5160
}
5261
}
53-
}
54-
55-
fun Question.asConsoleString(): String {
56-
val variants = this.variants
57-
.mapIndexed { index, word -> " ${index + 1} - ${word.translate}" }
58-
.joinToString(separator = "\n")
59-
return "\n" + this.correctAnswer.original + ":" + "\n" + variants + "\n ---------- \n 0 - Меню"
6062
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.ifedorov.telegrambot.console
2+
3+
import ru.ifedorov.telegrambot.trainer.model.Question
4+
5+
fun Question.asConsoleString(): String =
6+
this.variants
7+
.mapIndexed { index, word -> " ${index + 1} - ${word.translate}" }
8+
.joinToString(
9+
prefix = "\n ${correctAnswer.original}:\n",
10+
separator = "\n",
11+
postfix = "\n ---------- \n 0 - Меню"
12+
)

0 commit comments

Comments
 (0)