-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/initial kraken setup #1
Open
arghyaiitb
wants to merge
7
commits into
master
Choose a base branch
from
feat/initial-kraken-setup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
693c817
basic configuration and db connection
arghyaiitb e106320
added get rating info api
arghyaiitb 90f2b00
added model for video
arghyaiitb 9cdb2c8
added video api
arghyaiitb 2988385
added video analysis api
arghyaiitb 242d626
added eslint packages
arghyaiitb bd3fae7
eslint fixes
arghyaiitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,6 @@ | |
"browser": true, | ||
"mocha": true | ||
}, | ||
"parser": "babel-eslint", | ||
"extends": "eslint:recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
.idea/ | ||
.build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,66 @@ | ||
{ | ||
|
||
|
||
|
||
|
||
|
||
|
||
"i18n": { | ||
"contentPath": "path:./locales", | ||
"fallback": "en-US" | ||
"databaseConfig": { | ||
"uri": "", | ||
"databases": { | ||
"core": "core", | ||
"factcheck": "factcheck" | ||
} | ||
}, | ||
|
||
|
||
"specialization": { | ||
}, | ||
|
||
"middleware": { | ||
|
||
|
||
|
||
"compress": { | ||
"priority": 10, | ||
"enabled": true | ||
}, | ||
"appsec": { | ||
"priority": 110, | ||
"module": { | ||
"name": "lusca", | ||
"arguments": [ | ||
{ | ||
"csrf": false, | ||
"xframe": "SAMEORIGIN", | ||
"p3p": false, | ||
"csp": false | ||
} | ||
] | ||
} | ||
}, | ||
"logger": { | ||
"enabled": true, | ||
"route": "/*", | ||
"priority": 20, | ||
"module": { | ||
"name": "path:middleware/logHandler", | ||
"arguments": [ | ||
{ | ||
"writeToDisk": true, | ||
"component": "dega_video_analyzer", | ||
"logDir": "/tmp/dega", | ||
"writeToConsole": true, | ||
"level": "info" | ||
} | ||
] | ||
} | ||
}, | ||
"static": { | ||
"module": { | ||
"arguments": [ "path:./.build" ] | ||
} | ||
}, | ||
|
||
"router": { | ||
"module": { | ||
"arguments": [{ "directory": "path:./controllers" }] | ||
} | ||
}, | ||
"errorHandler": { | ||
"enabled": true, | ||
"priority": 140, | ||
"module": { | ||
"name": "path:middleware/errorHandler", | ||
"arguments": [] | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"databaseConfig": { | ||
"uri": "mongodb://root:[email protected]:27017/admin", | ||
"databases": { | ||
"core": "core", | ||
"factcheck": "factcheck" | ||
} | ||
}, | ||
"middleware": { | ||
"devtools": { | ||
"enabled": true, | ||
"priority": 35, | ||
"module": { | ||
"name": "construx", | ||
"arguments": [ | ||
"path:./public", | ||
"path:./.build", | ||
{ | ||
"copier": { | ||
"module": "construx-copier", | ||
"files": "**/*" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const RatingModel = require('../../../models/ratings'); | ||
const utils = require('../../../lib/utils'); | ||
|
||
function getRatingList(req, res, next) { | ||
const logger = req.logger; | ||
utils.setLogTokens(logger, 'ratings', 'getRating', req.query.client, null); | ||
const model = new RatingModel(logger); | ||
const clientId = req.query.client; | ||
return model.getRating( | ||
req.app.kraken, | ||
'', | ||
req.query.sortBy, | ||
req.query.sortAsc, | ||
req.query.limit, | ||
req.query.next, | ||
req.query.previous | ||
).then((result) => { | ||
if (result) { | ||
res.status(200).json(result); | ||
return; | ||
} | ||
res.sendStatus(404); | ||
}).catch(next); | ||
} | ||
|
||
|
||
function getRatingDetails(req, res, next) { | ||
const logger = req.logger; | ||
utils.setLogTokens(logger, 'ratings', 'getRating', req.query.client, null); | ||
const clientId = req.query.client; | ||
var model = new RatingModel(logger); | ||
return model.getRatingDetails( | ||
req.app.kraken, | ||
'', | ||
req.params.ratingId | ||
).then((result) => { | ||
if (result) { | ||
res.status(200).json(result); | ||
return; | ||
} | ||
res.sendStatus(404); | ||
}).catch(next); | ||
} | ||
|
||
module.exports = function routes(router) { | ||
router.get('/', getRatingList); | ||
router.get('/:ratingId', getRatingDetails); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
const VideoAnalysisModel = require('../../../models/videoAnalysis'); | ||
const utils = require('../../../lib/utils'); | ||
const Joi = require('@hapi/joi'); | ||
const ObjectId = require('mongodb').ObjectId; | ||
|
||
|
||
function getVideoAnalysisList(req, res, next) { | ||
const logger = req.logger; | ||
const clientId = req.query.client; | ||
utils.setLogTokens(logger, 'videoAnalysis', 'getVideoAnalysisList', req.query.client, null); | ||
let model = new VideoAnalysisModel(logger); | ||
return model.getVideoAnalysisList( | ||
req.app.kraken, | ||
clientId, | ||
req.query.videoId, | ||
req.query.sortBy, | ||
req.query.sortAsc, | ||
req.query.limit, | ||
req.query.next, | ||
req.query.previous | ||
).then((result) => { | ||
if (result) { | ||
res.status(200).json(result); | ||
return; | ||
} | ||
res.sendStatus(404); | ||
}).catch(next); | ||
} | ||
|
||
|
||
function getVideoAnalysisDetails(req, res, next) { | ||
const logger = req.logger; | ||
const clientId = req.query.client; | ||
utils.setLogTokens(logger, 'videoAnalysis', 'getVideoAnalysisDetails', req.query.client, null); | ||
let model = new VideoAnalysisModel(logger); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create model object outside all functions and resuse it (change it to const instead of let) |
||
return model.getVideoDetails( | ||
req.app.kraken, | ||
clientId, | ||
req.params.videoId | ||
).then((result) => { | ||
if (result) { | ||
res.status(200).json(result); | ||
return; | ||
} | ||
res.sendStatus(404); | ||
}).catch(next); | ||
} | ||
|
||
function createVideoAnalysis(req, res, next) { | ||
const logger = req.logger; | ||
utils.setLogTokens(logger, 'videoAnalysis', 'createVideoAnalysis', req.query.client, null); | ||
const clientId = req.query.client; | ||
var requestBody = req.body; | ||
const schema = Joi.object().keys({ | ||
shown_title: Joi.string().required(), | ||
shown_description: Joi.string(), | ||
reality_title: Joi.string().required(), | ||
reality_description: Joi.string(), | ||
reality_source: Joi.string().required(), | ||
youtube_link: Joi.string().required(), | ||
rating_id: Joi.string().alphanum().min(24).max(24).required(), | ||
video_id: Joi.string().alphanum().min(24).max(24).required(), | ||
end_time_in_sec: Joi.number().required() | ||
}); | ||
|
||
const {error, value} = Joi.validate(requestBody, schema); | ||
if (error) { | ||
return res.status(400).json({error: error.message}); | ||
} | ||
|
||
const videoAnalysisObj = { | ||
'shown_title': value.shown_title, | ||
'shown_description': value.shown_description, | ||
'reality_title': value.reality_title, | ||
'reality_description': value.reality_description, | ||
'reality_source': value.reality_source, | ||
'youtube_link': value.youtube_link, | ||
'rating': { | ||
'$id': ObjectId(value.rating_id), | ||
'$ref': 'video' | ||
}, | ||
'video': { | ||
'$id': ObjectId(value.video_id), | ||
'$ref': 'video' | ||
}, | ||
'end_time_in_sec': value.end_time_in_sec, | ||
'client_id': clientId | ||
}; | ||
|
||
let model = new VideoAnalysisModel(logger); | ||
return model.createVideoAnalysis( | ||
req.app.kraken, | ||
videoAnalysisObj | ||
).then((result) => { | ||
if (result) { | ||
res.status(200).json(result); | ||
return; | ||
} | ||
res.sendStatus(404); | ||
}).catch(next); | ||
} | ||
|
||
function updateVideoAnalysis(req, res, next) { | ||
const logger = req.logger; | ||
utils.setLogTokens(logger, 'videoAnalysis', 'updateVideoAnalysis', req.query.client, null); | ||
const clientId = req.query.client; | ||
let requestBody = req.body; | ||
const schema = Joi.object().keys({ | ||
_id: Joi.string().alphanum().min(24).max(24).required(), | ||
shown_title: Joi.string().required(), | ||
shown_description: Joi.string(), | ||
reality_title: Joi.string().required(), | ||
reality_description: Joi.string(), | ||
reality_source: Joi.string().required(), | ||
youtube_link: Joi.string().required(), | ||
rating_id: Joi.string().alphanum().min(24).max(24).required(), | ||
video_id: Joi.string().alphanum().min(24).max(24).required(), | ||
end_time_in_sec: Joi.number().required() | ||
}); | ||
|
||
const {error, value} = Joi.validate(requestBody, schema); | ||
if (error) { | ||
return res.status(400).json({error: error.message}); | ||
} | ||
|
||
const videoAnalysisObj = { | ||
'shown_title': value.shown_title, | ||
'shown_description': value.shown_description, | ||
'reality_title': value.reality_title, | ||
'reality_description': value.reality_description, | ||
'reality_source': value.reality_source, | ||
'youtube_link': value.youtube_link, | ||
'rating': { | ||
'$id': ObjectId(value.rating_id), | ||
'$ref': 'video' | ||
}, | ||
'video': { | ||
'$id': ObjectId(value.video_id), | ||
'$ref': 'video' | ||
}, | ||
'end_time_in_sec': value.end_time_in_sec, | ||
'client_id': clientId | ||
}; | ||
|
||
|
||
|
||
let model = new VideoAnalysisModel(logger); | ||
return model.updateVideoAnalysis( | ||
req.app.kraken, | ||
clientId, | ||
req.params.id, | ||
videoAnalysisObj | ||
).then((result) => { | ||
if (result) { | ||
res.status(200).json(result); | ||
return; | ||
} | ||
res.sendStatus(404); | ||
}).catch(next); | ||
} | ||
|
||
function deleteVideoAnalysis(req, res, next) { | ||
const logger = req.logger; | ||
utils.setLogTokens(logger, 'videoAnalysis', 'deleteVideoAnalysis', req.query.client, null); | ||
const clientId = req.query.client; | ||
|
||
let model = new VideoAnalysisModel(logger); | ||
return model.deleteVideoAnalysis( | ||
req.app.kraken, | ||
clientId, | ||
req.params.id | ||
).then((result) => { | ||
if (result) { | ||
res.status(200).json(result); | ||
return; | ||
} | ||
res.sendStatus(404); | ||
}).catch(next); | ||
} | ||
|
||
|
||
|
||
module.exports = function routes(router) { | ||
router.get('/', getVideoAnalysisList); | ||
router.post('/', createVideoAnalysis); | ||
router.get('/:id', getVideoAnalysisDetails); | ||
router.put('/:id', updateVideoAnalysis); | ||
router.delete('/:id', deleteVideoAnalysis); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the file names should be all small separated by - between words thats the convention we follow today. rename videoAnalysis to video-analysis.js