feat: add endpoints to get notes
This commit is contained in:
14
server.ts
14
server.ts
@@ -1,4 +1,5 @@
|
||||
import { Application, Router } from "@oak/oak";
|
||||
import { getNotes, getNotesByDid } from "./src/data/db.ts";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
@@ -6,6 +7,19 @@ router.get("/", (ctx) => {
|
||||
ctx.response.body = "Hello world";
|
||||
});
|
||||
|
||||
router.get("/notes", (ctx) => {
|
||||
const cursor = ctx.request.url.searchParams.get("cursor") ?? undefined;
|
||||
const limit = Number(ctx.request.url.searchParams.get("limit")) || 20;
|
||||
ctx.response.body = getNotes(cursor, limit);
|
||||
});
|
||||
|
||||
router.get("/:did/notes", (ctx) => {
|
||||
const { did } = ctx.params;
|
||||
const cursor = ctx.request.url.searchParams.get("cursor") ?? undefined;
|
||||
const limit = Number(ctx.request.url.searchParams.get("limit")) || 20;
|
||||
ctx.response.body = getNotesByDid(did, cursor, limit);
|
||||
});
|
||||
|
||||
const app = new Application();
|
||||
app.use(router.routes());
|
||||
app.use(router.allowedMethods());
|
||||
|
||||
Reference in New Issue
Block a user