From be2e77c9b865d755f42f06c91e812478a3a7593a Mon Sep 17 00:00:00 2001 From: shwtea <shwetagupta0711754@gmail.com> Date: Fri, 6 Sep 2024 11:58:27 +0530 Subject: [PATCH] platform added --- api/template/business.js | 8 ++++---- api/template/controller.js | 8 ++++---- api/template/service.js | 12 +++++------- swagger.yaml | 11 +++++++++++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/api/template/business.js b/api/template/business.js index 5065318..c42fc3b 100644 --- a/api/template/business.js +++ b/api/template/business.js @@ -14,9 +14,9 @@ const updateAndMapWidget = async (page,widgetId,position, startTime, endTime) => }; -const createTemplate = async (name, desc, widgets, hashId) => { +const createTemplate = async (name, desc,platform, widgets, hashId) => { try { - const response = await templateService.createTemplate(name, desc, widgets, hashId); + const response = await templateService.createTemplate(name, desc,platform, widgets, hashId); return { status: '200', response } } catch (error) { throw error @@ -24,9 +24,9 @@ const createTemplate = async (name, desc, widgets, hashId) => { }; -const getParticularTemplate = async (page) => { +const getParticularTemplate = async (page,platform) => { try { - const response = await templateService.getParticularTemplate(page); + const response = await templateService.getParticularTemplate(page,platform); console.log(page,"Pagessssssss"); return { status: '200', response } } catch (error) { diff --git a/api/template/controller.js b/api/template/controller.js index fb47864..a8cc120 100644 --- a/api/template/controller.js +++ b/api/template/controller.js @@ -18,8 +18,8 @@ const updateAndMapWidget = async (req, res, next) => { const createTemplate = async (req, res, next) => { try { - const { name, desc, widgets, hashId } = req.body; - const response = await templateBusiness.createTemplate(name, desc, widgets, hashId); + const { name, desc,platform, widgets, hashId } = req.body; + const response = await templateBusiness.createTemplate(name, desc,platform, widgets, hashId); return res.status(response.status).json({ data: response }); } catch (error) { throw error @@ -29,8 +29,8 @@ const createTemplate = async (req, res, next) => { const getParticularTemplate = async (req, res) => { try { console.log("GET template details of a particular page"); - const { page } = req.params; - const response = await templateBusiness.getParticularTemplate(page); + const { page,platform } = req.params; + const response = await templateBusiness.getParticularTemplate(page,platform); return res.status(response.status).json({ data: response }); } catch (error) { throw error; diff --git a/api/template/service.js b/api/template/service.js index 2d172f8..1bcae56 100644 --- a/api/template/service.js +++ b/api/template/service.js @@ -37,12 +37,12 @@ const updateAndMapWidget = async (page,widgetId,position, startTime, endTime) => }; -const createTemplate = async (name, desc, widgets, hashId) => { +const createTemplate = async (name, desc, platform, widgets, hashId) => { try { - console.log("in service") const newTemplate = new Template({ name, desc, + platform, widgets, hashId }); @@ -56,13 +56,11 @@ const createTemplate = async (name, desc, widgets, hashId) => { }; -const getParticularTemplate = async (page,res) => { +const getParticularTemplate = async (page,platform) => { try { - const template = await Template.findOne({ name: page}).populate('widgets.widgetId'); + const template = await Template.findOne({ name: page,platform}).populate('widgets.widgetId'); if (!template) { - // return res.status(404).json({ error: 'Template not found' }); - console.error('Template not found'); - res.status(404).send(); + return res.status(404).json({ error: 'Template not found' }); } return template; } catch (error) { diff --git a/swagger.yaml b/swagger.yaml index 812af00..63757fd 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -21,6 +21,12 @@ paths: schema: type: string description: The page for which template details are requested. + - in: path + name: platform + required: true + schema: + type: string + description: The platform for which template details are requested. responses: '200': description: Template retrieved successfully @@ -313,6 +319,11 @@ paths: type: string description: A description of the template example: "Template for the homepage widget" + platform: + type: string + enum: ['web', 'mobile', 'both'] + description: The platform for which the template is intended + example: "web" widgets: type: array description: A list of widgets mapped to the template -- GitLab