Skip to content
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

Reconfigured routes and Controllers for QnA #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ module.exports = {
sourceType: 'module',
},
rules: {
"no-unused-vars": "warn",
"no-console": "off",
"no-plusplus": "off",
},
};
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
.DS_STORE

.env

node_modules/

dist/

lib-cov
coverage

package-lock.json
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "atelier-backend",
"name": "atelier-backend-questions-answers",
"version": "1.0.0",
"description": "",
"description": "Back end service for all Questions and Answers related to front end of Atelier ecommerce",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server-dev": "nodemon server/app.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Audacious-Artichokes/atelier-backend.git"
"url": "https://github.com/Audacious-Artichokes/atelier-backend-questions-answers.git"
},
"author": "Rachel Miller, Michael Del Pape, Rachel Miller",
"author": "Rachel Miller",
"license": "ISC",
"bugs": {
"url": "https://github.com/Audacious-Artichokes/atelier-backend/issues"
Expand Down
7 changes: 0 additions & 7 deletions server/app.js

This file was deleted.

16 changes: 16 additions & 0 deletions server/controllers/answers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const axios = require('axios');

exports.answers = {
getAll: (req, res) => {

},
addAnswer: (req, res) => {

},
markAsHelpful: (req, res) => {

},
report: (req, res) => {

}
}
12 changes: 0 additions & 12 deletions server/controllers/product.js

This file was deleted.

Empty file removed server/controllers/qa.js
Empty file.
21 changes: 21 additions & 0 deletions server/controllers/questions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const axios = require('axios');

exports.questions = {
getAll: (req, res) => {
console.log('GET ALL REQ QUERY PARAMS IS ', req.query);
// getting with the params: product_id, page: 1 and count: 6
// page has potential to increase
// send back get request in the form of results (results.data.results, an arr)
},
addQuestion: (req, res) => {
console.log('POST REQ FOR QUESTION ', req.body)
//posting coming in with {...question, product_id}
// productId, body, name, email
},
markAsHelpful: (req, res) => {
console.log('PUT REQUEST FOR HELPFUL Qs ', req.body);
}
report: (req, res) => {
console.log('PUT REQUEST FOR REPORT Qs', req.body);
}
}
Empty file removed server/controllers/reviews.js
Empty file.
34 changes: 28 additions & 6 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
require('dotenv').config();
// const path = require('path');

const express = require('express');
const morgan = require('morgan');
const cors = require('cors');

const routes = require('./routes/index');
const questions = require('./controllers/questions');
const answers = require('./controllers/answers');

const app = express();

// Middleware

// Middleware - functions called between processing the request and sending the response in application.
app.use(cors());
app.use(morgan('dev'));

/* For POST and PUT requests, any time you're sending data
these will serve up a json object in the req.body
urlencoded will recognize incoming req object as strings or arrays
express.json will recognize incoming req obj as a json obj
alternative to urlencoded and express.json is body-parser:
app.use(bodyParser.json()) and app.use(bodyParser.urlencoded({extended: true})) */
app.use(express.urlencoded({ extended: true }));
app.use(express.json());

// Set up routes
app.use(routes);
app.get('/qa/questions', questions.getAll);
app.get('/qa/questions/:question_id/answers', answers.getAll);

app.post('/qa/questions', questions.addQuestion);
app.post('/qa/questions/:question_id/answers', answers.addAnswer);

app.put('/qa/questions/:question_id/helpful', questions.markAsHelpful);
app.put('/qa/answers/:answer_id/helpful', answers.markAsHelpful);

app.put('/qa/questions/:question_id/report', questions.report);
app.put('/qa/answers/:answer_id/report', answers.report);



const PORT = process.env.PORT || 3000;

app.listen(PORT, () => {
console.log(`Server available at http://localhost:${PORT}`);
});

module.exports = app;
9 changes: 0 additions & 9 deletions server/routes/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions server/routes/product.js

This file was deleted.

Empty file removed server/routes/qa.js
Empty file.
Empty file removed server/routes/reviews.js
Empty file.