From bcce03dc4a6adfe2023f99c058f2d2a6b4e6d7a2 Mon Sep 17 00:00:00 2001 From: Rash Date: Sun, 11 Aug 2024 13:13:53 +0100 Subject: [PATCH] |#4 | @rashjredmund | did api versioning and updated landing page in API base route --- .husky/pre-commit | 3 -- README.md | 49 +++++++++++++------ public/main.html | 29 +++++++++-- src/api/v1/index.ts | 18 +++++++ src/{ => api/v1}/middlewares/index.ts | 0 .../v1}/modules/auth/auth.controller.ts | 0 src/{ => api/v1}/modules/auth/auth.service.ts | 0 .../modules/languages/language.controller.ts | 0 .../v1}/modules/languages/language.service.ts | 0 .../v1}/modules/match/match.controller.ts | 0 .../v1}/modules/match/match.service.ts | 0 src/{ => api/v1}/routes/auth-router.ts | 0 src/{ => api/v1}/routes/language-router.ts | 0 src/{ => api/v1}/routes/match-router.ts | 0 src/api/v2/index.ts | 17 +++++++ src/server/index.ts | 8 +-- 16 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 src/api/v1/index.ts rename src/{ => api/v1}/middlewares/index.ts (100%) rename src/{ => api/v1}/modules/auth/auth.controller.ts (100%) rename src/{ => api/v1}/modules/auth/auth.service.ts (100%) rename src/{ => api/v1}/modules/languages/language.controller.ts (100%) rename src/{ => api/v1}/modules/languages/language.service.ts (100%) rename src/{ => api/v1}/modules/match/match.controller.ts (100%) rename src/{ => api/v1}/modules/match/match.service.ts (100%) rename src/{ => api/v1}/routes/auth-router.ts (100%) rename src/{ => api/v1}/routes/language-router.ts (100%) rename src/{ => api/v1}/routes/match-router.ts (100%) create mode 100644 src/api/v2/index.ts diff --git a/.husky/pre-commit b/.husky/pre-commit index 14ccce4..1382386 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - npm run pre-commit \ No newline at end of file diff --git a/README.md b/README.md index a60b58f..61fd988 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # wiki-lex-match -__table of content__ +**table of content** - [local setup](#setup-repo-locally) - [how to render the](#how-to-render-the-documentation) @@ -9,7 +9,7 @@ __table of content__ ## setup repo locally - Clone repo with - + ```bash git clone git@github.com:Wikidata-Cameroon/WMA_HackKmer_Yaounde_Backend.git wiki-lex-match-backend ``` @@ -20,27 +20,48 @@ __table of content__ cd wiki-lex-match-backend ``` +- Run the following command on your terminal to install packages and dependencies with npm + + ```bash + npm install + # or npm i for short + ``` + +### Note + +- If you do not have node or npm installed to your machine, download and install the runtime from [node](https://nodejs.org/en/download/package-manager) + ## How to start server - Start local server in watch mode - ```bash - npm run dev - ``` + ```bash + npm run dev + ``` + +- Generate Project Build -- Build to js + ```bash + npm run build + ``` - ```bash - npm run build - ``` +- Visit API locally through + + ```bash + http://localhost/8080 + + # You can navigate to API version 1 (the current latest version) + http://localhost/8080/api/v1 + ``` ## Contributing -- __Git flow__ +- **Git flow** - Branches should be name with `feature/` format - Writing commits + - Commit messages should follow the for mat `# | | ` - @example is `"|#1 | @rashjredmund | installed express and configured base project template. setup hustky, prettier, and eslint. also updated readme file"` @@ -59,8 +80,8 @@ __table of content__ - Always assign the PR to yourself and your team-mate -- __Building__ - +- **Building** + - Navigate to `src/modules/` to start contributing - Set up your routes in the `src/route/*` directory in the right file or add one if need be @@ -69,6 +90,6 @@ __table of content__ | -___ +--- -__Happy Coding Everyone 🚀__ +**Happy Coding Everyone 🚀** diff --git a/public/main.html b/public/main.html index 7d043dc..86febf3 100644 --- a/public/main.html +++ b/public/main.html @@ -42,10 +42,31 @@

target="_blank">@rebase code camp

- - API docs - + diff --git a/src/api/v1/index.ts b/src/api/v1/index.ts new file mode 100644 index 0000000..1b9376d --- /dev/null +++ b/src/api/v1/index.ts @@ -0,0 +1,18 @@ +import { Router } from "express"; +import { authRouter } from "./routes/auth-router"; +import { languageRouter } from "./routes/language-router"; +import { matchRouter } from "./routes/match-router"; + +const routerV1 = Router(); + +routerV1.get("/", (_, res) => { + return res.status(200).json({ + message: "🚀 wiki-lex-match V1 🚀", + }); +}); + +routerV1.use("/auth", authRouter); +routerV1.use("/languages", languageRouter); +routerV1.use("/match", matchRouter); + +export default routerV1; diff --git a/src/middlewares/index.ts b/src/api/v1/middlewares/index.ts similarity index 100% rename from src/middlewares/index.ts rename to src/api/v1/middlewares/index.ts diff --git a/src/modules/auth/auth.controller.ts b/src/api/v1/modules/auth/auth.controller.ts similarity index 100% rename from src/modules/auth/auth.controller.ts rename to src/api/v1/modules/auth/auth.controller.ts diff --git a/src/modules/auth/auth.service.ts b/src/api/v1/modules/auth/auth.service.ts similarity index 100% rename from src/modules/auth/auth.service.ts rename to src/api/v1/modules/auth/auth.service.ts diff --git a/src/modules/languages/language.controller.ts b/src/api/v1/modules/languages/language.controller.ts similarity index 100% rename from src/modules/languages/language.controller.ts rename to src/api/v1/modules/languages/language.controller.ts diff --git a/src/modules/languages/language.service.ts b/src/api/v1/modules/languages/language.service.ts similarity index 100% rename from src/modules/languages/language.service.ts rename to src/api/v1/modules/languages/language.service.ts diff --git a/src/modules/match/match.controller.ts b/src/api/v1/modules/match/match.controller.ts similarity index 100% rename from src/modules/match/match.controller.ts rename to src/api/v1/modules/match/match.controller.ts diff --git a/src/modules/match/match.service.ts b/src/api/v1/modules/match/match.service.ts similarity index 100% rename from src/modules/match/match.service.ts rename to src/api/v1/modules/match/match.service.ts diff --git a/src/routes/auth-router.ts b/src/api/v1/routes/auth-router.ts similarity index 100% rename from src/routes/auth-router.ts rename to src/api/v1/routes/auth-router.ts diff --git a/src/routes/language-router.ts b/src/api/v1/routes/language-router.ts similarity index 100% rename from src/routes/language-router.ts rename to src/api/v1/routes/language-router.ts diff --git a/src/routes/match-router.ts b/src/api/v1/routes/match-router.ts similarity index 100% rename from src/routes/match-router.ts rename to src/api/v1/routes/match-router.ts diff --git a/src/api/v2/index.ts b/src/api/v2/index.ts new file mode 100644 index 0000000..047a527 --- /dev/null +++ b/src/api/v2/index.ts @@ -0,0 +1,17 @@ +import { Router } from "express"; + +const routerV2 = Router(); + +routerV2.get("/", (_, res) => { + return res.status(200).json({ + message: "🚀 wiki-lex-match V2 🚀", + }); +}); + +routerV2.get("*", (_, res) => { + return res.status(200).json({ + message: "API v2 is not yet available", + }); +}); + +export default routerV2; diff --git a/src/server/index.ts b/src/server/index.ts index fe4ebce..1e009ea 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1,7 +1,4 @@ import express, { type Application } from "express"; -import { authRouter } from "../routes/auth-router"; -import { languageRouter } from "../routes/language-router"; -import { matchRouter } from "../routes/match-router"; import path from "path"; import cors, { type CorsOptions } from "cors"; @@ -26,9 +23,8 @@ export default async (app: Application) => { .sendFile(path.join(__dirname, "../../public/api-docs/index.html")); }); - app.use("/auth", authRouter); - app.use("/languages", languageRouter); - app.use("/match", matchRouter); + app.use("/api/v1/", (await import("../api/v1")).default); + app.use("/api/v2/", (await import("../api/v2")).default); app.get("/health", (_, res) => { res.status(200).json({