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
No related branches found
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');
const app = express();
app.use(bodyParser.json());
const apiBaseRouter = require('./api/apiBaseRouter');
// Connect to MongoDB
connectDB();
......@@ -15,6 +16,9 @@ connectDB();
const swaggerDocument = YAML.load('./swagger.yaml');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
// API base URL
app.use(apiBaseRouter);
// Start the server
const PORT = process.env.PORT || 5000;
......
openapi: 3.0.0
info:
title: Layout Management API
title: Widgetized Homepage API
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:
/api/layout/{layout}:
/widget/allLayout/{page}:
get:
summary: Get a specific layout
summary: Get widget details for a page
parameters:
- in: path
name: layout
name: page
required: true
schema:
type: string
description: The layout identifier
description: The page for which widget details are requested.
responses:
200:
description: Successfully retrieved layout
'200':
description: Widgets retrieved successfully
content:
application/json:
schema:
type: array
items:
type: object
properties:
id:
type: string
title:
type: string
layout:
type: string
priority:
type: integer
enable:
type: boolean
buttonData:
......@@ -41,6 +48,8 @@ paths:
type: string
sectionHeadingText:
type: string
apiUrl:
type: string
list:
type: array
items:
......@@ -57,14 +66,12 @@ paths:
type: string
landingUrl:
type: string
rowStartTime:
type: string
rowEndTime:
type: string
timerPosition:
type: string
timerColor:
type: string
display_order:
type: integer
dimension:
type: object
properties:
......@@ -72,84 +79,21 @@ paths:
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
'404':
description: Widgets not found
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:
error:
type: string
/api/newLayout:
/widget/createWidget:
post:
summary: Create a new layout
summary: Create a new widget
requestBody:
required: true
content:
......@@ -159,7 +103,7 @@ paths:
properties:
title:
type: string
layout:
widget:
type: string
priority:
type: integer
......@@ -176,6 +120,8 @@ paths:
type: string
sectionHeadingText:
type: string
apiUrl:
type: string
list:
type: array
items:
......@@ -192,14 +138,12 @@ paths:
type: string
landingUrl:
type: string
rowStartTime:
type: string
rowEndTime:
type: string
timerPosition:
type: string
timerColor:
type: string
display_order:
type: integer
dimension:
type: object
properties:
......@@ -207,38 +151,64 @@ paths:
type: integer
breadth:
type: integer
display_order:
type: integer
banner_title:
type: string
responses:
201:
description: New layout created successfully
'201':
description: Widget created successfully
content:
application/json:
schema:
type: object
properties:
message:
id:
type: string
layoutId:
message:
type: string
400:
'400':
description: Bad request
content:
application/json:
schema:
type: object
properties:
error:
type: string
/api/layout/{layout}:
delete:
summary: Delete a layout
/api/templates/{page}/widgets/{widgetId}:
put:
summary: Update and map a widget to a particular page
parameters:
- 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
schema:
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:
200:
description: Layout deleted successfully
'200':
description: Widget mapped successfully
content:
application/json:
schema:
......@@ -246,5 +216,18 @@ paths:
properties:
message:
type: string
404:
description: Layout not found
widgetId:
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