From bff82ecbb306ac0cf1636b09bb9bdf4d1d7087ab Mon Sep 17 00:00:00 2001
From: Matt Kirby <MattJKirby@outlook.com>
Date: Sat, 15 Apr 2023 01:29:50 +0100
Subject: [PATCH] Friends routes

---
 .../src/Routes/FriendsRouter.ts               | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 backend-services/friend-service/src/Routes/FriendsRouter.ts

diff --git a/backend-services/friend-service/src/Routes/FriendsRouter.ts b/backend-services/friend-service/src/Routes/FriendsRouter.ts
new file mode 100644
index 00000000..771e8e3b
--- /dev/null
+++ b/backend-services/friend-service/src/Routes/FriendsRouter.ts
@@ -0,0 +1,38 @@
+import express, { Response } from 'express'
+import { FriendManager } from '../Friends/FriendManager'
+import { CustomJWTRequest } from '../Middleware/Auth'
+
+export const FriendsRouter = express.Router()
+const friendManager = new FriendManager();
+
+/**
+ * GET '/'
+ * Returns a string
+ */
+FriendsRouter.get('/', async (req:CustomJWTRequest, res:Response): Promise<void> => {
+  const {token} = req
+  return friendManager.GetFriendIds(token as string).then(result => {
+    res.status(200).json({result: result});
+  }).catch((error: Error) => {
+    res.status(400).json({error: error})
+  });
+});
+
+/**
+ * Delete '/'
+ * Returns a string
+ */
+ FriendsRouter.delete('/', async (req:CustomJWTRequest, res:Response): Promise<Response> => {
+  const {user_id, friend_id} = req.body
+  const {token} = req
+
+  if(token !== user_id){
+    return res.status(400).json({error: 'unauthorised'})
+  }
+
+  return friendManager.RemoveFriend(user_id, friend_id).then(result => {
+    return res.sendStatus(200);
+  }).catch((error: Error) => {
+    return res.status(400).json({error: error})
+  });
+});
\ No newline at end of file
-- 
GitLab