From f070678960143d850382d0eb567002b0ff861936 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Sun, 9 Feb 2025 18:26:53 +0000 Subject: [PATCH] feat: set up api architecture with initial route --- src/controllers/EntriesController.js | 11 +++++++++++ src/index.js | 11 +++++++++++ src/routes/entries.js | 12 ++++++++++++ src/services/EntriesService.js | 7 +++++++ 4 files changed, 41 insertions(+) create mode 100644 src/controllers/EntriesController.js create mode 100644 src/index.js create mode 100644 src/routes/entries.js create mode 100644 src/services/EntriesService.js diff --git a/src/controllers/EntriesController.js b/src/controllers/EntriesController.js new file mode 100644 index 0000000..1e3be4f --- /dev/null +++ b/src/controllers/EntriesController.js @@ -0,0 +1,11 @@ +export class EntriesController { + entriesService + + constructor(entriesService) { + this.entriesService = entriesService + } + + getEntry = async (req, res) => { + const response = await this.entriesService.getEntry() + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..68b64b8 --- /dev/null +++ b/src/index.js @@ -0,0 +1,11 @@ +import express from "express" +import entries from "./routes/entries" +const app = express() +const port = 3000 + +app.use(express.json()) +app.use("/entries", entries) + +app.listen(port, () => { + console.info(`INFO Server running at http://localhost:${port}`) +}) diff --git a/src/routes/entries.js b/src/routes/entries.js new file mode 100644 index 0000000..513278d --- /dev/null +++ b/src/routes/entries.js @@ -0,0 +1,12 @@ +import express from "express" +import { EntriesService } from "../services/EntriesService" +import { EntriesController } from "../controllers/EntriesController" +import { EntriesService } from "../services/EntriesService" + +const router = express.Router() +const entriesService = new EntriesService() +const entriesController = new EntriesController(entriesService) + +router.get("/:entry", entriesController.getEntry) + +export default router diff --git a/src/services/EntriesService.js b/src/services/EntriesService.js new file mode 100644 index 0000000..5a47c6d --- /dev/null +++ b/src/services/EntriesService.js @@ -0,0 +1,7 @@ +export class EntriesService { + // TODO add DatabaseConnectorService + + getEntry = async () => { + return "API is working" + } +}