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

basic api added

parent 354ca8ae
No related branches found
No related tags found
1 merge request!2Shweta working
......@@ -5,14 +5,21 @@ const getAllWidgetService = require('../layout/service');
const getAllWidget = async () => {
const getAllWidget = async (page) => {
try {
// logger.info(`Entering | getAllWidget BusinessLogic |`);
const response = await getAllWidgetService.getAllWidget();
// logger.info(`Exiting | generateAadhaarOtp BusinessLogic |`);
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) {
// logger.error(` Error | getAllWidget BusinessLogic | ${error}`)
throw error
}
......@@ -22,4 +29,5 @@ const getAllWidget = async () => {
module.exports = {
getAllWidget,
createWidget
};
......@@ -5,25 +5,26 @@ const layoutBusiness = require('./business');
const getAllWidget = async (req, res, next) => {
try {
console.log("comign here")
// logger.info(`Entering | getAllWidget Controller | ${req.body}`);
// const schema = Joi.object({
// aadhaarNumber: Joi.string().required(),
// });
// const { error } = schema.validate({ });
// if (error) {
// logger.error(` Error | getAllWidget Controller | ${JSON.stringify(error)}`)
// return next(new ExpressError('BAD_REQUEST'));
// }
const response = await layoutBusiness.getAllWidget();
// logger.info(`Exiting | getAllWidget Controller |`);
const { page } = req.params;
const response = await layoutBusiness.getAllWidget(page);
return res.status(response.status).json({ data: response });
} catch (error) {
// logger.error(` Error | getAllWidget Controller | ${error}`)
next(new ExpressError(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} = require('./controller');
const { getAllWidget,createWidget} = require('./controller');
layoutRouter.get('/allLayout', getAllWidget);
layoutRouter.get('/allLayout/:page', getAllWidget);
// layoutRouter.post('/aadhaarOtpVerify', aadhaarOtpVerify);
// layoutRouter.post('/aadhaarPanSimilarity', aadhaarPanSimilarity);
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 getAllWidget = async () => {
const createWidget = async (data) => {
try {
// logger.info(`Entering | getAllWidget Service |`);
const response = "123";
// logger.info(`Exiting | getAllWidget Service |`);
return { status: '200', response }
console.log("in service")
const widget = new Widget(data);
await widget.save();
return { status: 201, id: widget._id, message: 'Widget created successfully' };
} catch (error) {
// logger.error(` Error | getAllWidget Service | ${error}`)
throw error
}
......@@ -17,4 +30,5 @@ const getAllWidget = async () => {
module.exports = {
getAllWidget,
createWidget
};
\ No newline at end of file
......@@ -31,8 +31,7 @@ const ListItemSchema = new Schema({
// Define main Widget schema
const WidgetSchema = new Schema({
title: { type: String, required: true },
layout: { type: String, required: true },
priority: { type: Number, required: true },
widget: { type: String, required: true },
enable: { type: Boolean, default: true },
buttonData: [ButtonDataSchema],
sectionHeadingText: { type: String, required: true },
......
......@@ -9,8 +9,6 @@ const app = express();
app.use(bodyParser.json());
const apiBaseRouter = require('./api/apiBaseRouter');
const baseURL = '/api-service';
// Connect to MongoDB
connectDB();
......
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:
......@@ -42,6 +48,8 @@ paths:
type: string
sectionHeadingText:
type: string
apiUrl:
type: string
list:
type: array
items:
......@@ -58,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:
......@@ -73,84 +79,21 @@ paths:
type: integer
breadth:
type: integer
display_order:
type: integer
banner_title:
type: string
404:
description: Layout not found
/widget/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:
......@@ -160,7 +103,7 @@ paths:
properties:
title:
type: string
layout:
widget:
type: string
priority:
type: integer
......@@ -177,6 +120,8 @@ paths:
type: string
sectionHeadingText:
type: string
apiUrl:
type: string
list:
type: array
items:
......@@ -193,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:
......@@ -208,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:
......@@ -247,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