diff --git a/src/main/kotlin/Stores/TeamStore.kt b/src/main/kotlin/Stores/TeamStore.kt new file mode 100644 index 0000000..376f446 --- /dev/null +++ b/src/main/kotlin/Stores/TeamStore.kt @@ -0,0 +1,32 @@ +package Stores + +import io.ktor.http.Parameters +import models.Team +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.insert +import org.jetbrains.exposed.sql.select +import org.joda.time.DateTime +import java.util.* + +object TeamStore { + suspend fun createChannel(params: Parameters): String? { + val uuid = UUID.randomUUID().toString() + DatabaseFactory.dbQuery { + Team.insert { + it[name] = params["name"]!! + it[id] = uuid + it[createdAt] = DateTime.now() + it[updateAt] = DateTime.now() + } + } + return getTeam(uuid) + } + + suspend fun getTeam(uuid: String?): String? { + return DatabaseFactory.dbQuery { + Team.select { + Team.id.eq(uuid!!) + }.takeIf { !it.empty() }?.map { it[Team.id] }?.get(0) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/models/Team.kt b/src/main/kotlin/models/Team.kt new file mode 100644 index 0000000..8c82cec --- /dev/null +++ b/src/main/kotlin/models/Team.kt @@ -0,0 +1,11 @@ +package models + +import org.jetbrains.exposed.sql.Table + +object Team : Table() { + val id = varchar("id", 36).primaryKey() + val createdAt = Channel.date("createdAt") + val updateAt = Channel.date("updateAt") + + val name = varchar("name", 30) +} \ No newline at end of file