|
@@ -1,13 +1,44 @@
|
|
|
import { Hono } from "hono"
|
|
import { Hono } from "hono"
|
|
|
-
|
|
|
|
|
|
|
+import { getDB } from "../database"
|
|
|
const route = new Hono<Environment>()
|
|
const route = new Hono<Environment>()
|
|
|
|
|
|
|
|
-route.get("/", c => {
|
|
|
|
|
- return c.text("Hello User!")
|
|
|
|
|
|
|
+route.get("/:id", async c => {
|
|
|
|
|
+ const db = getDB(c)
|
|
|
|
|
+ return c.json(
|
|
|
|
|
+ await db
|
|
|
|
|
+ .selectFrom("user")
|
|
|
|
|
+ .where("id", "=", Number(c.req.param("id")))
|
|
|
|
|
+ .selectAll()
|
|
|
|
|
+ .executeTakeFirstOrThrow()
|
|
|
|
|
+ )
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+route.patch("/:id", async c => {
|
|
|
|
|
+ const db = getDB(c)
|
|
|
|
|
+ const body = await c.req.json()
|
|
|
|
|
+ await db
|
|
|
|
|
+ .updateTable("user")
|
|
|
|
|
+ .set(body)
|
|
|
|
|
+ .where("id", "=", Number(c.req.param("id")))
|
|
|
|
|
+ .executeTakeFirstOrThrow()
|
|
|
|
|
+ return c.text("")
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+route.get("/", async c => {
|
|
|
|
|
+ const db = getDB(c)
|
|
|
|
|
+ return c.json(await db.selectFrom("user").selectAll().execute())
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-route.post("/", c => {
|
|
|
|
|
- return c.text("User created!")
|
|
|
|
|
|
|
+route.post("/", async c => {
|
|
|
|
|
+ const db = getDB(c)
|
|
|
|
|
+ const user = await db
|
|
|
|
|
+ .insertInto("user")
|
|
|
|
|
+ .values({
|
|
|
|
|
+ name: "John Doe"
|
|
|
|
|
+ })
|
|
|
|
|
+ .returningAll()
|
|
|
|
|
+ .executeTakeFirstOrThrow()
|
|
|
|
|
+ return c.json(user)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
export default route
|
|
export default route
|