From 15fbc0c20afa39d1500199a71acdb0f39f4a2c85 Mon Sep 17 00:00:00 2001 From: akram Date: Sat, 23 Dec 2023 21:59:30 +0200 Subject: [PATCH 1/7] =?UTF-8?q?=E2=9C=A8=20feat:=20create=20the=20captain?= =?UTF-8?q?=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/routes/captain.route.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 server/routes/captain.route.js diff --git a/server/routes/captain.route.js b/server/routes/captain.route.js new file mode 100644 index 00000000..6d7e3104 --- /dev/null +++ b/server/routes/captain.route.js @@ -0,0 +1,8 @@ +import { Router } from "express" +import authMiddleware from "../middlewares/auth.middleware"; + + +const captainRouter = Router(); + +// Check that the user is authorized +captainRouter.use('/', authMiddleware); \ No newline at end of file From 76df2dcf0fc3a860ef6598810cf9a85ce231cd1c Mon Sep 17 00:00:00 2001 From: akram Date: Sat, 23 Dec 2023 22:20:55 +0200 Subject: [PATCH 2/7] =?UTF-8?q?=E2=9C=A8=20feat:=20Implement=20the=20capta?= =?UTF-8?q?in=20controller=20&=20allCaptainsInfo=20function=20in=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/captain.controller.js | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 server/controllers/captain.controller.js diff --git a/server/controllers/captain.controller.js b/server/controllers/captain.controller.js new file mode 100644 index 00000000..e8c5942b --- /dev/null +++ b/server/controllers/captain.controller.js @@ -0,0 +1,27 @@ +import db from '../database/db.js' + +const captainController = { + allCaptainsInfo: async (req, res) => { + try { + // Query on the database to get the captains info + const result = await db.query(` + SELECT * + FROM "Captain" + `) + + // Respond with the data retrieved and a successful retrieval message + res.status(200).json({ + message: 'Successful retrieval', + result, + }) + + } catch (error) { + console.log(error); + res.status(500).json({ + error: 'An error occured while retrieving the captains info' + }) + } + }, +} + +export default captainController \ No newline at end of file From 8827abdfd5e47cd3c585a286338efc2f02869371 Mon Sep 17 00:00:00 2001 From: akram Date: Sat, 23 Dec 2023 23:20:10 +0200 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=94=A8=20fix:=20Return=20the=20newly?= =?UTF-8?q?=20created=20captain=20after=20signUp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/auth.controller.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/controllers/auth.controller.js b/server/controllers/auth.controller.js index 38de5dbf..ded075dd 100644 --- a/server/controllers/auth.controller.js +++ b/server/controllers/auth.controller.js @@ -44,6 +44,7 @@ const authController = { // Send the response res.status(201).json({ message: 'Captain created successfully', + newCaptain, }) } catch (error) { console.log(error) From 40747bd99b7ee2f5b40a819b1ec1443f7f1b0b76 Mon Sep 17 00:00:00 2001 From: akram Date: Sat, 23 Dec 2023 23:20:52 +0200 Subject: [PATCH 4/7] =?UTF-8?q?=E2=9C=A8feat:=20Make=20the=20routing=20for?= =?UTF-8?q?=20the=20captain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/captain.controller.js | 2 +- server/routes/api.route.js | 3 +++ server/routes/captain.route.js | 9 +++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/controllers/captain.controller.js b/server/controllers/captain.controller.js index e8c5942b..dfb9db8a 100644 --- a/server/controllers/captain.controller.js +++ b/server/controllers/captain.controller.js @@ -12,7 +12,7 @@ const captainController = { // Respond with the data retrieved and a successful retrieval message res.status(200).json({ message: 'Successful retrieval', - result, + body: result, }) } catch (error) { diff --git a/server/routes/api.route.js b/server/routes/api.route.js index da9b32f2..c7cebb90 100644 --- a/server/routes/api.route.js +++ b/server/routes/api.route.js @@ -1,7 +1,10 @@ import { Router } from 'express' import authRouter from './auth.route.js' +import captainRouter from './captain.route.js' + const apiRouter = Router() apiRouter.use('/auth', authRouter) +apiRouter.use('/captain', captainRouter) export default apiRouter diff --git a/server/routes/captain.route.js b/server/routes/captain.route.js index 6d7e3104..9f11013e 100644 --- a/server/routes/captain.route.js +++ b/server/routes/captain.route.js @@ -1,8 +1,13 @@ import { Router } from "express" -import authMiddleware from "../middlewares/auth.middleware"; +import authMiddleware from "../middlewares/auth.middleware.js"; +import captainController from "../controllers/captain.controller.js"; const captainRouter = Router(); // Check that the user is authorized -captainRouter.use('/', authMiddleware); \ No newline at end of file +//captainRouter.use('/', authMiddleware); + +captainRouter.get('/allCaptains/info', captainController.allCaptainsInfo) + +export default captainRouter \ No newline at end of file From 0b68834bf678bd2731f3a0af864ae1eb9d72a977 Mon Sep 17 00:00:00 2001 From: akram Date: Sat, 23 Dec 2023 23:40:24 +0200 Subject: [PATCH 5/7] =?UTF-8?q?=E2=9C=A8=20feat:=20Implement=20all=20capta?= =?UTF-8?q?in=20count=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/captain.controller.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/server/controllers/captain.controller.js b/server/controllers/captain.controller.js index dfb9db8a..a06b30f0 100644 --- a/server/controllers/captain.controller.js +++ b/server/controllers/captain.controller.js @@ -22,6 +22,27 @@ const captainController = { }) } }, + allCaptainsCount: async (req, res) => { + try { + // Query on the database to get the captains info + const result = await db.query(` + SELECT COUNT(*) + FROM "Captain" + `); + + // Respond with the data retrieved and a successful retrieval message + res.status(200).json({ + message: 'Successful retrieval', + body: result, + }) + + } catch (error) { + console.log(error); + res.status(500).json({ + error: 'An error occured while retrieving the captains count' + }) + } + } } export default captainController \ No newline at end of file From 1f8415e5a07376398df2ed5a522c2d2dca1209c9 Mon Sep 17 00:00:00 2001 From: akram Date: Sat, 23 Dec 2023 23:41:40 +0200 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=8C=BFfeat:=20Make=20the=20routing=20?= =?UTF-8?q?for=20allCaptainsCount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/routes/captain.route.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/routes/captain.route.js b/server/routes/captain.route.js index 9f11013e..5886d7ae 100644 --- a/server/routes/captain.route.js +++ b/server/routes/captain.route.js @@ -9,5 +9,7 @@ const captainRouter = Router(); //captainRouter.use('/', authMiddleware); captainRouter.get('/allCaptains/info', captainController.allCaptainsInfo) +captainRouter.get('/allCaptains/count', captainController.allCaptainsCount) + export default captainRouter \ No newline at end of file From 822786c7c2a0406bcd2889ec4d0ed6f9da74a4e9 Mon Sep 17 00:00:00 2001 From: akram Date: Sun, 24 Dec 2023 00:12:13 +0200 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=94=A8=20fix:=20move=20the=20authMidd?= =?UTF-8?q?leware=20to=20api.route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/routes/api.route.js | 3 ++- server/routes/captain.route.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/routes/api.route.js b/server/routes/api.route.js index c7cebb90..8f574d29 100644 --- a/server/routes/api.route.js +++ b/server/routes/api.route.js @@ -1,10 +1,11 @@ import { Router } from 'express' import authRouter from './auth.route.js' import captainRouter from './captain.route.js' +import authMiddleware from '../middlewares/auth.middleware.js' const apiRouter = Router() apiRouter.use('/auth', authRouter) -apiRouter.use('/captain', captainRouter) +apiRouter.use('/captain', authMiddleware, captainRouter) export default apiRouter diff --git a/server/routes/captain.route.js b/server/routes/captain.route.js index 5886d7ae..9d27c6c5 100644 --- a/server/routes/captain.route.js +++ b/server/routes/captain.route.js @@ -6,7 +6,7 @@ import captainController from "../controllers/captain.controller.js"; const captainRouter = Router(); // Check that the user is authorized -//captainRouter.use('/', authMiddleware); + captainRouter.get('/allCaptains/info', captainController.allCaptainsInfo) captainRouter.get('/allCaptains/count', captainController.allCaptainsCount)