Skip to content

Commit

Permalink
Merge pull request #4 from kaiwalyakoparkar/dev
Browse files Browse the repository at this point in the history
feat: 🚀 Post request handled
  • Loading branch information
kaiwalyakoparkar authored Sep 4, 2021
2 parents 22e1259 + 4275d32 commit 50c8fd9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 168 deletions.
20 changes: 20 additions & 0 deletions controllers/operationsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require('path');
const feed = require('../dev-data/data/feed.json');
const fs = require('fs');

exports.getFeed = (req, res) => {
res.status(200).json({
Expand All @@ -9,3 +11,21 @@ exports.getFeed = (req, res) => {
},
});
};

exports.createFeed = (req, res) => {
const newFeed = req.body;
feed.push(newFeed);

fs.writeFile(
path.join(__dirname, '../dev-data/data/feed.json'),
JSON.stringify(feed),
(err) => {
res.status(201).json({
status: 'success',
data: {
feed,
},
});
}
);
};
168 changes: 1 addition & 167 deletions dev-data/data/feed.json
Original file line number Diff line number Diff line change
@@ -1,167 +1 @@
[
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
},
{
"profilePicture": "https://i.imgur.com/R4ikJd1.jpg",
"username": "Andreas Brixen",
"posts": [
{
"postImg": "https://i.imgur.com/l8rN74g.png",
"caption": "A good old book."
}
],
"points": 80
}
]
[{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"https://i.imgur.com/R4ikJd1.jpg","username":"Andreas Brixen","posts":[{"postImg":"https://i.imgur.com/l8rN74g.png","caption":"A good old book."}],"points":80},{"profilePicture":"trial","username":"trial trial","posts":[{"postImg":"trial","caption":"trial."}],"points":80}]
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('dotenv').config();
const morgan = require('morgan');

const app = express();
app.use(express.json());

if (process.env.DEV_ENVIRONMENT === 'development') {
app.use(morgan('dev'));
Expand Down
5 changes: 4 additions & 1 deletion routes/operationsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const route = express.Router();

const operationsController = require('../controllers/operationsController.js');

route.route('/').get(operationsController.getFeed);
route
.route('/')
.get(operationsController.getFeed)
.post(operationsController.createFeed);

module.exports = route;

0 comments on commit 50c8fd9

Please sign in to comment.