@@ -12,6 +13,6 @@ export default function Browser() {
{/* divider */}
{/* recipe cards, or "no recipes matching your search" */}
-
+
)
}
\ No newline at end of file
diff --git a/client/src/components/pages/Profile.tsx b/client/src/components/pages/Profile.tsx
index 02d8c00..ab9d24b 100644
--- a/client/src/components/pages/Profile.tsx
+++ b/client/src/components/pages/Profile.tsx
@@ -7,13 +7,14 @@ import Protect from "../../util/Protect";
export default function Profile() {
const [message, setMessage] = useState
();
- const { user } = useContext(AuthContext);
+ // const { user } = useAuthContext();
+ const { user } = useAuthContext();
const navigate = useNavigate();
return (
-
{user!.firstname}'s Profile
+
{user?.firstname}'s Profile
Things and stuff!
diff --git a/client/src/components/pages/Subscriptions.tsx b/client/src/components/pages/Subscriptions.tsx
deleted file mode 100644
index e69de29..0000000
diff --git a/client/src/components/pages/Subscriptions/Constructor.tsx b/client/src/components/pages/Subscriptions/Constructor.tsx
new file mode 100644
index 0000000..2fb56eb
--- /dev/null
+++ b/client/src/components/pages/Subscriptions/Constructor.tsx
@@ -0,0 +1,3 @@
+export default class Constructor {
+
+}
\ No newline at end of file
diff --git a/client/src/components/pages/Subscriptions/Subscriptions.tsx b/client/src/components/pages/Subscriptions/Subscriptions.tsx
new file mode 100644
index 0000000..0c57f6a
--- /dev/null
+++ b/client/src/components/pages/Subscriptions/Subscriptions.tsx
@@ -0,0 +1,13 @@
+import { useContext } from "react";
+import { useAuthContext } from "../../../context/AuthContext";
+import Protect from "../../../util/Protect";
+
+export default function Subscriptions() {
+ const { user } = useAuthContext();
+
+ return (
+
+ {user?.firstname}'s Subscriptions
+
+ )
+}
\ No newline at end of file
diff --git a/client/src/components/ui/Navbar.tsx b/client/src/components/ui/Navbar.tsx
index c0efde9..a1c9790 100644
--- a/client/src/components/ui/Navbar.tsx
+++ b/client/src/components/ui/Navbar.tsx
@@ -7,7 +7,7 @@ import Button from "./Button";
import "/src/sass/components/Navbar.scss";
const Navbar = () => {
- const { user } = useContext(AuthContext);
+ const { user } = useAuthContext();
const navigate = useNavigate();
const navbarLoggedIn = (
diff --git a/client/src/util/Protect.tsx b/client/src/util/Protect.tsx
index 77dae68..4cf5481 100644
--- a/client/src/util/Protect.tsx
+++ b/client/src/util/Protect.tsx
@@ -3,9 +3,10 @@ import { useNavigate } from "react-router-dom";
import { Button, Page } from "../components/ui";
import Divider from "../components/ui/Divider";
import { AuthContext } from "../context/AuthContext";
+import { ProtectPortal } from "./types";
-export default function Protect({ children = <>> }) {
- const { user } = useContext(AuthContext);
+const Protect: ProtectPortal = ({ children = <>> }) => {
+ const { user } = useAuthContext();
const navigate = useNavigate();
if (!user) {
@@ -26,4 +27,6 @@ export default function Protect({ children = <>> }) {
)
}
-}
\ No newline at end of file
+}
+
+export default Protect;
\ No newline at end of file
diff --git a/client/src/util/apiUtils.tsx b/client/src/util/apiUtils.tsx
index d3fcd17..1bc2653 100644
--- a/client/src/util/apiUtils.tsx
+++ b/client/src/util/apiUtils.tsx
@@ -87,6 +87,13 @@ export const getAllRecipes = async () => {
} catch (e: any) {
throw e;
}
- // const result = await fetch(API + 'recipe').then(response => response.json());
- // return result;
+}
+
+// for user friendships
+export const getFriendships = async () => {
+ try {
+
+ } catch (e: any) {
+ throw e;
+ }
}
\ No newline at end of file
diff --git a/client/src/util/types.ts b/client/src/util/types.ts
index 705b086..a595f8d 100644
--- a/client/src/util/types.ts
+++ b/client/src/util/types.ts
@@ -10,6 +10,11 @@ interface ButtonParams extends PortalBase {
onClick?: (params?: any) => any
}
+interface ModifiedPortal extends PortalBase {
+ children?: ReactNode | ReactNode[]
+}
+
export type PageComponent = FC
export type PanelComponent = FC
-export type ButtonComponent = FC
\ No newline at end of file
+export type ButtonComponent = FC
+export type ProtectPortal = FC
\ No newline at end of file
diff --git a/server/controllers/UserCtl.ts b/server/controllers/UserCtl.ts
index 4a39721..82a6749 100644
--- a/server/controllers/UserCtl.ts
+++ b/server/controllers/UserCtl.ts
@@ -43,4 +43,14 @@ export default class UserCtl {
throw new Error(error);
}
}
+
+ async getFriends(id: string) {
+ try {
+ const result = await UserInstance.getFriends(id);
+ if (!result) throw createError(404, "You have no friends");
+ return result;
+ } catch (e: any) {
+ throw new Error(e);
+ }
+ }
}
\ No newline at end of file
diff --git a/server/db/sql/friendships.sql b/server/db/sql/friendships.sql
new file mode 100644
index 0000000..850df88
--- /dev/null
+++ b/server/db/sql/friendships.sql
@@ -0,0 +1,13 @@
+SELECT
+ recipin.cmp_userfriendships.id,
+ recipin.cmp_userfriendships.datecreated,
+ recipin.appusers.id,
+ recipin.appusers.firstname,
+ recipin.appusers.lastname,
+ recipin.appusers.handle,
+ recipin.appusers.email
+FROM recipin.cmp_userfriendships
+INNER JOIN recipin.appusers
+ON recipin.appusers.id = recipin.cmp_userfriendships.seconduserid
+WHERE firstuserid = $1
+AND cmp_userfriendships.active = true;
\ No newline at end of file
diff --git a/server/index.ts b/server/index.ts
index 6b9b3ce..a4802fe 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -1,4 +1,5 @@
import express from 'express';
+import path from 'path';
import cors from 'cors';
import dotenv from 'dotenv';
dotenv.config();
@@ -9,7 +10,10 @@ const port = 8080;
const app = express();
app.use(cors());
+export const appRoot = path.resolve(__dirname);
+
(async function() {
+
const app = express();
await loaders(app);
app.listen(port, () => {
diff --git a/server/models/user.ts b/server/models/user.ts
index f609695..37f874c 100644
--- a/server/models/user.ts
+++ b/server/models/user.ts
@@ -1,7 +1,9 @@
import { IUser } from "../schemas";
+import fs from "fs";
import pgPromise from "pg-promise";
import pool from '../db';
import now from "../util/now";
+import { appRoot } from "..";
const pgp = pgPromise({ capSQL: true });
export class User {
@@ -91,4 +93,15 @@ export class User {
throw new Error(error);
}
}
+
+ async getFriends(id: string) {
+ try {
+ const sql = fs.readFileSync(appRoot + '/db/sql/friendships.sql').toString();
+ const result = await pool.query(sql, [id]);
+ if (result.rows.length) return result.rows;
+ return null;
+ } catch (e: any) {
+ throw new Error(e);
+ }
+ }
}
\ No newline at end of file
diff --git a/server/routes/users.ts b/server/routes/users.ts
index 89a5210..4692993 100644
--- a/server/routes/users.ts
+++ b/server/routes/users.ts
@@ -12,6 +12,7 @@ export const userRoute = (app: Express) => {
res.status(200).send(data);
})
+ // get, put by id
router.get('/:id', async (req, res, next) => {
const { id } = req.params;
try {
@@ -33,13 +34,21 @@ export const userRoute = (app: Express) => {
}
})
+ // create user
router.post('/', async (req, res) => {
const data = req.body;
const response = userCtl.post(data);
res.status(200).send(response);
})
- router.get('/hidden-thing', (req, res) => {
- res.send('does this route actually work?');
+ // get friendships by requester ID
+ router.get('/friends/:id', async (req, res, next) => {
+ const { id } = req.params;
+ try {
+ const result = await userCtl.getFriends(id);
+ res.status(200).send(result);
+ } catch(e) {
+ next(e);
+ }
})
}
\ No newline at end of file