code dump
This commit is contained in:
parent
562fef9d92
commit
f61adb428d
@ -1,24 +1,25 @@
|
|||||||
package com.wyattjmiller.entities
|
package com.wyattjmiller.entities
|
||||||
|
|
||||||
import com.wyattjmiller.data.Authors
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("Recipe")
|
@SerialName("Recipe")
|
||||||
data class Recipe(
|
data class Recipe(
|
||||||
val id: Int?,
|
val id: Int?,
|
||||||
val name: String,
|
val name: String,
|
||||||
val desc: String,
|
val desc: String,
|
||||||
val ingredients: String,
|
val ingredients: String,
|
||||||
var createdTimestamp: String,
|
var createdTimestamp: String,
|
||||||
val author: Int,
|
val author: Int,
|
||||||
|
val deletedTimestamp: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("RecipeDraft")
|
@SerialName("RecipeDraft")
|
||||||
data class RecipeDraft(
|
data class RecipeDraft(
|
||||||
val name: String,
|
val name: String,
|
||||||
val desc: String,
|
val desc: String,
|
||||||
val ingredients: String,
|
val ingredients: String,
|
||||||
val author: Int,
|
val author: Int,
|
||||||
)
|
)
|
||||||
|
@ -13,20 +13,24 @@ class AuthorRoute {
|
|||||||
private val author = AuthorDao()
|
private val author = AuthorDao()
|
||||||
|
|
||||||
private fun Route.getAllAuthors() {
|
private fun Route.getAllAuthors() {
|
||||||
get("/author") {
|
get("/author") { call.respond(author.getAllAuthors()) }
|
||||||
call.respond(author.getAllAuthors())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Route.getAuthor() {
|
private fun Route.getAuthor() {
|
||||||
get("/author/{id?}") {
|
get("/author/{id?}") {
|
||||||
val id = call.parameters["id"]?.toInt() ?: return@get call.respond(
|
val id =
|
||||||
HttpStatusCode.BadRequest, "Missing author identifier :("
|
call.parameters["id"]?.toInt()
|
||||||
)
|
?: return@get call.respond(
|
||||||
|
HttpStatusCode.BadRequest,
|
||||||
|
"Missing author identifier :("
|
||||||
|
)
|
||||||
|
|
||||||
val res = author.getAuthor(id) ?: return@get call.respond(
|
val res =
|
||||||
HttpStatusCode.NotFound, "No recipe found :("
|
author.getAuthor(id)
|
||||||
)
|
?: return@get call.respond(
|
||||||
|
HttpStatusCode.NotFound,
|
||||||
|
"No recipe found :("
|
||||||
|
)
|
||||||
|
|
||||||
call.respond(res)
|
call.respond(res)
|
||||||
}
|
}
|
||||||
@ -35,7 +39,7 @@ class AuthorRoute {
|
|||||||
private fun Route.createAuthor() {
|
private fun Route.createAuthor() {
|
||||||
post("/author") {
|
post("/author") {
|
||||||
val req = call.receive<AuthorDraft>()
|
val req = call.receive<AuthorDraft>()
|
||||||
val res = author.createAuthor(req)
|
val _res = author.createAuthor(req)
|
||||||
call.respond(HttpStatusCode.Created)
|
call.respond(HttpStatusCode.Created)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,16 +47,17 @@ class AuthorRoute {
|
|||||||
private fun Route.updateAuthor() {
|
private fun Route.updateAuthor() {
|
||||||
put("/author/{id?}") {
|
put("/author/{id?}") {
|
||||||
val req = call.receive<AuthorDraft>()
|
val req = call.receive<AuthorDraft>()
|
||||||
val id = call.parameters["id"]?.toIntOrNull() ?: return@put call.respond(
|
val id =
|
||||||
HttpStatusCode.BadRequest, "Missing author identifier :("
|
call.parameters["id"]?.toIntOrNull()
|
||||||
)
|
?: return@put call.respond(
|
||||||
|
HttpStatusCode.BadRequest,
|
||||||
|
"Missing author identifier :("
|
||||||
|
)
|
||||||
|
|
||||||
if (author.updateAuthor(id, req)) {
|
if (author.updateAuthor(id, req)) {
|
||||||
call.respond(HttpStatusCode.Created)
|
call.respond(HttpStatusCode.Created)
|
||||||
} else {
|
} else {
|
||||||
call.respond(
|
call.respond(HttpStatusCode.NotFound, "No author found :(")
|
||||||
HttpStatusCode.NotFound, "No author found :("
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,4 +71,5 @@ class AuthorRoute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user