Compare commits
No commits in common. "440008ec6438d8a3abddf38acf34a13039a12acf" and "ff4a2746f2ad767c5ee24aba60d7e7c08b9cf524" have entirely different histories.
440008ec64
...
ff4a2746f2
4 changed files with 3 additions and 81 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -4,8 +4,6 @@ build/
|
||||||
!**/src/main/**/build/
|
!**/src/main/**/build/
|
||||||
!**/src/test/**/build/
|
!**/src/test/**/build/
|
||||||
|
|
||||||
.kotlin/
|
|
||||||
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
.classpath
|
.classpath
|
||||||
|
@ -35,4 +33,4 @@ out/
|
||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
|
@ -1,17 +0,0 @@
|
||||||
package su.coolpeople.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
// https://wiki.dc09.ru/doku.php?id=wiki:coolpeople:dev:backend#анкета
|
|
||||||
@Serializable
|
|
||||||
data class Profile(
|
|
||||||
val name: String,
|
|
||||||
val age: UInt,
|
|
||||||
val lat: Float,
|
|
||||||
val lon: Float,
|
|
||||||
val city: String,
|
|
||||||
val approx_loc: Boolean,
|
|
||||||
val desc: String,
|
|
||||||
val tags: Array<String>, // TODO: maybe MutableList<String>
|
|
||||||
val contacts: Array<String>, // TODO: same
|
|
||||||
)
|
|
|
@ -1,22 +0,0 @@
|
||||||
package su.coolpeople.model
|
|
||||||
|
|
||||||
object ProfileRepository {
|
|
||||||
// TODO: Meilisearch
|
|
||||||
private val profiles = hashMapOf(
|
|
||||||
0u to Profile(
|
|
||||||
"name", 20u,
|
|
||||||
60f, 49f, "city", true,
|
|
||||||
"description",
|
|
||||||
arrayOf("programming", "music"),
|
|
||||||
arrayOf("t.me/example"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
fun getById(id: UInt): Profile? {
|
|
||||||
return profiles.get(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteById(id: UInt): Boolean {
|
|
||||||
return profiles.remove(id) != null
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,48 +3,11 @@ package su.coolpeople.plugins
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
import io.ktor.http.HttpStatusCode
|
|
||||||
import su.coolpeople.model.ProfileRepository
|
|
||||||
import kotlin.text.toUInt
|
|
||||||
|
|
||||||
fun Application.configureRouting() {
|
fun Application.configureRouting() {
|
||||||
routing {
|
routing {
|
||||||
route("/api/profile") {
|
get("/") {
|
||||||
put {
|
call.respondText("Hello World!")
|
||||||
TODO()
|
|
||||||
}
|
|
||||||
|
|
||||||
get("/{id}") {
|
|
||||||
val id = try {
|
|
||||||
call.parameters["id"]!!.toUInt()
|
|
||||||
} catch (ex: kotlin.NumberFormatException) {
|
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
val profile = ProfileRepository.getById(id)
|
|
||||||
if (profile == null) {
|
|
||||||
call.respond(HttpStatusCode.NotFound)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
call.respond(profile)
|
|
||||||
}
|
|
||||||
|
|
||||||
delete("/{id}") {
|
|
||||||
val id = try {
|
|
||||||
call.parameters["id"]!!.toUInt()
|
|
||||||
} catch (ex: kotlin.NumberFormatException) {
|
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
|
||||||
return@delete
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ProfileRepository.deleteById(id)) {
|
|
||||||
call.respond(HttpStatusCode.NotFound)
|
|
||||||
} else {
|
|
||||||
call.respond(HttpStatusCode.OK)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue