Compare commits

..

No commits in common. "02793fa80637031bf4ebee9309858a112d139203" and "b67cc939b62761fa563aac3fd3a77ad15255dc61" have entirely different histories.

6 changed files with 27 additions and 36 deletions

View File

@ -7,21 +7,15 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.21'
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
apply plugin: 'kotlin'
apply plugin: 'kotlinx-serialization'
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'application'
@ -53,15 +47,13 @@ dependencies {
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
compile 'com.zaxxer:HikariCP:5.0.0'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.2.1"
implementation "io.insert-koin:koin-core:$koin_version"
implementation "io.insert-koin:koin-ktor:$koin_version"
implementation "io.ktor:ktor-serialization:$ktor_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "io.ktor:ktor-server-netty:$ktor_version"
implementation "ch.qos.logback:logback-classic:$logback_version"
implementation "io.ktor:ktor-server-core:$ktor_version"
implementation "io.ktor:ktor-gson:$ktor_version"
implementation "io.ktor:ktor-server-host-common:$ktor_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"

View File

@ -5,11 +5,11 @@ import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.gson.*
import io.ktor.features.*
import org.apache.http.HttpException
import com.kmalbz.database.DatabaseFactory
import com.kmalbz.database.dao.SampleObjects
import io.ktor.serialization.*
import io.ktor.util.*
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
@ -21,7 +21,8 @@ fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@Suppress("unused") // Referenced in application.conf
fun Application.module() {
install(ContentNegotiation) {
json()
gson {
}
}
install(Koin) {

View File

@ -1,11 +1,10 @@
package com.kmalbz.api.model
import kotlinx.datetime.LocalDateTime
import kotlinx.serialization.Serializable
import com.google.gson.annotations.SerializedName
import java.time.LocalDate
@Serializable
data class ApiObject(
val tag: String,
val device_id: Int,
val device_date: LocalDateTime
@SerializedName("tag") val tag: String,
@SerializedName("device_id") val device_id: Int,
@SerializedName("device_date") val device_date: LocalDate
)

View File

@ -2,13 +2,13 @@ package com.kmalbz.database.dao
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.`java-time`.datetime
import java.time.LocalDateTime
import org.jetbrains.exposed.sql.`java-time`.date
import java.time.LocalDate
object SampleObjects : IntIdTable() {
val tag: Column<String> = varchar("tag", 32)
val timestamp: Column<LocalDateTime> = datetime("timestamp").default(LocalDateTime.now())
val timestamp: Column<LocalDate> = date("timestamp").default(LocalDate.now())
val device_id: Column<Int> = integer("device_id")
val device_date: Column<LocalDateTime> = datetime("device_date")
val device_date: Column<LocalDate> = date("device_date")
override val primaryKey = PrimaryKey(id, name = "PK_SampleObject_Id")
}

View File

@ -1,7 +1,8 @@
package com.kmalbz.database.service
import com.kmalbz.api.model.ApiObject
import kotlinx.datetime.LocalDateTime
import java.time.LocalDate
import java.util.*
interface ISampleObjectService{
fun addOne(apiObject: ApiObject)
@ -10,7 +11,7 @@ interface ISampleObjectService{
suspend fun getPage(page: Long): List<ApiObject>
suspend fun getSampleObjectbyDeviceID(device_id: Int): List<ApiObject>
suspend fun getSampleObjectbyTag(tag: String): ApiObject?
suspend fun getSampleObjectbyDate(date: LocalDateTime): List<ApiObject>
suspend fun getSampleObjectbeforeDate(date: LocalDateTime): List<ApiObject>
suspend fun getSampleObjectafterDate(date: LocalDateTime): List<ApiObject>
suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject>
suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject>
suspend fun getSampleObjectafterDate(date: LocalDate): List<ApiObject>
}

View File

@ -5,13 +5,11 @@ import com.kmalbz.database.model.SampleObject
import com.kmalbz.database.dao.SampleObjects
import com.kmalbz.api.model.ApiObject
import io.ktor.util.*
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.toJavaLocalDateTime
import kotlinx.datetime.toKotlinLocalDateTime
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import java.time.LocalDate
@KtorExperimentalAPI
@ -21,7 +19,7 @@ class SampleObjectService : ISampleObjectService {
transaction {
SampleObject.new {
tag = apiObject.tag
device_date = apiObject.device_date.toJavaLocalDateTime()
device_date = apiObject.device_date
device_id = apiObject.device_id
}
}
@ -52,28 +50,28 @@ class SampleObjectService : ISampleObjectService {
.singleOrNull()
}
override suspend fun getSampleObjectbyDate(date: LocalDateTime): List<ApiObject> = dbQuery {
override suspend fun getSampleObjectbyDate(date: LocalDate): List<ApiObject> = dbQuery {
SampleObjects.select {
(SampleObjects.timestamp eq date.toJavaLocalDateTime())
(SampleObjects.timestamp eq date)
}.mapNotNull { toSampleObject(it) }
}
override suspend fun getSampleObjectbeforeDate(date: LocalDateTime): List<ApiObject> = dbQuery {
override suspend fun getSampleObjectbeforeDate(date: LocalDate): List<ApiObject> = dbQuery {
SampleObjects.select {
(SampleObjects.timestamp less date.toJavaLocalDateTime())
(SampleObjects.timestamp less date)
}.mapNotNull { toSampleObject(it) }
}
override suspend fun getSampleObjectafterDate(date: LocalDateTime): List<ApiObject> = dbQuery {
override suspend fun getSampleObjectafterDate(date: LocalDate): List<ApiObject> = dbQuery {
SampleObjects.select {
(SampleObjects.timestamp greater date.toJavaLocalDateTime())
(SampleObjects.timestamp greater date)
}.mapNotNull { toSampleObject(it) }
}
private fun toSampleObject(row: ResultRow): ApiObject =
ApiObject(
tag = row[SampleObjects.tag],
device_date = row[SampleObjects.device_date].toKotlinLocalDateTime(),
device_date = row[SampleObjects.device_date],
device_id = row[SampleObjects.device_id]
)
}