add update command.

This commit is contained in:
dalbodeule
2024-06-12 23:12:59 +09:00
parent 02d12e74b5
commit 2d28bf8bcb
5 changed files with 78 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package space.mori.chzzk_bot.services
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import space.mori.chzzk_bot.models.Command
import space.mori.chzzk_bot.models.Commands
import space.mori.chzzk_bot.models.User
@@ -29,6 +30,18 @@ object CommandService {
}
}
fun updateCommand(user: User, command: String, content: String): Command {
return transaction {
val updated = Commands.update({Commands.user eq user.id and(Commands.command eq command)}) {
it[Commands.content] = content
}
if(updated == 0) throw RuntimeException("Command not found! $command")
return@transaction Command.find(Commands.user eq user.id and(Commands.command eq command)).first()
}
}
fun getCommand(id: Int): Command? {
return transaction {
return@transaction Command.findById(id)