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

Feature testing #9

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/node_modules
/static/bundle.js
/static/bundle.map.js
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
93 changes: 11 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,17 @@
# Delivereat
DeliverRabbit: A food delivery app

Let's create an app that allows customers to order food online.
What the project does?
It provides a menu on load. Menu items can be added to an order.

A few notes before we get started
What technologies it uses?
Node.js and React.

* Fork and clone repo at [https://github.com/constructorlabs/delivereat](https://github.com/constructorlabs/delivereat)
* Start by building the simplest thing that works. Add to it as you go along. Test your application as frequently as possible to make sure it does what you expect
* Create a RESTful API for your service. Think about a good way to organise your API into **nouns** and **verbs**, which correspond to **resources** and **HTTP methods**
* Split your code into an API on the server and render data from server in browser using React.
* Splitting out our application into an API and interface allows us to re-use the API. For example we could use it to create a native mobile app or allow third parties to place orders on our system
* Commit frequently and push to Github
* Implement features one at a time
* Make sure your app is responsive
* You may want to design the API first, before implementing the UI that uses and API
Functionality still to include:

## Features
- Minimum order logic
- Notification upon order submission
- Orders Admin Dashboard with html injected into handlebars template

**Menu**
* Design a menu for a restaurant such as food items, prices etc. By providing each item with an id we can refer to it later. The first item has already been created for you. Feel free to amend it.
* Create an API endpoint that returns a menu of items with prices available to order
* Create a page that displays the menu to the user using the API
Known bugs to fix:

**Order**

* Update the menu page to make it an order page
* It should allow the user to specify quantities of items to order
* It should add a delivery charge and display the total order cost
* Create an API to receive and save the submitted order

**Closures**

* Rather than storing all data in global scope on the server, try to implement data manipulation and retrieval functionality using closures.

**Order history**

* Allow the user to see their order history
* Allow the user to re-order same items again
* Allow users to delete items from order history

**Extension**

* Design and implement an extension of your choosing

## Stretch goals

**Admin**

* Create a new page for the restaurant owner to see all orders coming in
* When an order is ready to ship the restaurant owner needs to be able to mark the order as sent
* Create an API endpoint to receive and update order status

**Notification**

* Send the user an SMS using [Twilio](https://www.twilio.com/) when their order is ready

## Technical notes

* Run `npm install` after cloning to download all dependencies
* Use `npm run dev -- --watch` to build React
* Use `node index.js` to run the Node server in another tab
* Place all static files such as images and CSS in the `static` folder. When requesting those files from the server use `/static` at the beginning of the URL. For example `<link rel="stylesheet" type="text/css" href="/static/styles.css">`
* `bundle.js` produced by webpack will be output in the `static` folder
* To send data server using a POST, PUT or PATCH request you can do something the example below, where `order` is an object we want to send to the server and `http://localhost:8080/api/order` is URL we want to send it to.

```js
fetch('http://localhost:8080/api/order', {
method: 'post',
body: JSON.stringify(order),
headers: {
'Content-Type': 'application/json'
}
}).then(function(response) {
return response.json();
}).then(function(data) {
// handle response
});
```

* Check out [Nodemon](https://nodemon.io/) to automatically rebuild and restart your server when changes are saved.

## README

* Produce a README.md which explains
* what the project does
* what technologies it uses
* how to build it and run it
* any unresolved issues the user should be aware of
- Selecting an item will place it in the basket, if the amount ordered is decreased to zero, it will still remain in the basket, if there are any other items ordered.
132 changes: 122 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,135 @@
const express = require('express');
const bodyParser = require('body-parser');
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const port = process.env.PORT || 8080;

app.use(bodyParser.json());
app.use('/static', express.static('static'));
app.set('view engine', 'hbs');
app.use("/static", express.static("static"));
app.set("view engine", "hbs");

const menu = {
0: {
id: 0,
name: "Strawberry cheesecake",
price: 6,
img: "../static/cheesecake.jpg",
desc:
"Baked cheesecake on a sweetmeal biscuit base topped with strawberries in a sauce"
},
1: {
id: 1,
name: "Strawberry cheesecake",
price: 6
name: "Chocolate Cake",
price: 5,
img: "../static/chocolatecake.jpg",
desc: "Chocolate Cake layered and topped with Belgian Chocolate Buttercream"
},
2: {
id: 2,
name: "Victoria Sponge",
price: 7,
img: "../static/victoriasponge.jpg",
desc:
"Layers of sponge sandwiched with buttercream and raspberry jam, topped with a dusting of sugar"
},
3: {
id: 3,
name: "Muffin",
price: 3,
img: "../static/muffin.jpg",
desc: "Vanilla flavour mini muffins with milk chocolate chips"
},
4: {
id: 4,
name: "Crumpet",
price: 4,
img: "../static/crumpet.jpg",
desc: "Soft, fluffy and deliciously gluten free"
},
5: {
id: 5,
name: "Waffles",
price: 5,
img: "../static/waffles.jpg",
desc:
"Soft, toasted waffles and their characteristic sweet, creamy caramel fillings"
},
6: {
id: 6,
name: "Custard Tart",
price: 8,
img: "../static/custardtart.jpg",
desc:
"Shortcrust pastry tarts filled with egg custard made with free range eggs, topped with nutmeg"
},
7: {
id: 7,
name: "Lemon Tart",
price: 1,
img: "../static/lemontart.jpg",
desc: "Shortcrust pastry with lemon filling and a sugar dusting"
}
};

app.get('/', function(req, res){
res.render('index');
const orders = {};

app.get("/", function(req, res) {
res.render("index");
});

//// Gets all menu items
app.get("/menu", function(req, res) {
res.json(menu);
});

//// Gets specific menu item
function getItem(menu, item) {
return menu[item];
}
app.get("/menu/:item", function(req, res) {
const menuItem = getItem(menu, req.params.item);
res.json(menuItem);
});

/// Create new order
function createOrder(newOrder) {
const lastId = Object.keys(orders).pop();
const id = lastId ? lastId : 0;
const newId = +id + 1;
newOrder.id = newId;
orders[newId] = newOrder;
return newOrder;
}

app.post("/order", function(req, res) {
const newReq = createOrder(req.body);
res.json(orders);
});

//// Gets all orders
app.get("/order", function(req, res) {
res.json(orders);
});

//// Gets specific order
function getOrderByNumber(orders, order) {
return orders[order];
}

app.get("/order/:orderNum", function(req, res) {
const specificOrder = getOrderByNumber(orders, req.params.orderNum);

if (specificOrder) {
res.json(specificOrder);
} else {
res.status(404).json({ error: "Order not found" });
}
});

app.listen(8080, function(){
console.log('Listening on port 8080');
// Local Server Listener
// app.listen(8080, function() {
// console.log("Listening on port 8080");
// });
// Heroku Server
app.listen(port, function() {
console.log(`Listening on port number ${port}`);
});
Loading