Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-155
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-155
2021-155
Commits
2d0f5a5e
Commit
2d0f5a5e
authored
Jun 26, 2021
by
dasunx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
automated answer models added, python connected
parent
2567ae9b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
1 deletion
+137
-1
backend/controllers/questions.js
backend/controllers/questions.js
+26
-0
backend/models/automatedAnswer.js
backend/models/automatedAnswer.js
+40
-0
backend/models/blogArticle.js
backend/models/blogArticle.js
+22
-0
backend/models/githubRepo.js
backend/models/githubRepo.js
+46
-0
backend/routes.js
backend/routes.js
+3
-1
No files found.
backend/controllers/questions.js
View file @
2d0f5a5e
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
()
...
...
backend/models/automatedAnswer.js
0 → 100644
View file @
2d0f5a5e
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
);
backend/models/blogArticle.js
0 → 100644
View file @
2d0f5a5e
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
);
backend/models/githubRepo.js
0 → 100644
View file @
2d0f5a5e
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
);
backend/routes.js
View file @
2d0f5a5e
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment