-
Notifications
You must be signed in to change notification settings - Fork 38
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
HL - DeliverEAT App #7
Open
HTLuff
wants to merge
13
commits into
constructorlabs:master
Choose a base branch
from
HTLuff:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
077422e
menu items and price rendering on screen after CDM and fetch call
cc7f162
current order functionality now capturing form changes
41ac220
some styling added for header and fonts
8937137
removed add to order bytton
2a2d87f
menu section complete before develop restructuring
5765c36
app architecture now better with data stored in top level
68c1bc9
orders now being submitted
006856d
extensive css added
809a9aa
submit button now clears basket
00677e2
basket submit button now resets input fields
a193b2f
heroku command tools installed
61b4624
changes made to server file amand app.listen function
a1fbaf2
commit bundle
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
/node_modules | ||
/static/bundle.js | ||
/static/bundle.map.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice