Skip to content
Snippets Groups Projects
Commit 064ff054 authored by shwtea's avatar shwtea
Browse files

first commit

parent 668e9921
Branches
No related tags found
No related merge requests found
node_modules/
package-lock.json
db.js 0 → 100644
// 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;
{
"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"
}
}
// 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`);
});
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment