From c4a1570cbd976fbc43b109a8963de94eee5bbcfd Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Wed, 25 Sep 2024 18:02:33 +0100 Subject: [PATCH 01/14] feat(routers): import & define express.Router --- src/app.ts | 13 ++++--------- src/routes/router.ts | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/app.ts b/src/app.ts index 7d6701b..a244bb4 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,21 +1,16 @@ -import express, { Express, Request, Response } from "express"; +import express, { Express, Request, Response, Router } from "express"; import * as dotenv from "dotenv"; dotenv.config(); const keys = { port: process.env.PORT } const app: Express = express(); +const router: Router = Router(); -//h1 Routers +//h1 System Logs console.log(`Now in ./app`); -app.get('/openai', (req: Request, res: Response) => { - res.send({ message: "Server --> OpenAI" }); -}); - -app.get('/spotify', (req: Request, res: Response) => { - res.send({ message: "Server --> Spotify" }); -}); +//h1 Routers //h2 Fallback app.get('/', (req: Request, res: Response) => { diff --git a/src/routes/router.ts b/src/routes/router.ts index ea33e2b..8cef76e 100644 --- a/src/routes/router.ts +++ b/src/routes/router.ts @@ -1,11 +1,27 @@ -import express, { Express, Request, Response } from "express"; +import express, { Express, Request, Response, Router } from "express"; import * as dotenv from "dotenv"; dotenv.config(); const keys = { port: process.env.PORT } const app: Express = express(); +const router: Router = Router(); + +//h1 System Logs +console.log(`Now in ./src/routes/router.ts`); //h1 Routers +app.get('/openai', (req: Request, res: Response) => { + res.send({ message: "Server --> OpenAI" }); +}); + +app.get('/spotify', (req: Request, res: Response) => { + res.send({ message: "Server --> Spotify" }); +}); + +//h2 Server +app.get('/', (req: Request, res: Response) => { + res.send({ message: "Server --> Server" }); +}); -console.log(`Now in ./src/routes/router.ts`); \ No newline at end of file +//h2 Fallbacks \ No newline at end of file From e4301c2516b9d789f78dda8542f8f504198b7a15 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Wed, 25 Sep 2024 18:29:52 +0100 Subject: [PATCH 02/14] build(router): npm install itty-router --- package-lock.json | 7 +++++++ package.json | 1 + src/app.ts | 12 ++---------- src/routes/router.ts | 10 ++++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index deb189d..b4bbbf5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@spotify/web-api-ts-sdk": "^1.2.0", "dotenv": "^16.4.5", "express": "^4.21.0", + "itty-router": "^5.0.18", "openai": "^4.63.0", "tsx": "^4.19.1" }, @@ -4648,6 +4649,12 @@ "dev": true, "license": "MIT" }, + "node_modules/itty-router": { + "version": "5.0.18", + "resolved": "https://registry.npmjs.org/itty-router/-/itty-router-5.0.18.tgz", + "integrity": "sha512-mK3ReOt4ARAGy0V0J7uHmArG2USN2x0zprZ+u+YgmeRjXTDbaowDy3kPcsmQY6tH+uHhDgpWit9Vqmv/4rTXwA==", + "license": "MIT" + }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", diff --git a/package.json b/package.json index d5da359..7431cd1 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@spotify/web-api-ts-sdk": "^1.2.0", "dotenv": "^16.4.5", "express": "^4.21.0", + "itty-router": "^5.0.18", "openai": "^4.63.0", "tsx": "^4.19.1" } diff --git a/src/app.ts b/src/app.ts index a244bb4..43a0930 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,5 +1,6 @@ import express, { Express, Request, Response, Router } from "express"; import * as dotenv from "dotenv"; +import * as hub from "./routes/router.js"; dotenv.config(); @@ -7,17 +8,8 @@ const keys = { port: process.env.PORT } const app: Express = express(); const router: Router = Router(); -//h1 System Logs -console.log(`Now in ./app`); +app.use(hub); -//h1 Routers - -//h2 Fallback -app.get('/', (req: Request, res: Response) => { - res.send({ message: "Server --> Server" }); -}); - -//h1 Listeners app.listen(keys.port, () => { console.log(`Server running on port ${keys.port}`); }); \ No newline at end of file diff --git a/src/routes/router.ts b/src/routes/router.ts index 8cef76e..7b2b173 100644 --- a/src/routes/router.ts +++ b/src/routes/router.ts @@ -11,17 +11,19 @@ const router: Router = Router(); console.log(`Now in ./src/routes/router.ts`); //h1 Routers -app.get('/openai', (req: Request, res: Response) => { +router.get('/openai', (req: Request, res: Response) => { res.send({ message: "Server --> OpenAI" }); }); -app.get('/spotify', (req: Request, res: Response) => { +router.get('/spotify', (req: Request, res: Response) => { res.send({ message: "Server --> Spotify" }); }); //h2 Server -app.get('/', (req: Request, res: Response) => { +router.get('/', (req: Request, res: Response) => { res.send({ message: "Server --> Server" }); }); -//h2 Fallbacks \ No newline at end of file +//h2 Fallbacks + +export \ No newline at end of file From af9f5218e1894c681f5ee03f04e0afc661f57df9 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Wed, 25 Sep 2024 18:53:27 +0100 Subject: [PATCH 03/14] build(router): router hierarchy - configure itty-router - simplify `./routes` due to controlled number of flows --- src/app.ts | 24 +++++++++++++++--------- src/routes/openai/router.ts | 9 --------- src/routes/router.ts | 32 ++++++++++---------------------- src/routes/server/router.ts | 9 --------- src/routes/spotify/router.ts | 9 --------- 5 files changed, 25 insertions(+), 58 deletions(-) delete mode 100644 src/routes/openai/router.ts delete mode 100644 src/routes/server/router.ts delete mode 100644 src/routes/spotify/router.ts diff --git a/src/app.ts b/src/app.ts index 43a0930..138648b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,15 +1,21 @@ -import express, { Express, Request, Response, Router } from "express"; +//h1 IMPORT import * as dotenv from "dotenv"; -import * as hub from "./routes/router.js"; +import express, { Express, Request, Response } from "express"; +import { AutoRouter } from "itty-router"; +import { router as childRouter } from "./routes/router.js"; +//h1 CONFIG dotenv.config(); +const keys = { port: process.env.PORT }; +const app = express(); +const router = AutoRouter(); -const keys = { port: process.env.PORT } -const app: Express = express(); -const router: Router = Router(); +//h1 SERVER +app.listen(keys.port, () => { console.log(`Port ${keys.port}`) }); -app.use(hub); +router + .all("/go/*", childRouter.fetch) + .get('/', () => "Router Path: './app'"); -app.listen(keys.port, () => { - console.log(`Server running on port ${keys.port}`); -}); \ No newline at end of file +//h1 EXPORT +export default router; \ No newline at end of file diff --git a/src/routes/openai/router.ts b/src/routes/openai/router.ts deleted file mode 100644 index a088d14..0000000 --- a/src/routes/openai/router.ts +++ /dev/null @@ -1,9 +0,0 @@ -import express, { Express, Request, Response } from "express"; -import * as dotenv from "dotenv"; - -dotenv.config(); - -const keys = { port: process.env.PORT } -const app: Express = express(); - -console.log(`Now in ./src/routes/openai/router.ts`); \ No newline at end of file diff --git a/src/routes/router.ts b/src/routes/router.ts index 7b2b173..6305c51 100644 --- a/src/routes/router.ts +++ b/src/routes/router.ts @@ -1,29 +1,17 @@ -import express, { Express, Request, Response, Router } from "express"; -import * as dotenv from "dotenv"; +//h1 IMPORT +import { AutoRouter } from "itty-router"; -dotenv.config(); +//h1 ROUTES +export const router = AutoRouter({ base: "/go" }); -const keys = { port: process.env.PORT } -const app: Express = express(); -const router: Router = Router(); +router.get("/", () => "Router Path: ./routes/router"); -//h1 System Logs -console.log(`Now in ./src/routes/router.ts`); - -//h1 Routers -router.get('/openai', (req: Request, res: Response) => { - res.send({ message: "Server --> OpenAI" }); +/* router.get('/openai', (req: Request, res: Response) => { + res.send({ message: "Server --> OpenAI" }); }); - router.get('/spotify', (req: Request, res: Response) => { - res.send({ message: "Server --> Spotify" }); + res.send({ message: "Server --> Spotify" }); }); - -//h2 Server router.get('/', (req: Request, res: Response) => { - res.send({ message: "Server --> Server" }); -}); - -//h2 Fallbacks - -export \ No newline at end of file + res.send({ message: "Server --> Server" }); +}); */ \ No newline at end of file diff --git a/src/routes/server/router.ts b/src/routes/server/router.ts deleted file mode 100644 index b76eba3..0000000 --- a/src/routes/server/router.ts +++ /dev/null @@ -1,9 +0,0 @@ -import express, { Express, Request, Response } from "express"; -import * as dotenv from "dotenv"; - -dotenv.config(); - -const keys = { port: process.env.PORT } -const app: Express = express(); - -console.log(`Now in ./src/routes/server/router.ts`); \ No newline at end of file diff --git a/src/routes/spotify/router.ts b/src/routes/spotify/router.ts deleted file mode 100644 index a10e0e0..0000000 --- a/src/routes/spotify/router.ts +++ /dev/null @@ -1,9 +0,0 @@ -import express, { Express, Request, Response } from "express"; -import * as dotenv from "dotenv"; - -dotenv.config(); - -const keys = { port: process.env.PORT } -const app: Express = express(); - -console.log(`Now in ./src/routes/spotify/router.ts`); \ No newline at end of file From 4a18316cc0beee5be3d969c2a92c05789e524352 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Wed, 25 Sep 2024 19:24:33 +0100 Subject: [PATCH 04/14] Create test routes representing each API --- src/app.ts | 13 ++++++++----- src/routes/router.ts | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/app.ts b/src/app.ts index 138648b..f3cbe77 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,8 +1,9 @@ //h1 IMPORT import * as dotenv from "dotenv"; import express, { Express, Request, Response } from "express"; -import { AutoRouter } from "itty-router"; -import { router as childRouter } from "./routes/router.js"; + +import { AutoRouter, html, IRequest, json, text } from "itty-router"; +import { router as hub } from "./routes/router.js"; //h1 CONFIG dotenv.config(); @@ -11,11 +12,13 @@ const app = express(); const router = AutoRouter(); //h1 SERVER -app.listen(keys.port, () => { console.log(`Port ${keys.port}`) }); +app.listen(keys.port, () => { + console.log(`Port ${keys.port}`) +}); router - .all("/go/*", childRouter.fetch) - .get('/', () => "Router Path: './app'"); + .all("/go/*", hub.fetch) + .get('/', () => ({ message: "Router Path: './app'" })); //h1 EXPORT export default router; \ No newline at end of file diff --git a/src/routes/router.ts b/src/routes/router.ts index 6305c51..41de889 100644 --- a/src/routes/router.ts +++ b/src/routes/router.ts @@ -1,17 +1,19 @@ //h1 IMPORT -import { AutoRouter } from "itty-router"; +import { AutoRouter, html, IRequest, json, text } from "itty-router"; //h1 ROUTES -export const router = AutoRouter({ base: "/go" }); +const router = AutoRouter({ base: "/go" }); -router.get("/", () => "Router Path: ./routes/router"); +router.get("/openai", ( req: IRequest ) => { + console.log("Router Path: ./routes/router:openai"); +}); -/* router.get('/openai', (req: Request, res: Response) => { - res.send({ message: "Server --> OpenAI" }); +router.get("/spotify", ( req: IRequest ) => { + console.log("Router Path: ./routes/router:spotify"); }); -router.get('/spotify', (req: Request, res: Response) => { - res.send({ message: "Server --> Spotify" }); + +router.get("/", ( req: IRequest ) => { + console.log("Router Path: ./routes/router:server"); }); -router.get('/', (req: Request, res: Response) => { - res.send({ message: "Server --> Server" }); -}); */ \ No newline at end of file + +export { router }; \ No newline at end of file From acf427ad8445ffb112d34c1184d331f97e99b4ca Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Thu, 26 Sep 2024 10:37:45 +0100 Subject: [PATCH 05/14] mermaid flow diagram --- docs/ROUTE_SCRATCH.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docs/ROUTE_SCRATCH.md diff --git a/docs/ROUTE_SCRATCH.md b/docs/ROUTE_SCRATCH.md new file mode 100644 index 0000000..3e6a8bf --- /dev/null +++ b/docs/ROUTE_SCRATCH.md @@ -0,0 +1,40 @@ +# Routes Scratchpad + +```mermaid + graph TD + + input + output + + subgraph jason + inSEvent + inSGenre + inDDate + appApp + appOut + end + + subgraph tanya + toOpenAI + openai + fromOpenAI + end + + subgraph gaj + toSpotify + spotify + fromSpotify + end + + + input --> inSEvent & inSGenre & inDDate + inSEvent & inSGenre --> toOpenAI + toOpenAI --> openai + openai --> fromOpenAI + inDDate & fromOpenAI --> appApp + appApp --> toSpotify + toSpotify --> spotify + spotify --> fromSpotify + fromSpotify --> appOut + appOut --> output +``` From 124b8cbf90061fed31d0b20dacedc366aaaf767a Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Thu, 26 Sep 2024 13:07:23 +0100 Subject: [PATCH 06/14] build(router): Architecture - routes & controllers MVP structure completed & clean - function calls working within some routes - some work has begun on separation of concerns between controllers, routes & models - controllers now have descriptive names - routers call sequentially & successfully - routers point towards controllers in anticipation of calling them BREAKING CHANGE: --- docs/{ROUTE_SCRATCH.md => DATAFLOW.md} | 0 docs/ROUTES.md | 40 +++++++++++++++++++ package-lock.json | 31 ++++++++++++++ package.json | 1 + scratch/itty-router.js | 10 +++++ src/app.ts | 33 +++------------ src/controllers/index.ts | 0 .../openAI/{index.ts => extractEmotion.ts} | 22 +++++----- src/controllers/server/index.ts | 0 .../spotify/{index.ts => searchGenre.ts} | 4 +- src/controllers/user/getInput.ts | 27 +++++++++++++ .../user/showOutput.ts} | 23 +++++------ src/models/spotify/searchGenre.ts | 38 ++++++++++++++++++ src/routes/internal/user.ts | 13 ++++++ src/routes/openAI/index.ts | 16 ++++++++ src/routes/router.ts | 19 --------- src/routes/routes.ts | 16 ++++++++ src/routes/spotify/index.ts | 15 +++++++ 18 files changed, 237 insertions(+), 71 deletions(-) rename docs/{ROUTE_SCRATCH.md => DATAFLOW.md} (100%) create mode 100644 docs/ROUTES.md create mode 100644 scratch/itty-router.js delete mode 100644 src/controllers/index.ts rename src/controllers/openAI/{index.ts => extractEmotion.ts} (58%) delete mode 100644 src/controllers/server/index.ts rename src/controllers/spotify/{index.ts => searchGenre.ts} (94%) create mode 100644 src/controllers/user/getInput.ts rename src/{routes/playlist/router.ts => controllers/user/showOutput.ts} (58%) create mode 100644 src/models/spotify/searchGenre.ts create mode 100644 src/routes/internal/user.ts create mode 100644 src/routes/openAI/index.ts delete mode 100644 src/routes/router.ts create mode 100644 src/routes/routes.ts create mode 100644 src/routes/spotify/index.ts diff --git a/docs/ROUTE_SCRATCH.md b/docs/DATAFLOW.md similarity index 100% rename from docs/ROUTE_SCRATCH.md rename to docs/DATAFLOW.md diff --git a/docs/ROUTES.md b/docs/ROUTES.md new file mode 100644 index 0000000..3e6a8bf --- /dev/null +++ b/docs/ROUTES.md @@ -0,0 +1,40 @@ +# Routes Scratchpad + +```mermaid + graph TD + + input + output + + subgraph jason + inSEvent + inSGenre + inDDate + appApp + appOut + end + + subgraph tanya + toOpenAI + openai + fromOpenAI + end + + subgraph gaj + toSpotify + spotify + fromSpotify + end + + + input --> inSEvent & inSGenre & inDDate + inSEvent & inSGenre --> toOpenAI + toOpenAI --> openai + openai --> fromOpenAI + inDDate & fromOpenAI --> appApp + appApp --> toSpotify + toSpotify --> spotify + spotify --> fromSpotify + fromSpotify --> appOut + appOut --> output +``` diff --git a/package-lock.json b/package-lock.json index 699b0e8..ba2c606 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "express": "^4.21.0", "itty-router": "^5.0.18", "openai": "^4.63.0", + "prompt-sync": "^4.2.0", "swagger-jsdoc": "^6.2.8", "swagger-ui-express": "^5.0.1", "tsx": "^4.19.1" @@ -5669,6 +5670,36 @@ "license": "MIT", "optional": true }, + "node_modules/prompt-sync": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/prompt-sync/-/prompt-sync-4.2.0.tgz", + "integrity": "sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw==", + "license": "MIT", + "dependencies": { + "strip-ansi": "^5.0.0" + } + }, + "node_modules/prompt-sync/node_modules/ansi-regex": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/prompt-sync/node_modules/strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^4.1.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", diff --git a/package.json b/package.json index 0587423..fd3a312 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "express": "^4.21.0", "itty-router": "^5.0.18", "openai": "^4.63.0", + "prompt-sync": "^4.2.0", "swagger-jsdoc": "^6.2.8", "swagger-ui-express": "^5.0.1", "tsx": "^4.19.1" diff --git a/scratch/itty-router.js b/scratch/itty-router.js new file mode 100644 index 0000000..61180c8 --- /dev/null +++ b/scratch/itty-router.js @@ -0,0 +1,10 @@ +//h1 itty-router syntax +import { AutoRouter, html, IRequest, json, text } from "itty-router"; + +const router = AutoRouter(); + +router + .all("/go/*", hub.fetch) + .get('/', () => ({ message: "Router Path: './app'" })); + +//n3 one day. sigh. \ No newline at end of file diff --git a/src/app.ts b/src/app.ts index 4047a46..40c4430 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,42 +1,21 @@ //h1 SETUP import * as dotenv from 'dotenv'; - -import express, { Request, Response } from 'express'; -import { AutoRouter, html, IRequest, json, text } from "itty-router"; - +import express, { Request, Response, Router } from 'express'; import swaggerDocs from './swagger.js'; - -import { router as hub } from "./routes/router.js"; +import { router as routes } from "./routes/routes.js"; //h2 CONFIG dotenv.config(); const keys = { port: process.env.PORT }; - const app = express(); -const router = AutoRouter(); - +const router = express.Router(); swaggerDocs(app); //h1 ACTIVE -app.listen(keys.port, () => { - console.log(`Port ${keys.port}`) -}); +app.listen(keys.port, () => { console.log(`Port ${keys.port}`) }); //h2 Routers -router - .all("/go/*", hub.fetch) - .get('/', () => ({ message: "Router Path: './app'" })); - -//h3 Old Express Routers -/* app.get('/openai', (req: Request, res: Response) => { - res.send({ message: "Server --> OpenAI" }); -}); -app.get('/spotify', (req: Request, res: Response) => { - res.send({ message: "Server --> Spotify" }); -}); -app.get('/', (req: Request, res: Response) => { - res.send({ message: "Server --> Server" }); -}); */ +app.use(routes); //h1 EXPORT -export default router; \ No newline at end of file +export { router }; \ No newline at end of file diff --git a/src/controllers/index.ts b/src/controllers/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/controllers/openAI/index.ts b/src/controllers/openAI/extractEmotion.ts similarity index 58% rename from src/controllers/openAI/index.ts rename to src/controllers/openAI/extractEmotion.ts index 0be0be9..0aafe8a 100644 --- a/src/controllers/openAI/index.ts +++ b/src/controllers/openAI/extractEmotion.ts @@ -3,12 +3,8 @@ import dotenv from 'dotenv'; dotenv.config(); -// Initialize OpenAI with your API key from the environment variables -const openai = new OpenAI({ - apiKey: process.env.OPENAI_API_KEY, -}); +const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); -// Function to extract emotions from user input async function extractEmotionFromText(userInput: string): Promise { try { // Call the OpenAI Chat Completion API @@ -31,7 +27,15 @@ async function extractEmotionFromText(userInput: string): Promise { } // Example usage: - const userInput = "To be, or not to be, that is the question: Whether 'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune, Or to take Arms against a Sea of troubles, And by opposing end them: to die, to sleep;"; - extractEmotionFromText(userInput).then(emotion => { - console.log(`Extracted Emotion: ${emotion}`); - }); \ No newline at end of file +const demo = { + userInput: `To be, or not to be, that is the question: + Whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune, + Or to take Arms against a Sea of troubles, + And by opposing end them: to die, to sleep + ` +}; + +/* extractEmotionFromText(demo.userInput) + .then(emotion => { console.log(`Extracted Emotion: ${emotion}`)}); */ + +export { extractEmotionFromText } \ No newline at end of file diff --git a/src/controllers/server/index.ts b/src/controllers/server/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/controllers/spotify/index.ts b/src/controllers/spotify/searchGenre.ts similarity index 94% rename from src/controllers/spotify/index.ts rename to src/controllers/spotify/searchGenre.ts index 9e44eb4..5cf2c43 100644 --- a/src/controllers/spotify/index.ts +++ b/src/controllers/spotify/searchGenre.ts @@ -12,7 +12,7 @@ const sdk = SpotifyApi.withClientCredentials(clientId, clientSecret); console.log('Client ID:', clientId); // Define an async function to search tracks based on genre -async function searchGenre(genre: string) { +export async function searchGenre(genre: string) { try { console.log(`Searching for tracks in the genre: ${genre}`); @@ -35,4 +35,4 @@ async function searchGenre(genre: string) { } // Call the function with a specific genre (e.g., jazz) -searchGenre('rock'); +searchGenre('rock'); \ No newline at end of file diff --git a/src/controllers/user/getInput.ts b/src/controllers/user/getInput.ts new file mode 100644 index 0000000..99ffea6 --- /dev/null +++ b/src/controllers/user/getInput.ts @@ -0,0 +1,27 @@ +import promptSync from 'prompt-sync'; +import { userInput } from "../../types/userInput.js"; +const prompt = promptSync(); + +async function userInput() { + const mood: string = prompt(` + Tell me what happened on that date, and how you felt about it. + `); + + const genre: string = prompt(` + What genre of music would you like to feature on this playlist? + `); + + const userInput: userInput = { + eventDescription: mood, + musicGenre: genre, + date: new Date() + }; + + userInput.date.setFullYear(await prompt(`Type a 4 digit year`)) + userInput.date.setMonth(await prompt(`Type a 2 digit month`)); + userInput.date.setDate(await prompt(`Type a 2 digit day`)); + + return userInput; +} + +export { userInput }; \ No newline at end of file diff --git a/src/routes/playlist/router.ts b/src/controllers/user/showOutput.ts similarity index 58% rename from src/routes/playlist/router.ts rename to src/controllers/user/showOutput.ts index b9de0d2..2bd9404 100644 --- a/src/routes/playlist/router.ts +++ b/src/controllers/user/showOutput.ts @@ -1,6 +1,6 @@ -import { Router, Request, Response } from 'express'; - -const router = Router(); +import express, { Router, Request, Response } from 'express'; +import { searchGenre as generatePlaylist } from '../spotify/searchGenre.js'; +const router = express.Router(); /** * @openapi @@ -24,18 +24,13 @@ const router = Router(); * '400': * description: Invalid input */ -router.post('/playlist', async (req: Request, res: Response) => { - // Your implementation to handle the request - // Use your controllers to interact with OpenAI and Spotify APIs - try { - const userInput = req.body; - // Validate userInput based on your interface definitions - // Call your controller function + +function userOutput () {} + +router.get('/playlist', async (req: Request, res: Response) => { + const userInput = req.body; const playlist = await generatePlaylist(userInput); res.status(200).json(playlist); - } catch (error) { - res.status(400).json({ error: error.message }); - } }); -export default router; \ No newline at end of file +export { userOutput }; \ No newline at end of file diff --git a/src/models/spotify/searchGenre.ts b/src/models/spotify/searchGenre.ts new file mode 100644 index 0000000..5cf2c43 --- /dev/null +++ b/src/models/spotify/searchGenre.ts @@ -0,0 +1,38 @@ +import { SpotifyApi } from '@spotify/web-api-ts-sdk'; +import * as dotenv from 'dotenv'; + +dotenv.config(); + +// Access the client ID and secret from the .env file +const clientId = process.env.SPOTIFY_CLIENT_ID; +const clientSecret = process.env.SPOTIFY_CLIENT_SECRET; + +// Initialize the Spotify SDK using client credentials +const sdk = SpotifyApi.withClientCredentials(clientId, clientSecret); +console.log('Client ID:', clientId); + +// Define an async function to search tracks based on genre +export async function searchGenre(genre: string) { + try { + console.log(`Searching for tracks in the genre: ${genre}`); + + // Search for tracks by genre + const searchResults = await sdk.search(`genre:${genre}`, ['track']); + + // Check if any tracks are found + if (searchResults.tracks && searchResults.tracks.items.length > 0) { + searchResults.tracks.items.forEach((track, index) => { + console.log(`${index + 1}. ${track.name} by ${track.artists[0].name}`); + }); + } else { + console.log(`No tracks found for the genre: ${genre}`); + } + + return searchResults.tracks?.items; + } catch (error) { + console.error('Error fetching tracks by genre:', error); + } +} + +// Call the function with a specific genre (e.g., jazz) +searchGenre('rock'); \ No newline at end of file diff --git a/src/routes/internal/user.ts b/src/routes/internal/user.ts new file mode 100644 index 0000000..02f2d55 --- /dev/null +++ b/src/routes/internal/user.ts @@ -0,0 +1,13 @@ +//h1 IMPORT +import express, { Request, Response, Router } from "express"; + +import { userInput } from "../../controllers/user/getInput.js"; + +const app = express(); +const router = express.Router(); + +//h1 ACTIVE +//app.get userInput + +//h1 EXPORT +export { router }; diff --git a/src/routes/openAI/index.ts b/src/routes/openAI/index.ts new file mode 100644 index 0000000..b11a53b --- /dev/null +++ b/src/routes/openAI/index.ts @@ -0,0 +1,16 @@ +//h1 IMPORT +import express, { Request, Response, Router } from "express"; +import { extractEmotionFromText as parseMood } from "../../controllers/openAI/extractEmotion.js"; +import { userInput } from "../../controllers/user/getInput.js"; + +const app = express(); +const router = express.Router(); + +app.get("/openAI", async (req: Request, res: Response) => { + const input = await userInput(); + const output = await parseMood(input.eventDescription); + + return output; +}); + +export { router }; diff --git a/src/routes/router.ts b/src/routes/router.ts deleted file mode 100644 index 41de889..0000000 --- a/src/routes/router.ts +++ /dev/null @@ -1,19 +0,0 @@ -//h1 IMPORT -import { AutoRouter, html, IRequest, json, text } from "itty-router"; - -//h1 ROUTES -const router = AutoRouter({ base: "/go" }); - -router.get("/openai", ( req: IRequest ) => { - console.log("Router Path: ./routes/router:openai"); -}); - -router.get("/spotify", ( req: IRequest ) => { - console.log("Router Path: ./routes/router:spotify"); -}); - -router.get("/", ( req: IRequest ) => { - console.log("Router Path: ./routes/router:server"); -}); - -export { router }; \ No newline at end of file diff --git a/src/routes/routes.ts b/src/routes/routes.ts new file mode 100644 index 0000000..7c7abfd --- /dev/null +++ b/src/routes/routes.ts @@ -0,0 +1,16 @@ +//h1 IMPORT +import express, { Request, Response, Router } from "express"; + +import { router as openAI } from "./openAI/index.js"; +import { router as spotify } from "./spotify/index.js"; +import { router as user } from "./internal/user.js"; + +const app = express(); +const router = express.Router(); + +app.use(openAI); +app.use(spotify); +app.use(user); + +//h1 EXPORT +export { router }; \ No newline at end of file diff --git a/src/routes/spotify/index.ts b/src/routes/spotify/index.ts new file mode 100644 index 0000000..18a87ca --- /dev/null +++ b/src/routes/spotify/index.ts @@ -0,0 +1,15 @@ +//h1 IMPORT +import express, { Request, Response, Router } from 'express'; + +const app = express(); +const router = express.Router(); + +import { searchGenre } from '../../models/spotify/searchGenre.js'; +import { userInput } from '../../controllers/user/getInput.js'; + +app.get("/spotify", async (req: Request, res: Response) => { + const input = await userInput(); + const output = await searchGenre(input.musicGenre); +}); + +export { router }; \ No newline at end of file From 49d2ed7381b5c2bd7c0a0cb05bc25cec49000fc1 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sat, 28 Sep 2024 17:03:24 +0100 Subject: [PATCH 07/14] documentation --- docs/DATAFLOW.md | 5 +++-- docs/ROUTES.md | 42 +++++++++++++----------------------------- docs/folders | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 docs/folders diff --git a/docs/DATAFLOW.md b/docs/DATAFLOW.md index 3e6a8bf..4732a1f 100644 --- a/docs/DATAFLOW.md +++ b/docs/DATAFLOW.md @@ -16,16 +16,17 @@ subgraph tanya toOpenAI - openai fromOpenAI end + + openai subgraph gaj toSpotify - spotify fromSpotify end + spotify input --> inSEvent & inSGenre & inDDate inSEvent & inSGenre --> toOpenAI diff --git a/docs/ROUTES.md b/docs/ROUTES.md index 3e6a8bf..59f4999 100644 --- a/docs/ROUTES.md +++ b/docs/ROUTES.md @@ -1,40 +1,24 @@ # Routes Scratchpad ```mermaid - graph TD - - input + graph LR + input --> inSEvent & inSGenre & inDDate output - subgraph jason - inSEvent - inSGenre - inDDate - appApp - appOut + inSEvent --> toOpenAI + inSGenre --> toOpenAI + inDDate --> appApp + appApp --> toSpotify + appOut --> output end - subgraph tanya - toOpenAI - openai - fromOpenAI + toOpenAI --> openai + openai --> fromOpenAI + fromOpenAI --> appApp end - subgraph gaj - toSpotify - spotify - fromSpotify + toSpotify --> spotify + spotify --> fromSpotify + fromSpotify --> appOut end - - - input --> inSEvent & inSGenre & inDDate - inSEvent & inSGenre --> toOpenAI - toOpenAI --> openai - openai --> fromOpenAI - inDDate & fromOpenAI --> appApp - appApp --> toSpotify - toSpotify --> spotify - spotify --> fromSpotify - fromSpotify --> appOut - appOut --> output ``` diff --git a/docs/folders b/docs/folders new file mode 100644 index 0000000..d489594 --- /dev/null +++ b/docs/folders @@ -0,0 +1,34 @@ +src +├── app.ts +├── controllers +│ ├── openAI +│ │ └── extractEmotion.ts +│ ├── spotify +│ │ └── searchGenre.ts +│ └── user +│ ├── getInput.ts +│ └── showOutput.ts +├── data +│ ├── demo +│ │ └── album.json +│ └── schema +│ └── categories.json +├── models +│ ├── openai +│ └── spotify +│ └── searchGenre.ts +├── routes +│ ├── internal +│ │ └── user.ts +│ ├── openAI +│ │ └── index.ts +│ ├── routes.ts +│ └── spotify +│ └── index.ts +├── swagger.ts +└── types + ├── openaiQuery.ts + ├── openaiResponse.ts + ├── spotifyQuery.ts + ├── spotifyResponse.ts + └── userInput.ts From 734f13c63a2c24cb8fae76dedd4b4e427b34f1c8 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sat, 28 Sep 2024 17:31:37 +0100 Subject: [PATCH 08/14] json output tests on all routes --- docs/ROUTES.md | 26 +++---------------- src/app.ts | 2 +- .../{user => internal}/getInput.ts | 0 .../{user => internal}/showOutput.ts | 0 src/routes/external/openAI.ts | 19 ++++++++++++++ src/routes/external/spotify.ts | 18 +++++++++++++ src/routes/internal/dev.ts | 15 +++++++++++ src/routes/internal/transfer.ts | 15 +++++++++++ src/routes/internal/user.ts | 14 ++++++++-- src/routes/openAI/index.ts | 16 ------------ src/routes/routes.ts | 12 ++++++--- src/routes/spotify/index.ts | 15 ----------- 12 files changed, 92 insertions(+), 60 deletions(-) rename src/controllers/{user => internal}/getInput.ts (100%) rename src/controllers/{user => internal}/showOutput.ts (100%) create mode 100644 src/routes/external/openAI.ts create mode 100644 src/routes/external/spotify.ts create mode 100644 src/routes/internal/dev.ts create mode 100644 src/routes/internal/transfer.ts delete mode 100644 src/routes/openAI/index.ts delete mode 100644 src/routes/spotify/index.ts diff --git a/docs/ROUTES.md b/docs/ROUTES.md index 59f4999..b9c4a36 100644 --- a/docs/ROUTES.md +++ b/docs/ROUTES.md @@ -1,24 +1,6 @@ # Routes Scratchpad -```mermaid - graph LR - input --> inSEvent & inSGenre & inDDate - output - subgraph jason - inSEvent --> toOpenAI - inSGenre --> toOpenAI - inDDate --> appApp - appApp --> toSpotify - appOut --> output - end - subgraph tanya - toOpenAI --> openai - openai --> fromOpenAI - fromOpenAI --> appApp - end - subgraph gaj - toSpotify --> spotify - spotify --> fromSpotify - fromSpotify --> appOut - end -``` +- [ ] Get input from user +- [ ] Send input to OpenAI +- [ ] Send OpenAI Output & Date to Spotify +- [ ] Receive Spotify diff --git a/src/app.ts b/src/app.ts index 40c4430..109b813 100644 --- a/src/app.ts +++ b/src/app.ts @@ -12,7 +12,7 @@ const router = express.Router(); swaggerDocs(app); //h1 ACTIVE -app.listen(keys.port, () => { console.log(`Port ${keys.port}`) }); +app.listen(keys.port, () => { console.log(`Server Listening on Port ${keys.port}`) }); //h2 Routers app.use(routes); diff --git a/src/controllers/user/getInput.ts b/src/controllers/internal/getInput.ts similarity index 100% rename from src/controllers/user/getInput.ts rename to src/controllers/internal/getInput.ts diff --git a/src/controllers/user/showOutput.ts b/src/controllers/internal/showOutput.ts similarity index 100% rename from src/controllers/user/showOutput.ts rename to src/controllers/internal/showOutput.ts diff --git a/src/routes/external/openAI.ts b/src/routes/external/openAI.ts new file mode 100644 index 0000000..8401177 --- /dev/null +++ b/src/routes/external/openAI.ts @@ -0,0 +1,19 @@ +//h1 IMPORT +import express, { Request, Response, Router } from "express"; +import { extractEmotionFromText as parseMood } from "../../controllers/openAI/extractEmotion.js"; +import { userInput } from "../../controllers/internal/getInput.js"; + +const app = express(); +const router = express.Router(); + +app.get("/openAI/parseMood", async (req: Request, res: Response) => { + res.json( + { route: "/openAI/parseMood", purpose: "use userInput to extract emotion description" } + ); + // const input = await userInput(); + // const output = await parseMood(input.eventDescription); + + // return output; +}); + +export { router }; diff --git a/src/routes/external/spotify.ts b/src/routes/external/spotify.ts new file mode 100644 index 0000000..d7393c4 --- /dev/null +++ b/src/routes/external/spotify.ts @@ -0,0 +1,18 @@ +//h1 IMPORT +import express, { Request, Response, Router } from "express"; + +const app = express(); +const router = express.Router(); + +import { searchGenre } from "../../models/spotify/searchGenre.js"; +import { userInput } from "../../controllers/internal/getInput.js"; + +app.get("/spotify/searchGenre", async (req: Request, res: Response) => { + res.json( + { route: "searchGenre", purpose: "useOpenAI & Date to retrieve playlist" } + ); + // const input = await userInput(); + // const output = await searchGenre(input.musicGenre); +}); + +export { router }; diff --git a/src/routes/internal/dev.ts b/src/routes/internal/dev.ts new file mode 100644 index 0000000..c3d162b --- /dev/null +++ b/src/routes/internal/dev.ts @@ -0,0 +1,15 @@ +//h1 IMPORT +import express, { Request, Response, Router } from "express"; + +const app = express(); +const router = express.Router(); + +//h1 ACTIVE +app.get('/', (req: Request, res: Response) => { + res.json([ + { route: "dev test", purpose: "test router" } + ]) +}) + +//h1 EXPORT +export { router }; diff --git a/src/routes/internal/transfer.ts b/src/routes/internal/transfer.ts new file mode 100644 index 0000000..4a81e02 --- /dev/null +++ b/src/routes/internal/transfer.ts @@ -0,0 +1,15 @@ +//h1 IMPORT +import express, { Request, Response, Router } from "express"; + +const app = express(); +const router = express.Router(); + +//h1 ACTIVE +app.get('/internal/transfer', (req: Request, res: Response) => { + res.json([ + { route: "/internal/transfer", purpose: "send to Spotify" } + ]) +}) + +//h1 EXPORT +export { router }; diff --git a/src/routes/internal/user.ts b/src/routes/internal/user.ts index 02f2d55..9fea6f6 100644 --- a/src/routes/internal/user.ts +++ b/src/routes/internal/user.ts @@ -1,13 +1,23 @@ //h1 IMPORT import express, { Request, Response, Router } from "express"; -import { userInput } from "../../controllers/user/getInput.js"; +import { userInput } from "../../controllers/internal/getInput.js"; const app = express(); const router = express.Router(); //h1 ACTIVE -//app.get userInput +app.get('/internal/user/input', (req: Request, res: Response) => { + res.json([ + { route: "/internal/user/input", purpose: "get input from user" } + ]) +}); + +app.get('/internal/user/output', (req: Request, res: Response) => { + res.json([ + { route: "/internal/user/output", purpose: "display output to user" } + ]) +}); //h1 EXPORT export { router }; diff --git a/src/routes/openAI/index.ts b/src/routes/openAI/index.ts deleted file mode 100644 index b11a53b..0000000 --- a/src/routes/openAI/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -//h1 IMPORT -import express, { Request, Response, Router } from "express"; -import { extractEmotionFromText as parseMood } from "../../controllers/openAI/extractEmotion.js"; -import { userInput } from "../../controllers/user/getInput.js"; - -const app = express(); -const router = express.Router(); - -app.get("/openAI", async (req: Request, res: Response) => { - const input = await userInput(); - const output = await parseMood(input.eventDescription); - - return output; -}); - -export { router }; diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 7c7abfd..38aaf0e 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,16 +1,20 @@ //h1 IMPORT import express, { Request, Response, Router } from "express"; -import { router as openAI } from "./openAI/index.js"; -import { router as spotify } from "./spotify/index.js"; -import { router as user } from "./internal/user.js"; - const app = express(); const router = express.Router(); +import { router as dev } from "./internal/dev.js"; +import { router as transfer } from "./internal/transfer.js"; +import { router as user } from "./internal/user.js"; +import { router as openAI } from "./external/openAI.js"; +import { router as spotify } from "./external/spotify.js"; + +app.use(dev); app.use(openAI); app.use(spotify); app.use(user); +app.use(transfer); //h1 EXPORT export { router }; \ No newline at end of file diff --git a/src/routes/spotify/index.ts b/src/routes/spotify/index.ts deleted file mode 100644 index 18a87ca..0000000 --- a/src/routes/spotify/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -//h1 IMPORT -import express, { Request, Response, Router } from 'express'; - -const app = express(); -const router = express.Router(); - -import { searchGenre } from '../../models/spotify/searchGenre.js'; -import { userInput } from '../../controllers/user/getInput.js'; - -app.get("/spotify", async (req: Request, res: Response) => { - const input = await userInput(); - const output = await searchGenre(input.musicGenre); -}); - -export { router }; \ No newline at end of file From 6c748534d2f16754bf4316b94432d0349c50c67f Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sat, 28 Sep 2024 18:07:13 +0100 Subject: [PATCH 09/14] router test message in ./src/app --- package-lock.json | 3 +- src/app.ts | 25 +++++++++++++++++ src/controllers/spotify/searchGenre.ts | 2 +- src/models/spotify/searchGenre.ts | 38 -------------------------- src/routes/external/spotify.ts | 2 +- src/routes/internal/dev.ts | 10 +++---- src/routes/routes.ts | 10 +++++++ 7 files changed, 44 insertions(+), 46 deletions(-) delete mode 100644 src/models/spotify/searchGenre.ts diff --git a/package-lock.json b/package-lock.json index ba2c606..eb5f26b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1507,7 +1507,8 @@ "node_modules/@spotify/web-api-ts-sdk": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@spotify/web-api-ts-sdk/-/web-api-ts-sdk-1.2.0.tgz", - "integrity": "sha512-JUaebva3Ohwo5I5tuTqyW/FKGOMbb40YevJMySAOINRxP7qQ/AMjBzfJx0zeO6yS+wAPfQSoGNsZaUggHw8vsA==" + "integrity": "sha512-JUaebva3Ohwo5I5tuTqyW/FKGOMbb40YevJMySAOINRxP7qQ/AMjBzfJx0zeO6yS+wAPfQSoGNsZaUggHw8vsA==", + "license": "Apache" }, "node_modules/@tsconfig/node10": { "version": "1.0.11", diff --git a/src/app.ts b/src/app.ts index 109b813..ae351ee 100644 --- a/src/app.ts +++ b/src/app.ts @@ -17,5 +17,30 @@ app.listen(keys.port, () => { console.log(`Server Listening on Port ${keys.port} //h2 Routers app.use(routes); +//h2 Routes +app.get('/', (req: Request, res: Response) => { + res.json({ route: "/", message: "test router" }); +}) + +app.get('/routes', (req: Request, res: Response) => { + res.json({ route: "/routes", message: "test router" }); +}); + +app.get('/routes/internal/transfer', (req: Request, res: Response) => { + res.json({ route: "/routes/internal/transfer", message: "test router" }); +}) + +app.get('/routes/internal/user', (req: Request, res: Response) => { + res.json({ route: "/routes/internal/user", message: "test router" }); +}); + +app.get("/routes/external/openAI", (req: Request, res: Response) => { + res.json({ route: "/routes/external/openAI", message: "test router" }); +}); + +app.get("/routes/external/spotify", (req: Request, res: Response) => { + res.json({ route: "/routes/external/spotify", message: "test router" }); +}); + //h1 EXPORT export { router }; \ No newline at end of file diff --git a/src/controllers/spotify/searchGenre.ts b/src/controllers/spotify/searchGenre.ts index 5cf2c43..4903600 100644 --- a/src/controllers/spotify/searchGenre.ts +++ b/src/controllers/spotify/searchGenre.ts @@ -35,4 +35,4 @@ export async function searchGenre(genre: string) { } // Call the function with a specific genre (e.g., jazz) -searchGenre('rock'); \ No newline at end of file +// searchGenre('rock'); \ No newline at end of file diff --git a/src/models/spotify/searchGenre.ts b/src/models/spotify/searchGenre.ts deleted file mode 100644 index 5cf2c43..0000000 --- a/src/models/spotify/searchGenre.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { SpotifyApi } from '@spotify/web-api-ts-sdk'; -import * as dotenv from 'dotenv'; - -dotenv.config(); - -// Access the client ID and secret from the .env file -const clientId = process.env.SPOTIFY_CLIENT_ID; -const clientSecret = process.env.SPOTIFY_CLIENT_SECRET; - -// Initialize the Spotify SDK using client credentials -const sdk = SpotifyApi.withClientCredentials(clientId, clientSecret); -console.log('Client ID:', clientId); - -// Define an async function to search tracks based on genre -export async function searchGenre(genre: string) { - try { - console.log(`Searching for tracks in the genre: ${genre}`); - - // Search for tracks by genre - const searchResults = await sdk.search(`genre:${genre}`, ['track']); - - // Check if any tracks are found - if (searchResults.tracks && searchResults.tracks.items.length > 0) { - searchResults.tracks.items.forEach((track, index) => { - console.log(`${index + 1}. ${track.name} by ${track.artists[0].name}`); - }); - } else { - console.log(`No tracks found for the genre: ${genre}`); - } - - return searchResults.tracks?.items; - } catch (error) { - console.error('Error fetching tracks by genre:', error); - } -} - -// Call the function with a specific genre (e.g., jazz) -searchGenre('rock'); \ No newline at end of file diff --git a/src/routes/external/spotify.ts b/src/routes/external/spotify.ts index d7393c4..9ea9ec6 100644 --- a/src/routes/external/spotify.ts +++ b/src/routes/external/spotify.ts @@ -4,7 +4,7 @@ import express, { Request, Response, Router } from "express"; const app = express(); const router = express.Router(); -import { searchGenre } from "../../models/spotify/searchGenre.js"; +import { searchGenre } from "../../controllers/spotify/searchGenre.js"; import { userInput } from "../../controllers/internal/getInput.js"; app.get("/spotify/searchGenre", async (req: Request, res: Response) => { diff --git a/src/routes/internal/dev.ts b/src/routes/internal/dev.ts index c3d162b..67a9013 100644 --- a/src/routes/internal/dev.ts +++ b/src/routes/internal/dev.ts @@ -5,11 +5,11 @@ const app = express(); const router = express.Router(); //h1 ACTIVE -app.get('/', (req: Request, res: Response) => { - res.json([ - { route: "dev test", purpose: "test router" } - ]) -}) +// app.get('/', (req: Request, res: Response) => { +// res.json([ +// { route: "dev test", purpose: "test router" } +// ]) +// }); //h1 EXPORT export { router }; diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 38aaf0e..deeedb1 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -16,5 +16,15 @@ app.use(spotify); app.use(user); app.use(transfer); +app.get('/routes', (req: Request, res: Response) => { + res.json([ + { + route: "/routes/", + path: "./routes/routes", + purpose: "test router" + } + ]) +}); + //h1 EXPORT export { router }; \ No newline at end of file From e998ebee93323298b1a9848a6ac8a4569b75fe73 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sat, 28 Sep 2024 19:01:43 +0100 Subject: [PATCH 10/14] fix(routers): Basic Structure - Routers mounted correctly - Test messages within each router --- src/app.ts | 60 +++++++++++++++++++-------------- src/routes/external/openAI.ts | 24 +++++++------ src/routes/external/spotify.ts | 23 +++++++------ src/routes/internal/dev.ts | 15 --------- src/routes/internal/transfer.ts | 13 ++++--- src/routes/internal/user.ts | 24 ++++++------- src/routes/routes.ts | 30 ++++++----------- 7 files changed, 86 insertions(+), 103 deletions(-) delete mode 100644 src/routes/internal/dev.ts diff --git a/src/app.ts b/src/app.ts index ae351ee..288c008 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,44 +2,52 @@ import * as dotenv from 'dotenv'; import express, { Request, Response, Router } from 'express'; import swaggerDocs from './swagger.js'; -import { router as routes } from "./routes/routes.js"; +import { router as hub } from "./routes/routes.js"; //h2 CONFIG dotenv.config(); const keys = { port: process.env.PORT }; const app = express(); -const router = express.Router(); +const router = Router(); swaggerDocs(app); //h1 ACTIVE -app.listen(keys.port, () => { console.log(`Server Listening on Port ${keys.port}`) }); +app.listen(keys.port, () => { + console.log(`Server Listening on Port ${keys.port}`) +}); //h2 Routers -app.use(routes); +app.use('/api', hub); -//h2 Routes +//h2 Endpoints app.get('/', (req: Request, res: Response) => { - res.json({ route: "/", message: "test router" }); -}) - -app.get('/routes', (req: Request, res: Response) => { - res.json({ route: "/routes", message: "test router" }); -}); - -app.get('/routes/internal/transfer', (req: Request, res: Response) => { - res.json({ route: "/routes/internal/transfer", message: "test router" }); -}) - -app.get('/routes/internal/user', (req: Request, res: Response) => { - res.json({ route: "/routes/internal/user", message: "test router" }); -}); - -app.get("/routes/external/openAI", (req: Request, res: Response) => { - res.json({ route: "/routes/external/openAI", message: "test router" }); -}); - -app.get("/routes/external/spotify", (req: Request, res: Response) => { - res.json({ route: "/routes/external/spotify", message: "test router" }); + res.json({ + message: "Welcome to the API", + endpoints: [ + { + path: "/api", + description: "API root", + subRoutes: [ + { + path: "/openAI", + description: "OpenAI-related endpoints" + }, + { + path: "/spotify", + description: "Spotify-related endpoints" + }, + { + path: "/user", + description: "User-related endpoints" + }, + { + path: "/transfer", + description: "Transfer-related endpoints" + } + ] + } + ] + }); }); //h1 EXPORT diff --git a/src/routes/external/openAI.ts b/src/routes/external/openAI.ts index 8401177..c91eb59 100644 --- a/src/routes/external/openAI.ts +++ b/src/routes/external/openAI.ts @@ -1,19 +1,21 @@ //h1 IMPORT -import express, { Request, Response, Router } from "express"; -import { extractEmotionFromText as parseMood } from "../../controllers/openAI/extractEmotion.js"; -import { userInput } from "../../controllers/internal/getInput.js"; +import { Request, Response, Router } from "express"; +// import { extractEmotionFromText as parseMood } from "../../controllers/openAI/extractEmotion.js"; +// import { userInput } from "../../controllers/internal/getInput.js"; -const app = express(); -const router = express.Router(); +const router = Router(); -app.get("/openAI/parseMood", async (req: Request, res: Response) => { +router.get("/test", (req: Request, res: Response) => { res.json( - { route: "/openAI/parseMood", purpose: "use userInput to extract emotion description" } + { route: "/api/openAI/test", message: "openAI Router" } ); - // const input = await userInput(); - // const output = await parseMood(input.eventDescription); - - // return output; }); +/* router.get("/parseMood", async (req: Request, res: Response) => { + const input = await userInput(); + const output = await parseMood(input.eventDescription); + + return output; +}); */ + export { router }; diff --git a/src/routes/external/spotify.ts b/src/routes/external/spotify.ts index 9ea9ec6..0645572 100644 --- a/src/routes/external/spotify.ts +++ b/src/routes/external/spotify.ts @@ -1,18 +1,19 @@ //h1 IMPORT -import express, { Request, Response, Router } from "express"; +import { Request, Response, Router } from "express"; +// import { searchGenre } from "../../controllers/spotify/searchGenre.js"; +// import { userInput } from "../../controllers/internal/getInput.js"; -const app = express(); -const router = express.Router(); +const router = Router(); -import { searchGenre } from "../../controllers/spotify/searchGenre.js"; -import { userInput } from "../../controllers/internal/getInput.js"; - -app.get("/spotify/searchGenre", async (req: Request, res: Response) => { +router.get("/test", (req: Request, res: Response) => { res.json( - { route: "searchGenre", purpose: "useOpenAI & Date to retrieve playlist" } - ); - // const input = await userInput(); - // const output = await searchGenre(input.musicGenre); + { route: "/api/spotify/test", message: "Spotify Router" } + ); }); +/* router.get("/searchGenre", async (req: Request, res: Response) => { + const input = await userInput(); + const output = await searchGenre(input.musicGenre); +}); */ + export { router }; diff --git a/src/routes/internal/dev.ts b/src/routes/internal/dev.ts deleted file mode 100644 index 67a9013..0000000 --- a/src/routes/internal/dev.ts +++ /dev/null @@ -1,15 +0,0 @@ -//h1 IMPORT -import express, { Request, Response, Router } from "express"; - -const app = express(); -const router = express.Router(); - -//h1 ACTIVE -// app.get('/', (req: Request, res: Response) => { -// res.json([ -// { route: "dev test", purpose: "test router" } -// ]) -// }); - -//h1 EXPORT -export { router }; diff --git a/src/routes/internal/transfer.ts b/src/routes/internal/transfer.ts index 4a81e02..46d9bbd 100644 --- a/src/routes/internal/transfer.ts +++ b/src/routes/internal/transfer.ts @@ -1,14 +1,13 @@ //h1 IMPORT -import express, { Request, Response, Router } from "express"; +import { Request, Response, Router } from "express"; -const app = express(); -const router = express.Router(); +const router = Router(); //h1 ACTIVE -app.get('/internal/transfer', (req: Request, res: Response) => { - res.json([ - { route: "/internal/transfer", purpose: "send to Spotify" } - ]) +router.get('/test', (req: Request, res: Response) => { + res.json([ + { route: "/api/transfer/test", purpose: "transfer Router" } + ]) }) //h1 EXPORT diff --git a/src/routes/internal/user.ts b/src/routes/internal/user.ts index 9fea6f6..812975d 100644 --- a/src/routes/internal/user.ts +++ b/src/routes/internal/user.ts @@ -1,23 +1,19 @@ //h1 IMPORT -import express, { Request, Response, Router } from "express"; +import { Request, Response, Router } from "express"; +// import { userInput } from "../../controllers/internal/getInput.js"; -import { userInput } from "../../controllers/internal/getInput.js"; - -const app = express(); -const router = express.Router(); +const router = Router(); //h1 ACTIVE -app.get('/internal/user/input', (req: Request, res: Response) => { - res.json([ - { route: "/internal/user/input", purpose: "get input from user" } - ]) +router.get("/test", (req: Request, res: Response) => { + res.json( + { route: "/api/user/test", message: "User Router" } + ); }); -app.get('/internal/user/output', (req: Request, res: Response) => { - res.json([ - { route: "/internal/user/output", purpose: "display output to user" } - ]) -}); +/* router.get('/input', (req: Request, res: Response) => {}); */ + +/* router.get('/output', (req: Request, res: Response) => {}); */ //h1 EXPORT export { router }; diff --git a/src/routes/routes.ts b/src/routes/routes.ts index deeedb1..ef9be11 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,29 +1,21 @@ //h1 IMPORT -import express, { Request, Response, Router } from "express"; - -const app = express(); -const router = express.Router(); - -import { router as dev } from "./internal/dev.js"; +import { Request, Response, Router } from "express"; import { router as transfer } from "./internal/transfer.js"; import { router as user } from "./internal/user.js"; import { router as openAI } from "./external/openAI.js"; import { router as spotify } from "./external/spotify.js"; -app.use(dev); -app.use(openAI); -app.use(spotify); -app.use(user); -app.use(transfer); +const router = Router(); + +//h1 Router +router.use('/openAI', openAI); +router.use('/spotify', spotify); +router.use('/user', user); +router.use('/transfer', transfer); -app.get('/routes', (req: Request, res: Response) => { - res.json([ - { - route: "/routes/", - path: "./routes/routes", - purpose: "test router" - } - ]) +//h2 Routes +router.get('/', (req: Request, res: Response) => { + res.json({ route: "/api/", message: "Hub Router" }); }); //h1 EXPORT From 55431bf593e1925ba2b99ed84e909b5112bf7a73 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sat, 28 Sep 2024 19:06:33 +0100 Subject: [PATCH 11/14] feat(routers): HTML Endpoint Menu Opening localhost in the browser returns a linklist --- src/app.ts | 40 +++++++++++---------------------- src/routes/external/openAI.ts | 4 ++-- src/routes/external/spotify.ts | 4 ++-- src/routes/internal/transfer.ts | 4 ++-- src/routes/internal/user.ts | 4 ++-- 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/app.ts b/src/app.ts index 288c008..3fa6845 100644 --- a/src/app.ts +++ b/src/app.ts @@ -21,33 +21,19 @@ app.use('/api', hub); //h2 Endpoints app.get('/', (req: Request, res: Response) => { - res.json({ - message: "Welcome to the API", - endpoints: [ - { - path: "/api", - description: "API root", - subRoutes: [ - { - path: "/openAI", - description: "OpenAI-related endpoints" - }, - { - path: "/spotify", - description: "Spotify-related endpoints" - }, - { - path: "/user", - description: "User-related endpoints" - }, - { - path: "/transfer", - description: "Transfer-related endpoints" - } - ] - } - ] - }); + res.send(` +

MoodTime

+

Available Endpoints:

+ + `); }); //h1 EXPORT diff --git a/src/routes/external/openAI.ts b/src/routes/external/openAI.ts index c91eb59..39b49b4 100644 --- a/src/routes/external/openAI.ts +++ b/src/routes/external/openAI.ts @@ -5,9 +5,9 @@ import { Request, Response, Router } from "express"; const router = Router(); -router.get("/test", (req: Request, res: Response) => { +router.get("/", (req: Request, res: Response) => { res.json( - { route: "/api/openAI/test", message: "openAI Router" } + { route: "/api/openAI/", message: "openAI Router" } ); }); diff --git a/src/routes/external/spotify.ts b/src/routes/external/spotify.ts index 0645572..b90f689 100644 --- a/src/routes/external/spotify.ts +++ b/src/routes/external/spotify.ts @@ -5,9 +5,9 @@ import { Request, Response, Router } from "express"; const router = Router(); -router.get("/test", (req: Request, res: Response) => { +router.get("/", (req: Request, res: Response) => { res.json( - { route: "/api/spotify/test", message: "Spotify Router" } + { route: "/api/spotify/", message: "Spotify Router" } ); }); diff --git a/src/routes/internal/transfer.ts b/src/routes/internal/transfer.ts index 46d9bbd..2e530f1 100644 --- a/src/routes/internal/transfer.ts +++ b/src/routes/internal/transfer.ts @@ -4,9 +4,9 @@ import { Request, Response, Router } from "express"; const router = Router(); //h1 ACTIVE -router.get('/test', (req: Request, res: Response) => { +router.get('/', (req: Request, res: Response) => { res.json([ - { route: "/api/transfer/test", purpose: "transfer Router" } + { route: "/api/transfer/", purpose: "transfer Router" } ]) }) diff --git a/src/routes/internal/user.ts b/src/routes/internal/user.ts index 812975d..aeaabde 100644 --- a/src/routes/internal/user.ts +++ b/src/routes/internal/user.ts @@ -5,9 +5,9 @@ import { Request, Response, Router } from "express"; const router = Router(); //h1 ACTIVE -router.get("/test", (req: Request, res: Response) => { +router.get("/", (req: Request, res: Response) => { res.json( - { route: "/api/user/test", message: "User Router" } + { route: "/api/user/", message: "User Router" } ); }); From 6bf8a79340303b5859a427f924a792e264fda879 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sat, 28 Sep 2024 19:32:05 +0100 Subject: [PATCH 12/14] feat(router): allow `npm run dev` to start a nodemon instance **Instructions** - `npm install` - `npm run dev` will: - run the project directly without compiling - restart if you make any changes to the code, allowing you to see changes in realtime **Packages** - New Installs - `@types/prompt-sync` - Updates - `@types/node`: `22.5.5 --> 22.7.4` - `tsx`: `dependencies --> devDependencies` **Configuration Changes** - `tsconfig.json` - target: `es2016 --> es2020` - module: `NodeNext --> ESNext` - strict: `false --> true` - `nodemon.json` - exec: `"ts-node --esm -r tsconfig-paths/register ./src/app.ts" --> "tsx src/app.ts"` BREAKING CHANGE: --- nodemon.json | 2 +- package-lock.json | 49 +++++++++++++++++--- package.json | 10 ++-- src/controllers/{internal => }/getInput.ts | 8 ++-- src/controllers/{internal => }/showOutput.ts | 0 tsconfig.json | 12 ++--- 6 files changed, 58 insertions(+), 23 deletions(-) rename src/controllers/{internal => }/getInput.ts (63%) rename src/controllers/{internal => }/showOutput.ts (100%) diff --git a/nodemon.json b/nodemon.json index 502d93b..4cc6d6a 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,5 +1,5 @@ { "watch": ["src"], "ext": "ts", - "exec": "ts-node --esm -r tsconfig-paths/register ./src/app.ts" + "exec": "tsx src/app.ts" } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index eb5f26b..569dfbf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,8 +16,7 @@ "openai": "^4.63.0", "prompt-sync": "^4.2.0", "swagger-jsdoc": "^6.2.8", - "swagger-ui-express": "^5.0.1", - "tsx": "^4.19.1" + "swagger-ui-express": "^5.0.1" }, "devDependencies": { "@definitelytyped/dtslint": "^0.2.23", @@ -25,7 +24,8 @@ "@tsconfig/node20": "^20.1.4", "@types/dotenv": "^6.1.1", "@types/express": "^4.17.21", - "@types/node": "^22.5.5", + "@types/node": "^22.7.4", + "@types/prompt-sync": "^4.2.3", "@types/swagger-jsdoc": "^6.0.4", "@types/swagger-ui-express": "^4.1.6", "eslint": "^9.11.0", @@ -34,6 +34,7 @@ "prettier": "^3.3.3", "ts-node": "^10.9.2", "tsconfig-paths": "^4.2.0", + "tsx": "^4.19.1", "typescript": "^5.6.2", "typescript-eslint": "^8.6.0" } @@ -836,6 +837,7 @@ "cpu": [ "ppc64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -852,6 +854,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -868,6 +871,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -884,6 +888,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -900,6 +905,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -916,6 +922,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -932,6 +939,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -948,6 +956,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -964,6 +973,7 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -980,6 +990,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -996,6 +1007,7 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1012,6 +1024,7 @@ "cpu": [ "loong64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1028,6 +1041,7 @@ "cpu": [ "mips64el" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1044,6 +1058,7 @@ "cpu": [ "ppc64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1060,6 +1075,7 @@ "cpu": [ "riscv64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1076,6 +1092,7 @@ "cpu": [ "s390x" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1092,6 +1109,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1108,6 +1126,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1124,6 +1143,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1140,6 +1160,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1156,6 +1177,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1172,6 +1194,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1188,6 +1211,7 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1204,6 +1228,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1630,9 +1655,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.5.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", - "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", + "version": "22.7.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.4.tgz", + "integrity": "sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==", "license": "MIT", "dependencies": { "undici-types": "~6.19.2" @@ -1662,6 +1687,13 @@ "node": ">= 6" } }, + "node_modules/@types/prompt-sync": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/@types/prompt-sync/-/prompt-sync-4.2.3.tgz", + "integrity": "sha512-Ox77gCSx0YyeakGt/qfOZUSFNSSi+sh3ABoGOiCwiO2KODx492BJnUm9oIXS+AHJtqp12iM4RduY6viTJ9bYwA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/qs": { "version": "6.9.16", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.16.tgz", @@ -3211,6 +3243,7 @@ "version": "0.23.1", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", + "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { @@ -3841,6 +3874,7 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -4004,6 +4038,7 @@ "version": "4.8.1", "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", + "dev": true, "license": "MIT", "dependencies": { "resolve-pkg-maps": "^1.0.0" @@ -5937,6 +5972,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, "license": "MIT", "funding": { "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" @@ -6815,6 +6851,7 @@ "version": "4.19.1", "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.1.tgz", "integrity": "sha512-0flMz1lh74BR4wOvBjuh9olbnwqCPc35OOlfyzHba0Dc+QNUeWX/Gq2YTbnwcWPO3BMd8fkzRVrHcsR+a7z7rA==", + "dev": true, "license": "MIT", "dependencies": { "esbuild": "~0.23.0", diff --git a/package.json b/package.json index fd3a312..994790e 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,10 @@ "description": "A thing that will, at some point, do a thing.", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", "dtslint": "dtslint types", "compile": "npx tsc", "server": "node dist/app.js", - "dev": "nodemon" + "dev": "nodemon --exec tsx src/app.ts" }, "keywords": [], "author": "", @@ -20,7 +19,8 @@ "@tsconfig/node20": "^20.1.4", "@types/dotenv": "^6.1.1", "@types/express": "^4.17.21", - "@types/node": "^22.5.5", + "@types/node": "^22.7.4", + "@types/prompt-sync": "^4.2.3", "@types/swagger-jsdoc": "^6.0.4", "@types/swagger-ui-express": "^4.1.6", "eslint": "^9.11.0", @@ -29,6 +29,7 @@ "prettier": "^3.3.3", "ts-node": "^10.9.2", "tsconfig-paths": "^4.2.0", + "tsx": "^4.19.1", "typescript": "^5.6.2", "typescript-eslint": "^8.6.0" }, @@ -40,7 +41,6 @@ "openai": "^4.63.0", "prompt-sync": "^4.2.0", "swagger-jsdoc": "^6.2.8", - "swagger-ui-express": "^5.0.1", - "tsx": "^4.19.1" + "swagger-ui-express": "^5.0.1" } } diff --git a/src/controllers/internal/getInput.ts b/src/controllers/getInput.ts similarity index 63% rename from src/controllers/internal/getInput.ts rename to src/controllers/getInput.ts index 99ffea6..bc09073 100644 --- a/src/controllers/internal/getInput.ts +++ b/src/controllers/getInput.ts @@ -1,5 +1,5 @@ import promptSync from 'prompt-sync'; -import { userInput } from "../../types/userInput.js"; +import { userInput } from "../types/userInput.js"; const prompt = promptSync(); async function userInput() { @@ -17,9 +17,9 @@ async function userInput() { date: new Date() }; - userInput.date.setFullYear(await prompt(`Type a 4 digit year`)) - userInput.date.setMonth(await prompt(`Type a 2 digit month`)); - userInput.date.setDate(await prompt(`Type a 2 digit day`)); + userInput.date.setFullYear(parseInt(await prompt(`Type a 4 digit year`), 10)); + userInput.date.setMonth(parseInt(await prompt(`Type a 2 digit month`), 10)); + userInput.date.setDate(parseInt(await prompt(`Type a 2 digit day`), 10)); return userInput; } diff --git a/src/controllers/internal/showOutput.ts b/src/controllers/showOutput.ts similarity index 100% rename from src/controllers/internal/showOutput.ts rename to src/controllers/showOutput.ts diff --git a/tsconfig.json b/tsconfig.json index 9de6a27..687f2b4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,16 @@ { "compilerOptions": { - "target": "es2016", - "module": "NodeNext", - "moduleResolution": "NodeNext", - // "allowJs": true, - // "checkJs": true, + "target": "ES2020", + "module": "ESNext", + "moduleResolution": "Node", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, - "strict": false, + "strict": true, "skipLibCheck": true, "outDir": "dist", "rootDir": "./src", "resolveJsonModule": true }, "include": ["src"], - "exclude": ["node_modules", "dist", "docs", ".github", ".vscode", ".gitignore", ".prettierrc.json", "eslint.config.mjs", "package-lock.json", "package.json", "README.md"] + "exclude": ["node_modules", "dist"] } From 3fe30c6d7db584b797e91fc08609c06ef17a110a Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sun, 29 Sep 2024 16:24:47 +0100 Subject: [PATCH 13/14] delete old routes doc & itty-route file --- docs/ROUTES.md | 6 ------ scratch/itty-router.js | 10 ---------- 2 files changed, 16 deletions(-) delete mode 100644 docs/ROUTES.md delete mode 100644 scratch/itty-router.js diff --git a/docs/ROUTES.md b/docs/ROUTES.md deleted file mode 100644 index b9c4a36..0000000 --- a/docs/ROUTES.md +++ /dev/null @@ -1,6 +0,0 @@ -# Routes Scratchpad - -- [ ] Get input from user -- [ ] Send input to OpenAI -- [ ] Send OpenAI Output & Date to Spotify -- [ ] Receive Spotify diff --git a/scratch/itty-router.js b/scratch/itty-router.js deleted file mode 100644 index 61180c8..0000000 --- a/scratch/itty-router.js +++ /dev/null @@ -1,10 +0,0 @@ -//h1 itty-router syntax -import { AutoRouter, html, IRequest, json, text } from "itty-router"; - -const router = AutoRouter(); - -router - .all("/go/*", hub.fetch) - .get('/', () => ({ message: "Router Path: './app'" })); - -//n3 one day. sigh. \ No newline at end of file From 0d43f53a054b4ee155d4b552009e6cd14c6bcc64 Mon Sep 17 00:00:00 2001 From: Jason Warren Date: Sun, 29 Sep 2024 16:42:30 +0100 Subject: [PATCH 14/14] Remove redundant import from showOutput --- src/controllers/showOutput.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/showOutput.ts b/src/controllers/showOutput.ts index 2bd9404..9d372c4 100644 --- a/src/controllers/showOutput.ts +++ b/src/controllers/showOutput.ts @@ -1,5 +1,5 @@ -import express, { Router, Request, Response } from 'express'; -import { searchGenre as generatePlaylist } from '../spotify/searchGenre.js'; +import express, { Request, Response } from 'express'; +import { searchGenre as generatePlaylist } from './spotify/searchGenre.js'; const router = express.Router(); /**