Permalink
Browse files

changes

  • Loading branch information...
maij committed Feb 13, 2020
1 parent fe682a3 commit 27a577e253f4cb8c4c227a73e701f5440122b7e8
@@ -0,0 +1,7 @@
function appIndex(req, res) {
res.send('Hello from the application index page');
}

module.exports = {
index: appIndex,
};
@@ -0,0 +1,34 @@
const express = require('express');
const router = express.Router();

const userModel = require('../models/user.js');

router.get('/', function(req, res) {
const allUsers = userModel.index();
res.render('user/index', {users: allUsers});
});

router.get('/new', function(req, res) {
res.render('user/new');
});

router.post('/', function(req, res) {
const newUser = req.body;
userModel.create(newUser);
res.send('ok');
});

router.get('/:index', function(req, res) {
res.render(
'user/show',
{
user: userModel.show(req.params.index)
});
});

router.delete('/:index', function(req, res) {
userModel.delete(req.params.index);
res.send('user deleted');
})

module.exports = router;
No changes.
@@ -0,0 +1,27 @@
// Keep track of users here instead of using a database.
// NOTE: Don't do this for your projects! This data will
// disappear whenever you restart your server.
const users = [];

function userIndex() {
return users;
}

function showUser(index) {
return users[index];
}

function createUser(newUser) {
users.push(newUser);
}

function deleteUser(index) {
users.splice(index, 1);
}

module.exports = {
index: userIndex,
show: showUser,
create: createUser,
delete: deleteUser,
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,59 +1,22 @@


const express = require('express');
const express = require('express')
const app = express();
app.use(express.urlencoded({ extended: true }));
app.set('view engine', 'hbs');

app.use(express.json());
const userController = require('./controllers/userController.js');
app.use('/user', userController);

const shops = [];

function getShops() {
return shops;
}

function getShop(index) {
return shops[index];
}

function addShop(newShop) {
shops.push(newShop);
return shops.indexOf(newShop);
}

function deleteShop(index) {
shops.splice(index, 1);
}

function updateShop(index, shop) {
shops[index] = shop;
}

app.get('/shops', function(req, res) {
res.send(getShops());
app.get('/', (req, res) => {
res.render('index')
});

app.get('/shops/:index', function(req, res) {
res.send(getShop(req.params.index));
});
// process.env.PORT is necessary for deployment to Heroku
// If environment variable is not provided, default to 3000
const PORT = process.env.PORT || 3000

app.post('/shops', function(req, res) {
addShop(req.body);
res.send('ok');
});

app.delete('/shops/:index', function(req, res) {
deleteShop(req.params.index);
res.send('ok');
});
app.listen(PORT, () => {
console.log(`Server is listening on PORT: ${PORT}`)
})

app.put('/shops/:index', function(req, res) {
updateShop(req.params.index, req.body);
res.send('ok');
});

const port = process.env.PORT || 3000;
app.listen(port, function() {
console.log('Listening on port ' + port);
});
// curl -s -w "\n" -X post localhost:3000/addShop --header "Content-Type:
// application/json" --data 'name': 'LadyCoffee', 'open': true
No changes.
No changes.
@@ -0,0 +1,2 @@
<h1>Welcome to Chirp</h1>
<p>An awesome app that is definitely not a Twitter rip-off.</p>
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Chirp</title>
<!-- Static assets can go in here! -->
<!-- <link rel="stylesheet" type="text/css" href="/css/styles.css"> -->
</head>
<body>
{{{ body }}}
<!-- The body tag is what our templates will be replacing. -->
</body>
</html>

0 comments on commit 27a577e

Please sign in to comment.