Commit 2d0f5a5e authored by dasunx's avatar dasunx

automated answer models added, python connected

parent 2567ae9b
const Question = require('../models/question');
const User = require('../models/user');
const AutomatedAnswer = require('../models/automatedAnswer');
const { body, validationResult } = require('express-validator');
const { spawn } = require('child_process');
const path = require('path');
exports.loadQuestions = async (req, res, next, id) => {
try {
......@@ -31,6 +34,13 @@ exports.createQuestion = async (req, res, next) => {
text
});
res.status(201).json(question);
const autoAnswer = await AutomatedAnswer.create({ question: question._id });
spawn('python', [
path.join(__dirname, '..', 'python', 'auto-answer', 'scrapper.py'),
title,
tags,
autoAnswer._id
]);
} catch (error) {
next(error);
}
......@@ -103,6 +113,22 @@ exports.loadComment = async (req, res, next, id) => {
next();
};
exports.getAutomatedAnswer = async (req, res, next) => {
console.log('HERE');
try {
const { q } = req.params;
const answer = await AutomatedAnswer.findOne({ question: q });
if (answer) {
res.json(answer);
} else {
res.status(404).json({ msg: 'No automated answer found' });
}
} catch (error) {
next(error);
}
};
exports.questionValidate = [
body('title')
.exists()
......
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const AutomatedAnswerSchema = mongoose.Schema({
question: {
type: Schema.Types.ObjectId,
ref: 'Question',
required: true
},
stackoverflow: {
url: {
type: String
},
content: {
type: String
},
status: {
type: String
}
},
github: [
{
type: Schema.Types.ObjectId,
ref: 'GitHubRepo'
}
],
youtube: [
{
type: String
}
],
blogs: [
{
type: Schema.Types.ObjectId,
ref: 'BlogArticle'
}
]
});
module.exports = mongoose.model('AutomatedAnswer', AutomatedAnswerSchema);
const mongoose = require('mongoose');
const BlogArticleSchema = mongoose.Schema({
automatedAnswer: {
type: Schema.Types.ObjectId,
ref: 'AutomatedAnswer',
required: true
},
blogName: {
type: String,
required: true
},
link: {
type: String,
required: true
},
content: {
type: String
}
});
module.exports = mongoose.model('BlogArticle', BlogArticleSchema);
const mongoose = require('mongoose');
const GitHubRepoSchema = mongoose.Schema({
github_username: {
type: String
},
avatar: {
type: String
},
repo_name: {
type: String
},
repo_URL: {
type: String,
require: true
},
description: {
type: String
},
wiki: {
type: String
},
language: {
type: String
},
created_at: {
type: Date
},
updated_at: {
type: Date
},
last_push: {
type: Date
},
forks: {
type: Number
},
open_issues: {
type: Number
},
watchers: {
type: Number
}
});
module.exports = mongoose.model('GitHubRepo', GitHubRepoSchema);
......@@ -14,7 +14,8 @@ const {
listQuestions,
listByTags,
listByUser,
removeQuestion
removeQuestion,
getAutomatedAnswer
} = require('./controllers/questions');
const {
loadAnswers,
......@@ -50,6 +51,7 @@ router.get('/question', listQuestions);
router.get('/questions/:tags', listByTags);
router.get('/question/user/:username', listByUser);
router.delete('/question/:question', [requireAuth, questionAuth], removeQuestion);
router.get('/automatedanswer/:q', getAutomatedAnswer);
//tags
router.get('/tags/populertags', listPopulerTags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment