Back

Version 29

4/26/2024
/** @jsx jsx */
/** @jsxFrag Fragment */
import { jsx, Fragment } from "https://deno.land/x/hono/middleware.ts";
import { getUserByUsername, insertUserLink, deleteUserLink, getLinkById, updateUserLink } from "https://esm.town/v/iamseeley/Queries";
import EditProfilePage from "https://esm.town/v/iamseeley/EditProfilePage";
import RootLayout from "https://esm.town/v/iamseeley/RootLayout";

export const addLinkHandler = async (c) => {
try {
const payload = await c.get('jwtPayload');
const body = await c.req.parseBody();
const label = body.label;
const url = body.url;

// Validate input
if (!label || !url) {
return c.json({ error: 'Label and URL are required' }, 400);
}

// Add the new link
await insertUserLink(payload.userId, label, url);

// Redirect to the edit-profile page
return c.redirect(`/edit-profile/${payload.username}`);
} catch (error) {
console.error("Error adding link:", error);
return c.html(
<RootLayout>
<p>Error adding link. Please try again.</p>
</RootLayout>
);
}
};

export const updateLinkHandler = async (c) => {
try {
Updated: May 1, 2024