From 4d1da02b5f25d0dc0685a77fb338348f80093c92 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 2 Dec 2024 11:17:14 +0100 Subject: [PATCH] Add express routes --- src/routes/booking.routes.js | 31 +++++++++++++++++++++++++++++++ src/routes/client.routes.js | 31 +++++++++++++++++++++++++++++++ src/routes/hotel.routes.js | 31 +++++++++++++++++++++++++++++++ src/routes/index.ts | 13 +++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 src/routes/booking.routes.js create mode 100644 src/routes/client.routes.js create mode 100644 src/routes/hotel.routes.js create mode 100644 src/routes/index.ts diff --git a/src/routes/booking.routes.js b/src/routes/booking.routes.js new file mode 100644 index 0000000..2b3d32b --- /dev/null +++ b/src/routes/booking.routes.js @@ -0,0 +1,31 @@ +import { Router } from "express"; +import BookingController from "../controllers/booking.controller"; + +class BookingRoutes { + router = Router(); + controller = new BookingController(); + + constructor() { + this.intializeRoutes(); + } + + intializeRoutes() { + // Create a new Booking + this.router.post("/", this.controller.create); + + // Retrieve all Bookings + this.router.get("/", this.controller.findAll); + + // Retrieve a single Booking with id + this.router.get("/:id", this.controller.findOne); + + // Update a Booking with id + this.router.put("/:id", this.controller.update); + + // Delete a Booking with id + this.router.delete("/:id", this.controller.delete); + } +} + +export default new BookingRoutes().router; + diff --git a/src/routes/client.routes.js b/src/routes/client.routes.js new file mode 100644 index 0000000..60f9a81 --- /dev/null +++ b/src/routes/client.routes.js @@ -0,0 +1,31 @@ +import { Router } from "express"; +import ClientController from "../controllers/client.controller"; + +class ClientRoutes { + router = Router(); + controller = new ClientController(); + + constructor() { + this.intializeRoutes(); + } + + intializeRoutes() { + // Create a new Client + this.router.post("/", this.controller.create); + + // Retrieve all Clients + this.router.get("/", this.controller.findAll); + + // Retrieve a single Client with id + this.router.get("/:id", this.controller.findOne); + + // Update a Client with id + this.router.put("/:id", this.controller.update); + + // Delete a Client with id + this.router.delete("/:id", this.controller.delete); + } +} + +export default new ClientRoutes().router; + diff --git a/src/routes/hotel.routes.js b/src/routes/hotel.routes.js new file mode 100644 index 0000000..0e5248f --- /dev/null +++ b/src/routes/hotel.routes.js @@ -0,0 +1,31 @@ +import { Router } from "express"; +import HotelController from "../controllers/hotel.controller"; + +class HotelRoutes { + router = Router(); + controller = new HotelController(); + + constructor() { + this.intializeRoutes(); + } + + intializeRoutes() { + // Create a new Hotel + this.router.post("/", this.controller.create); + + // Retrieve all Hotels + this.router.get("/", this.controller.findAll); + + // Retrieve a single Hotel with id + this.router.get("/:id", this.controller.findOne); + + // Update a Hotel with id + this.router.put("/:id", this.controller.update); + + // Delete a Hotel with id + this.router.delete("/:id", this.controller.delete); + } +} + +export default new HotelRoutes().router; + diff --git a/src/routes/index.ts b/src/routes/index.ts new file mode 100644 index 0000000..4119d1d --- /dev/null +++ b/src/routes/index.ts @@ -0,0 +1,13 @@ +import { Application } from "express"; + +import hotelRoutes from "./hotel.routes"; +import clientRoutes from "./client.routes"; +import bookingRoutes from "./booking.routes"; + +export default class Routes { + constructor(app: Application) { + app.use("/api/hotels", hotelRoutes); + app.use("/api/client", clientRoutes); + app.use("/api/booking", bookingRoutes); + } +}