Compare commits
2 commits
440008ec64
...
591cd28eb4
Author | SHA1 | Date | |
---|---|---|---|
591cd28eb4 | |||
ae2d98fa1f |
2 changed files with 7 additions and 16 deletions
|
@ -12,11 +12,11 @@ object ProfileRepository {
|
|||
),
|
||||
)
|
||||
|
||||
fun getById(id: UInt): Profile? {
|
||||
fun get(id: UInt): Profile? {
|
||||
return profiles.get(id)
|
||||
}
|
||||
|
||||
fun deleteById(id: UInt): Boolean {
|
||||
fun delete(id: UInt): Boolean {
|
||||
return profiles.remove(id) != null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package su.coolpeople.plugins
|
|||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.plugins.BadRequestException
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import su.coolpeople.model.ProfileRepository
|
||||
import kotlin.text.toUInt
|
||||
|
@ -15,14 +16,9 @@ fun Application.configureRouting() {
|
|||
}
|
||||
|
||||
get("/{id}") {
|
||||
val id = try {
|
||||
call.parameters["id"]!!.toUInt()
|
||||
} catch (ex: kotlin.NumberFormatException) {
|
||||
call.respond(HttpStatusCode.BadRequest)
|
||||
return@get
|
||||
}
|
||||
val id = call.parameters["id"]?.toUIntOrNull() ?: throw BadRequestException("Invalid ID")
|
||||
|
||||
val profile = ProfileRepository.getById(id)
|
||||
val profile = ProfileRepository.get(id)
|
||||
if (profile == null) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
return@get
|
||||
|
@ -32,14 +28,9 @@ fun Application.configureRouting() {
|
|||
}
|
||||
|
||||
delete("/{id}") {
|
||||
val id = try {
|
||||
call.parameters["id"]!!.toUInt()
|
||||
} catch (ex: kotlin.NumberFormatException) {
|
||||
call.respond(HttpStatusCode.BadRequest)
|
||||
return@delete
|
||||
}
|
||||
val id = call.parameters["id"]?.toUIntOrNull() ?: throw BadRequestException("Invalid ID")
|
||||
|
||||
if (!ProfileRepository.deleteById(id)) {
|
||||
if (!ProfileRepository.delete(id)) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
} else {
|
||||
call.respond(HttpStatusCode.OK)
|
||||
|
|
Loading…
Add table
Reference in a new issue