code dump

This commit is contained in:
Wyatt J. Miller 2023-11-13 07:30:43 -05:00
parent 562fef9d92
commit f61adb428d
2 changed files with 35 additions and 28 deletions

View File

@ -1,24 +1,25 @@
package com.wyattjmiller.entities
import com.wyattjmiller.data.Authors
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
@SerialName("Recipe")
data class Recipe(
val id: Int?,
val name: String,
val desc: String,
val ingredients: String,
var createdTimestamp: String,
val author: Int,
val id: Int?,
val name: String,
val desc: String,
val ingredients: String,
var createdTimestamp: String,
val author: Int,
val deletedTimestamp: String,
)
@Serializable
@SerialName("RecipeDraft")
data class RecipeDraft(
val name: String,
val desc: String,
val ingredients: String,
val author: Int,
val name: String,
val desc: String,
val ingredients: String,
val author: Int,
)

View File

@ -13,20 +13,24 @@ class AuthorRoute {
private val author = AuthorDao()
private fun Route.getAllAuthors() {
get("/author") {
call.respond(author.getAllAuthors())
}
get("/author") { call.respond(author.getAllAuthors()) }
}
private fun Route.getAuthor() {
get("/author/{id?}") {
val id = call.parameters["id"]?.toInt() ?: return@get call.respond(
HttpStatusCode.BadRequest, "Missing author identifier :("
)
val id =
call.parameters["id"]?.toInt()
?: return@get call.respond(
HttpStatusCode.BadRequest,
"Missing author identifier :("
)
val res = author.getAuthor(id) ?: return@get call.respond(
HttpStatusCode.NotFound, "No recipe found :("
)
val res =
author.getAuthor(id)
?: return@get call.respond(
HttpStatusCode.NotFound,
"No recipe found :("
)
call.respond(res)
}
@ -35,7 +39,7 @@ class AuthorRoute {
private fun Route.createAuthor() {
post("/author") {
val req = call.receive<AuthorDraft>()
val res = author.createAuthor(req)
val _res = author.createAuthor(req)
call.respond(HttpStatusCode.Created)
}
}
@ -43,16 +47,17 @@ class AuthorRoute {
private fun Route.updateAuthor() {
put("/author/{id?}") {
val req = call.receive<AuthorDraft>()
val id = call.parameters["id"]?.toIntOrNull() ?: return@put call.respond(
HttpStatusCode.BadRequest, "Missing author identifier :("
)
val id =
call.parameters["id"]?.toIntOrNull()
?: return@put call.respond(
HttpStatusCode.BadRequest,
"Missing author identifier :("
)
if (author.updateAuthor(id, req)) {
call.respond(HttpStatusCode.Created)
} else {
call.respond(
HttpStatusCode.NotFound, "No author found :("
)
call.respond(HttpStatusCode.NotFound, "No author found :(")
}
}
}
@ -67,3 +72,4 @@ class AuthorRoute {
}
}
}