From 6444b84af4c382e211747500647b1bbd4fca6f35 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Fri, 10 Apr 2026 01:20:53 -0400 Subject: [PATCH] stub out get endpoints, built list endpoint --- .bruno/Plan Endpoints/create plan.bru | 2 +- .bruno/Plan Endpoints/delete plan.bru | 2 +- .bruno/Plan Endpoints/list plans.bru | 16 ++++++++++++++ .bruno/Plan Endpoints/move plan.bru | 2 +- .bruno/Plan Endpoints/rename plan.bru | 2 +- .bruno/Plan Endpoints/update plan.bru | 2 +- mod.ts | 32 +++++++++++++++++++++++---- 7 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 .bruno/Plan Endpoints/list plans.bru diff --git a/.bruno/Plan Endpoints/create plan.bru b/.bruno/Plan Endpoints/create plan.bru index 65bb189..35ac6ea 100644 --- a/.bruno/Plan Endpoints/create plan.bru +++ b/.bruno/Plan Endpoints/create plan.bru @@ -1,7 +1,7 @@ meta { name: create plan type: http - seq: 1 + seq: 2 } post { diff --git a/.bruno/Plan Endpoints/delete plan.bru b/.bruno/Plan Endpoints/delete plan.bru index 6420739..498d6e4 100644 --- a/.bruno/Plan Endpoints/delete plan.bru +++ b/.bruno/Plan Endpoints/delete plan.bru @@ -1,7 +1,7 @@ meta { name: delete plan type: http - seq: 5 + seq: 7 } delete { diff --git a/.bruno/Plan Endpoints/list plans.bru b/.bruno/Plan Endpoints/list plans.bru new file mode 100644 index 0000000..0cb0d7d --- /dev/null +++ b/.bruno/Plan Endpoints/list plans.bru @@ -0,0 +1,16 @@ +meta { + name: list plans + type: http + seq: 1 +} + +get { + url: http://localhost:14014/api/list/[userId] + body: none + auth: inherit +} + +settings { + encodeUrl: true + timeout: 0 +} diff --git a/.bruno/Plan Endpoints/move plan.bru b/.bruno/Plan Endpoints/move plan.bru index 25dbe06..c36b17a 100644 --- a/.bruno/Plan Endpoints/move plan.bru +++ b/.bruno/Plan Endpoints/move plan.bru @@ -1,7 +1,7 @@ meta { name: move plan type: http - seq: 4 + seq: 5 } put { diff --git a/.bruno/Plan Endpoints/rename plan.bru b/.bruno/Plan Endpoints/rename plan.bru index 81a84c4..43f7d28 100644 --- a/.bruno/Plan Endpoints/rename plan.bru +++ b/.bruno/Plan Endpoints/rename plan.bru @@ -1,7 +1,7 @@ meta { name: rename plan type: http - seq: 3 + seq: 4 } put { diff --git a/.bruno/Plan Endpoints/update plan.bru b/.bruno/Plan Endpoints/update plan.bru index 886dc0d..2b975fb 100644 --- a/.bruno/Plan Endpoints/update plan.bru +++ b/.bruno/Plan Endpoints/update plan.bru @@ -1,7 +1,7 @@ meta { name: update plan type: http - seq: 2 + seq: 3 } put { diff --git a/mod.ts b/mod.ts index 6d5909e..0b236d3 100644 --- a/mod.ts +++ b/mod.ts @@ -16,8 +16,8 @@ discordHeaders.append('Accept', 'application/json'); const zohoHeaders = new Headers(discordHeaders); let zohoAuthExpireDT = new Date().getTime(); -const genericResponse = (status: StatusCode, customText = '') => - new Response(customText || STATUS_TEXT[status], { status: status, statusText: STATUS_TEXT[status] }); +const genericResponse = (status: StatusCode, customText = '', customHeaders = new Headers()) => + new Response(customText || STATUS_TEXT[status], { status: status, statusText: STATUS_TEXT[status], headers: customHeaders }); Deno.serve({ port: config.api.port }, async (req) => { try { @@ -29,7 +29,31 @@ Deno.serve({ port: config.api.port }, async (req) => { let failed = false; if (req.method === 'GET') { - // handle all gets + if (path === '/home') { + // SSR "login page" + return genericResponse(STATUS_CODE.Unauthorized, 'Please sign in.'); + } else if (path.startsWith('/home/')) { + // SSR "home page" + return genericResponse(STATUS_CODE.NotImplemented, 'WIP'); + } else if (path.startsWith('/read/')) { + return genericResponse(STATUS_CODE.NotImplemented, 'WIP'); + } else if (path.startsWith('/list/')) { + const userId = path.replace('/list/', ''); + const userMatch = await dbClient.query('SELECT id FROM users WHERE id = ?', [userId]).catch(() => { + failed = true; + }); + if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB."); + if (!userMatch.length) return genericResponse(STATUS_CODE.NotFound, 'User ID does not exist.'); + + const plans = await dbClient.query('SELECT id, name, folder FROM plans WHERE ownerId = ?', [userId]).catch(() => { + failed = true; + }); + if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB."); + + return genericResponse(STATUS_CODE.OK, JSON.stringify(plans)); + } else if (path.startsWith('/export/')) { + return genericResponse(STATUS_CODE.NotImplemented, 'WIP'); + } } else if (req.method === 'POST' && path === '/enroll') { const body = await req.json(); @@ -42,7 +66,7 @@ Deno.serve({ port: config.api.port }, async (req) => { if (body.name.length < 4 || body.name.length > 20) return genericResponse(STATUS_CODE.BadRequest, `Name too ${body.name.length < 4 ? 'short' : 'long'}.`); if (body.pin.length < 4 || body.pin.length > 20) return genericResponse(STATUS_CODE.BadRequest, `PIN too ${body.pin.length < 4 ? 'short' : 'long'}.`); - if (body.email.length > 255) return genericResponse(STATUS_CODE.BadRequest, `Email too long.`); + if (body.email.length > 255) return genericResponse(STATUS_CODE.BadRequest, 'Email too long.'); const id = nanoid();