Skip to content
Snippets Groups Projects
Commit eb424854 authored by Shweta Gupta's avatar Shweta Gupta
Browse files

Merge branch 'shweta-working' into 'development'

Shweta working

See merge request !2
parents 7c6ff283 d84aec7b
Branches
No related tags found
1 merge request!2Shweta working
const healthCheckRouter = require('./health-check/routes');
const layoutRouter = require('./layout/routes');
const apiBaseRouter = require('express').Router();
// Exposed endpoints
apiBaseRouter.use('/health-check', healthCheckRouter);
// apiBaseRouter.use('/pan', panRouter);
// apiBaseRouter.use('/otp', otpRouter);
apiBaseRouter.use('/widget', layoutRouter);
module.exports = apiBaseRouter;
const healthCheck = (req, res, next) => {
try {
return res.sendStatus(200);
} catch (error) {
console.log(error)
}
};
module.exports = {
healthCheck,
};
const healthCheckRouter = require('express').Router();
const { healthCheck } = require('./controller');
healthCheckRouter.get('/', healthCheck);
module.exports = healthCheckRouter;
/* eslint-disable prefer-promise-reject-errors */
/* eslint-disable no-throw-literal */
// const logger = require('utils/logger');
const getAllWidgetService = require('../layout/service');
const getAllWidget = async (page) => {
try {
const response = await getAllWidgetService.getAllWidget(page);
return { status: '200', response }
} catch (error) {
throw error
}
};
const createWidget = async (data) => {
try {
const response = await getAllWidgetService.createWidget(data);
return { status: '200', response }
} catch (error) {
throw error
}
};
module.exports = {
getAllWidget,
createWidget
};
// const logger = require('utils/logger');
const layoutBusiness = require('./business');
// const Joi = require('joi');
const getAllWidget = async (req, res, next) => {
try {
console.log("comign here")
const { page } = req.params;
const response = await layoutBusiness.getAllWidget(page);
return res.status(response.status).json({ data: response });
} catch (error) {
throw error
}
};
const createWidget = async (req, res, next) => {
try {
console.log("comign createWidget")
const response = await layoutBusiness.createWidget(req.body);
return res.status(response.status).json({ data: response });
} catch (error) {
throw error
}
};
module.exports = {
getAllWidget,
createWidget
};
\ No newline at end of file
const layoutRouter = require('express').Router();
const { getAllWidget,createWidget} = require('./controller');
layoutRouter.get('/allLayout/:page', getAllWidget);
layoutRouter.post('/createWidget', createWidget);
module.exports = layoutRouter;
\ No newline at end of file
// const logger = require('utils/logger');
const Widget = require("../models/widget");
const Template = require("../models/template")
const getAllWidget = async (page) => {
try {
const template = await Template.findOne({ name: page}).populate('widgets.widgetId');
if (!template) {
return res.status(404).json({ error: 'Template not found' });
}
res.status(200).json(template);
} catch (error) {
throw error
}
};
const createWidget = async (data) => {
try {
console.log("in service")
const widget = new Widget(data);
await widget.save();
return { status: 201, id: widget._id, message: 'Widget created successfully' };
} catch (error) {
throw error
}
};
module.exports = {
getAllWidget,
createWidget
};
\ No newline at end of file
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Define schema for widgets within a template or page
const WidgetRefSchema = new Schema({
widgetId: { type: mongoose.Schema.Types.ObjectId, ref: 'Widget', required: true }, // Reference to the Widget model
position: { type: Number, required: true },
startTime: { type: Date, required: true },
endTime: { type: Date, required: true }
});
// Define main Template schema
const TemplateSchema = new Schema({
name: { type: String, required: true },
desc: { type: String },
widgets: [WidgetRefSchema],
hashId: { type: String, unique: true, required: true },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now }
});
module.exports = mongoose.model('Template', TemplateSchema);
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Define schema for the button data
const ButtonDataSchema = new Schema({
url: { type: String, required: true },
title: { type: String, required: true }
});
// Define schema for banner data
const BannerDataSchema = new Schema({
imageName: { type: String, default: '' },
headingText: { type: String, required: true },
subHeadingText: { type: String, required: true },
landingUrl: { type: String, required: true },
timerPosition: { type: String, default: null },
timerColor: { type: String, default: null }
});
// Define schema for list items
const ListItemSchema = new Schema({
bannerData: { type: BannerDataSchema, required: true },
display_order: { type: Number, required: true },
dimension: {
length: { type: Number, required: true },
breadth: { type: Number, required: true }
},
banner_title: { type: String, required: true }
});
// Define main Widget schema
const WidgetSchema = new Schema({
title: { type: String, required: true },
widget: { type: String, required: true },
enable: { type: Boolean, default: true },
buttonData: [ButtonDataSchema],
sectionHeadingText: { type: String, required: true },
apiUrl: { type: String, required: true },
list: [ListItemSchema],
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now }
});
module.exports = mongoose.model('Widget', WidgetSchema);
...@@ -7,6 +7,7 @@ const connectDB = require('./db'); ...@@ -7,6 +7,7 @@ const connectDB = require('./db');
const app = express(); const app = express();
app.use(bodyParser.json()); app.use(bodyParser.json());
const apiBaseRouter = require('./api/apiBaseRouter');
// Connect to MongoDB // Connect to MongoDB
connectDB(); connectDB();
...@@ -15,6 +16,9 @@ connectDB(); ...@@ -15,6 +16,9 @@ connectDB();
const swaggerDocument = YAML.load('./swagger.yaml'); const swaggerDocument = YAML.load('./swagger.yaml');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
// API base URL
app.use(apiBaseRouter);
// Start the server // Start the server
const PORT = process.env.PORT || 5000; const PORT = process.env.PORT || 5000;
......
openapi: 3.0.0 openapi: 3.0.0
info: info:
title: Layout Management API title: Widgetized Homepage API
version: 1.0.0 version: 1.0.0
description: API for managing layouts including creating, retrieving, and deleting layouts. description: API for managing templates and widgets for a widgetized homepage and sub-pages.
# servers:
# - url: http://localhost:3000
# description: Local server
paths: paths:
/api/layout/{layout}: /widget/allLayout/{page}:
get: get:
summary: Get a specific layout summary: Get widget details for a page
parameters: parameters:
- in: path - in: path
name: layout name: page
required: true required: true
schema: schema:
type: string type: string
description: The layout identifier description: The page for which widget details are requested.
responses: responses:
200: '200':
description: Successfully retrieved layout description: Widgets retrieved successfully
content: content:
application/json: application/json:
schema: schema:
type: array
items:
type: object type: object
properties: properties:
id:
type: string
title: title:
type: string type: string
layout: layout:
type: string type: string
priority:
type: integer
enable: enable:
type: boolean type: boolean
buttonData: buttonData:
...@@ -41,6 +48,8 @@ paths: ...@@ -41,6 +48,8 @@ paths:
type: string type: string
sectionHeadingText: sectionHeadingText:
type: string type: string
apiUrl:
type: string
list: list:
type: array type: array
items: items:
...@@ -57,14 +66,12 @@ paths: ...@@ -57,14 +66,12 @@ paths:
type: string type: string
landingUrl: landingUrl:
type: string type: string
rowStartTime:
type: string
rowEndTime:
type: string
timerPosition: timerPosition:
type: string type: string
timerColor: timerColor:
type: string type: string
display_order:
type: integer
dimension: dimension:
type: object type: object
properties: properties:
...@@ -72,84 +79,21 @@ paths: ...@@ -72,84 +79,21 @@ paths:
type: integer type: integer
breadth: breadth:
type: integer type: integer
display_order:
type: integer
banner_title: banner_title:
type: string type: string
404: '404':
description: Layout not found description: Widgets not found
/api/AllLayout:
get:
summary: Get all layouts
responses:
200:
description: Successfully retrieved all layouts
content: content:
application/json: application/json:
schema: 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 type: object
properties: properties:
length: error:
type: integer
breadth:
type: integer
display_order:
type: integer
banner_title:
type: string type: string
/api/newLayout: /widget/createWidget:
post: post:
summary: Create a new layout summary: Create a new widget
requestBody: requestBody:
required: true required: true
content: content:
...@@ -159,7 +103,7 @@ paths: ...@@ -159,7 +103,7 @@ paths:
properties: properties:
title: title:
type: string type: string
layout: widget:
type: string type: string
priority: priority:
type: integer type: integer
...@@ -176,6 +120,8 @@ paths: ...@@ -176,6 +120,8 @@ paths:
type: string type: string
sectionHeadingText: sectionHeadingText:
type: string type: string
apiUrl:
type: string
list: list:
type: array type: array
items: items:
...@@ -192,14 +138,12 @@ paths: ...@@ -192,14 +138,12 @@ paths:
type: string type: string
landingUrl: landingUrl:
type: string type: string
rowStartTime:
type: string
rowEndTime:
type: string
timerPosition: timerPosition:
type: string type: string
timerColor: timerColor:
type: string type: string
display_order:
type: integer
dimension: dimension:
type: object type: object
properties: properties:
...@@ -207,38 +151,64 @@ paths: ...@@ -207,38 +151,64 @@ paths:
type: integer type: integer
breadth: breadth:
type: integer type: integer
display_order:
type: integer
banner_title: banner_title:
type: string type: string
responses: responses:
201: '201':
description: New layout created successfully description: Widget created successfully
content: content:
application/json: application/json:
schema: schema:
type: object type: object
properties: properties:
message: id:
type: string type: string
layoutId: message:
type: string type: string
400: '400':
description: Bad request description: Bad request
content:
application/json:
schema:
type: object
properties:
error:
type: string
/api/layout/{layout}: /api/templates/{page}/widgets/{widgetId}:
delete: put:
summary: Delete a layout summary: Update and map a widget to a particular page
parameters: parameters:
- in: path - in: path
name: layout name: page
required: true
schema:
type: string
description: The page to which the widget is to be mapped.
- in: path
name: widgetId
required: true required: true
schema: schema:
type: string type: string
description: The layout identifier description: The widget ID that needs to be mapped.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
position:
type: integer
startTime:
type: string
format: date-time
endTime:
type: string
format: date-time
responses: responses:
200: '200':
description: Layout deleted successfully description: Widget mapped successfully
content: content:
application/json: application/json:
schema: schema:
...@@ -246,5 +216,18 @@ paths: ...@@ -246,5 +216,18 @@ paths:
properties: properties:
message: message:
type: string type: string
404: widgetId:
description: Layout not found type: string
page:
type: string
position:
type: integer
'400':
description: Bad request
content:
application/json:
schema:
type: object
properties:
error:
type: string
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment