From 7df8b5ad8ec45317ca1ee49fa7c99edae90312b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Wed, 18 Aug 2021 12:02:59 +0000 Subject: [PATCH] API-13: Adding PartyPlaner main endpoint (#2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Also did some refactoring for cleaner code Co-authored-by: Patrick Müller Reviewed-on: https://git.plutodev.de/PlutoDev/plutoapi-v2/pulls/2 Co-authored-by: Patrick Müller Co-committed-by: Patrick Müller --- app.ts | 14 +++++----- src/models/dhbw-service/DHBWServiceRouter.ts | 22 +++++++++++++++ .../{ => generalInfo}/GeneralInfo.router.ts | 2 +- src/models/partyplaner/PartyPlaner.router.ts | 22 +++++++++++++++ src/models/partyplaner/data/Data.router.ts | 27 +++++++++++++++++++ .../HighlightMarker.router.ts | 21 +++++++++++++++ .../{ => addHighlight}/AddHighlight.router.ts | 0 .../addHighlights.service.ts | 0 8 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 src/models/dhbw-service/DHBWServiceRouter.ts rename src/models/dhbw-service/{ => generalInfo}/GeneralInfo.router.ts (93%) create mode 100644 src/models/partyplaner/PartyPlaner.router.ts create mode 100644 src/models/partyplaner/data/Data.router.ts create mode 100644 src/models/twitch-highlight-marker/HighlightMarker.router.ts rename src/models/twitch-highlight-marker/{ => addHighlight}/AddHighlight.router.ts (100%) rename src/models/twitch-highlight-marker/{ => addHighlight}/addHighlights.service.ts (100%) diff --git a/app.ts b/app.ts index 1459c33..fece404 100644 --- a/app.ts +++ b/app.ts @@ -12,11 +12,10 @@ if (!process.env.PORT) { const port: number = parseInt(process.env.PORT, 10); -// DHBW Service -import {generalInfoRouter} from "./src/models/dhbw-service/GeneralInfo.router"; - -// Twitch Highlight Marker -import {addHighlightRouter} from "./src/models/twitch-highlight-marker/AddHighlight.router"; +// Router imports +import {partyPlanerRouter} from "./src/models/partyplaner/PartyPlaner.router"; +import {highlightMarkerRouter} from "./src/models/twitch-highlight-marker/HighlightMarker.router"; +import { dhbwServiceRouter } from './src/models/dhbw-service/DHBWServiceRouter'; const app: express.Application = express(); const server: http.Server = http.createServer(app); @@ -25,8 +24,9 @@ const server: http.Server = http.createServer(app); app.use(bodyparser.json()); // Add routers -app.use('/dhbw-service/generalInfo', generalInfoRouter); -app.use('/twitch-highlight-marker/addHighlight', addHighlightRouter); +app.use('/dhbw-service', dhbwServiceRouter); +app.use('/twitch-highlight-marker', highlightMarkerRouter); +app.use('/partyplaner', partyPlanerRouter); // this is a simple route to make sure everything is working properly app.get('/', (req: express.Request, res: express.Response) => { diff --git a/src/models/dhbw-service/DHBWServiceRouter.ts b/src/models/dhbw-service/DHBWServiceRouter.ts new file mode 100644 index 0000000..058c9ed --- /dev/null +++ b/src/models/dhbw-service/DHBWServiceRouter.ts @@ -0,0 +1,22 @@ +/** + * Required External Modules and Interfaces + */ +import express, {Request, Response} from 'express'; +import {generalInfoRouter} from "./generalInfo/GeneralInfo.router"; + +/** + * Router Definition + */ +export const dhbwServiceRouter = express.Router(); + +// Sub-Endpoints +dhbwServiceRouter.use('/generalInfo', generalInfoRouter); + +generalInfoRouter.get('/', async (req: Request, res: Response) => { + try { + res.status(200).send(`Pluto Development DHBW Service App API Endpoint`); + } catch (e) { + console.log('Error handling a request: ' + e.message); + res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); + } +}) diff --git a/src/models/dhbw-service/GeneralInfo.router.ts b/src/models/dhbw-service/generalInfo/GeneralInfo.router.ts similarity index 93% rename from src/models/dhbw-service/GeneralInfo.router.ts rename to src/models/dhbw-service/generalInfo/GeneralInfo.router.ts index aeb4169..e416e21 100644 --- a/src/models/dhbw-service/GeneralInfo.router.ts +++ b/src/models/dhbw-service/generalInfo/GeneralInfo.router.ts @@ -19,7 +19,7 @@ generalInfoRouter.get('/', async (req: Request, res: Response) => { generalInfoRouter.post('/', async (req: Request, res: Response) => { try { - res.status(200).send(`GET generalInfo v2.1`); + res.status(200).send(`POST generalInfo v2.1`); } catch (e) { console.log('Error handling a request: ' + e.message); res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); diff --git a/src/models/partyplaner/PartyPlaner.router.ts b/src/models/partyplaner/PartyPlaner.router.ts new file mode 100644 index 0000000..611b814 --- /dev/null +++ b/src/models/partyplaner/PartyPlaner.router.ts @@ -0,0 +1,22 @@ +/** + * Required External Modules and Interfaces + */ +import express, {Request, Response} from 'express'; +import {dataRouter} from "./data/Data.router"; + +/** + * Router Definition + */ +export const partyPlanerRouter = express.Router(); + +// Sub-Endpoints +partyPlanerRouter.use('/data', dataRouter); + +partyPlanerRouter.get('/', async (req: Request, res: Response) => { + try { + res.status(200).send(`Pluto Development PartyPlaner API Endpoint V2`); + } catch (e) { + console.log('Error handling a request: ' + e.message); + res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); + } +}) diff --git a/src/models/partyplaner/data/Data.router.ts b/src/models/partyplaner/data/Data.router.ts new file mode 100644 index 0000000..20c30ce --- /dev/null +++ b/src/models/partyplaner/data/Data.router.ts @@ -0,0 +1,27 @@ +/** + * Required External Modules and Interfaces + */ +import express, {Request, Response} from 'express'; + +/** + * Router Definition + */ +export const dataRouter = express.Router(); + +dataRouter.get('/', async (req: Request, res: Response) => { + try { + res.status(200).send(`GET data`); + } catch (e) { + console.log('Error handling a request: ' + e.message); + res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); + } +}) + +dataRouter.post('/', async (req: Request, res: Response) => { + try { + res.status(200).send(`POST data`); + } catch (e) { + console.log('Error handling a request: ' + e.message); + res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); + } +}) diff --git a/src/models/twitch-highlight-marker/HighlightMarker.router.ts b/src/models/twitch-highlight-marker/HighlightMarker.router.ts new file mode 100644 index 0000000..b016121 --- /dev/null +++ b/src/models/twitch-highlight-marker/HighlightMarker.router.ts @@ -0,0 +1,21 @@ +/** + * Required External Modules and Interfaces + */ +import express, {Request, Response} from 'express'; +import {addHighlightRouter} from "./addHighlight/AddHighlight.router"; + +/** + * Router Definition + */ +export const highlightMarkerRouter = express.Router(); + +highlightMarkerRouter.use('/addHighlight', addHighlightRouter); + +highlightMarkerRouter.get('/', async (req: Request, res: Response) => { + try { + res.status(200).send(`Pluto Development Twitch Highlight Marker API Endpoint`); + } catch (e) { + console.log('Error handling a request: ' + e.message); + res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'})); + } +}) diff --git a/src/models/twitch-highlight-marker/AddHighlight.router.ts b/src/models/twitch-highlight-marker/addHighlight/AddHighlight.router.ts similarity index 100% rename from src/models/twitch-highlight-marker/AddHighlight.router.ts rename to src/models/twitch-highlight-marker/addHighlight/AddHighlight.router.ts diff --git a/src/models/twitch-highlight-marker/addHighlights.service.ts b/src/models/twitch-highlight-marker/addHighlight/addHighlights.service.ts similarity index 100% rename from src/models/twitch-highlight-marker/addHighlights.service.ts rename to src/models/twitch-highlight-marker/addHighlight/addHighlights.service.ts