diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..504afef81fbadc8c0a072e1ac93f1376bca7f4a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +package-lock.json diff --git a/db.js b/db.js new file mode 100644 index 0000000000000000000000000000000000000000..9ef5017bba74105c2aa70af36973e3900bab721e --- /dev/null +++ b/db.js @@ -0,0 +1,17 @@ +// db.js +const mongoose = require('mongoose'); + +const connectDB = async () => { + try { + await mongoose.connect('mongodb://localhost:27017/widgetTemplate', { + useNewUrlParser: true, + useUnifiedTopology: true + }); + console.log('MongoDB connected successfully.'); + } catch (err) { + console.error('MongoDB connection error:', err); + process.exit(1); + } +}; + +module.exports = connectDB; diff --git a/package.json b/package.json new file mode 100644 index 0000000000000000000000000000000000000000..5901318a1e25c12236c6dc73d86c1f0f62d53019 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "widgettemplate", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node server.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "body-parser": "^1.20.2", + "express": "^4.19.2", + "mongoose": "^8.6.0", + "nodemon": "^3.1.4", + "swagger-ui-express": "^5.0.1", + "yamljs": "^0.3.0" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000000000000000000000000000000000000..b99148637ddd19a5c8a6a6330ab58cada353805f --- /dev/null +++ b/server.js @@ -0,0 +1,24 @@ +// server.js +const express = require('express'); +const bodyParser = require('body-parser'); +const swaggerUi = require('swagger-ui-express'); +const YAML = require('yamljs'); +const connectDB = require('./db'); + +const app = express(); +app.use(bodyParser.json()); + +// Connect to MongoDB +connectDB(); + +// Serve Swagger API documentation +const swaggerDocument = YAML.load('./swagger.yaml'); +app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); + + +// Start the server +const PORT = process.env.PORT || 5000; +app.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); + console.log(`Swagger UI available at http://localhost:${PORT}/api-docs`); +}); diff --git a/swagger.yaml b/swagger.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d63e67b4734a809138f2c0f3e454d404ec207382 --- /dev/null +++ b/swagger.yaml @@ -0,0 +1,250 @@ +openapi: 3.0.0 +info: + title: Layout Management API + version: 1.0.0 + description: API for managing layouts including creating, retrieving, and deleting layouts. +paths: + /api/layout/{layout}: + get: + summary: Get a specific layout + parameters: + - in: path + name: layout + required: true + schema: + type: string + description: The layout identifier + responses: + 200: + description: Successfully retrieved layout + content: + application/json: + schema: + type: object + properties: + title: + type: string + layout: + type: string + priority: + type: integer + enable: + type: boolean + buttonData: + type: array + items: + type: object + properties: + url: + type: string + title: + type: string + sectionHeadingText: + type: string + list: + type: array + items: + type: object + properties: + bannerData: + type: object + properties: + imageName: + type: string + headingText: + type: string + subHeadingText: + type: string + landingUrl: + type: string + rowStartTime: + type: string + rowEndTime: + type: string + timerPosition: + type: string + timerColor: + type: string + dimension: + type: object + properties: + length: + type: integer + breadth: + type: integer + display_order: + type: integer + banner_title: + type: string + 404: + description: Layout not found + + /api/AllLayout: + get: + summary: Get all layouts + responses: + 200: + description: Successfully retrieved all layouts + content: + application/json: + schema: + type: array + items: + type: object + properties: + title: + type: string + layout: + type: string + priority: + type: integer + enable: + type: boolean + buttonData: + type: array + items: + type: object + properties: + url: + type: string + title: + type: string + sectionHeadingText: + type: string + list: + type: array + items: + type: object + properties: + bannerData: + type: object + properties: + imageName: + type: string + headingText: + type: string + subHeadingText: + type: string + landingUrl: + type: string + rowStartTime: + type: string + rowEndTime: + type: string + timerPosition: + type: string + timerColor: + type: string + dimension: + type: object + properties: + length: + type: integer + breadth: + type: integer + display_order: + type: integer + banner_title: + type: string + + /api/newLayout: + post: + summary: Create a new layout + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + title: + type: string + layout: + type: string + priority: + type: integer + enable: + type: boolean + buttonData: + type: array + items: + type: object + properties: + url: + type: string + title: + type: string + sectionHeadingText: + type: string + list: + type: array + items: + type: object + properties: + bannerData: + type: object + properties: + imageName: + type: string + headingText: + type: string + subHeadingText: + type: string + landingUrl: + type: string + rowStartTime: + type: string + rowEndTime: + type: string + timerPosition: + type: string + timerColor: + type: string + dimension: + type: object + properties: + length: + type: integer + breadth: + type: integer + display_order: + type: integer + banner_title: + type: string + responses: + 201: + description: New layout created successfully + content: + application/json: + schema: + type: object + properties: + message: + type: string + layoutId: + type: string + 400: + description: Bad request + + /api/layout/{layout}: + delete: + summary: Delete a layout + parameters: + - in: path + name: layout + required: true + schema: + type: string + description: The layout identifier + responses: + 200: + description: Layout deleted successfully + content: + application/json: + schema: + type: object + properties: + message: + type: string + 404: + description: Layout not found