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

Need to write readme .... #16

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dcf0c3a
taking orders and semi styled - should have done a commit earlier!
philberryman Oct 14, 2018
291051d
Trying to get confirmation page working. Also - grid is not playing n…
philberryman Oct 14, 2018
6296d6f
Done for the weekend
philberryman Oct 14, 2018
746e306
working with transactions
philberryman Oct 18, 2018
9243563
orders being sent into database with orderId returned to confirmation…
philberryman Oct 18, 2018
99ff92c
orders being sent into database with orderId returned to confirmation…
philberryman Oct 18, 2018
7f7c0d6
removed bundle file
philberryman Oct 18, 2018
e551763
Merge branch 'delivereat-sql'
philberryman Oct 18, 2018
e99793d
login nearly working
philberryman Oct 18, 2018
c315124
working on registration page
philberryman Oct 18, 2018
0b555bb
account creating and login working - no validation or error handling yet
philberryman Oct 19, 2018
9a022d3
SMS sent on confirmation
philberryman Oct 19, 2018
e8c4ff1
fixed issue where customer was fixed as customer 1. Whoops.
philberryman Oct 19, 2018
ecd4f17
Decided it was about time I wrote some tests (for Order.js)
philberryman Oct 19, 2018
2c645cb
made order a stateless componenent
philberryman Oct 19, 2018
be11f68
made more componenents stateless
philberryman Oct 21, 2018
a54b753
fixed bug in OrderItems componenent (pizzas not showing)
philberryman Oct 21, 2018
d370787
starting to implement admin screen
philberryman Oct 21, 2018
a7f9dc1
admin console is taking shape. Very basic
philberryman Oct 21, 2018
38c5318
added node version into package.json to enable heroku deployment
philberryman Nov 28, 2018
7a8230f
fixed event-stream library
philberryman Nov 28, 2018
873f964
adding config for Heroku
philberryman Nov 28, 2018
2ef59aa
adding config for Heroku
philberryman Nov 28, 2018
7a73f6c
updated database.sql
philberryman Nov 28, 2018
7ef81ac
Update README.md
philberryman Nov 28, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/static/bundle.js
/static/bundle.js.map
.DS_Store
.env
93 changes: 26 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,36 @@
# Delivereat
# Pizza Co 90 30 - A simply pizza delivery app

Let's create an app that allows customers to order food online.
https://pizzaco9030.herokuapp.com/

A few notes before we get started
This was a weekend project built during my amazing 12 weeks at Constructor Labs (a Javascript focussed bootcamp)

* 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
The task was to build a restaurant delivery app for the restaurant of our choice. Mine was for a Neopolitan style pizza restaurant. Pizza 90 30. Pizzas cooked in 90 seconds and delivered in 30 mins. All fictional. You will get hungry if you expect the pizza to arrive.

## Features
## Technology Used

**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
* React
* Node.js
* REST API
* Postgres database (holding menu, customers, orders)
* CSS Grid
* SCSS
* Twilio API for SMS confirmation

**Order**
## To run this code

* 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
* Fork the repo
* npm i
* Use the database.sql to setup the Postgres database
* Create .env file with the following variables:
DB_NAME=
DB_USERNAME=
DB_PASSWORD=
PORT=8080
twilio_accountSid=
twilio_authToken=
twilio_number=

## Stretch goals
## Any questions or issues ...

**Closures**
Send me a message.

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

**Own feature**

* Design and implement a feature of your choosing

## Technical notes

* Run `npm install` after cloning to download all dependencies
* Use `npm run dev -- --watch` to build React
* Use `node server.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(data => {
// handle response
});
```

* Check out [Nodemon](https://nodemon.io/) to automatically rebuild and restart your server when changes are saved.
* Hint: keep menu data and order data separate. Rather than storing prices in orders, refer to the menu data. This prevents unnecessary data duplication and helps ensure we maintain a single source of truth for each data item.

## Next steps

* We will continue working on this project the following weekend where we will add database storage using Postgres and implement authentication using passport.

## 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
18 changes: 18 additions & 0 deletions common/orderTotals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function orderTotals(newOrder, menu) {
const itemsCost = Object.values(newOrder).reduce((acc,item) => acc + (menu[item.id].price * item.quantity),0)
const deliveryCost = itemsCost > 30? 0:5
console.log(deliveryCost + "ddddd");


return {
itemsCost: itemsCost,
deliveryCost: deliveryCost,
discount: itemsCost > 50? itemsCost/10:0,
deliveryMessage: itemsCost === 0?'Free delivery on orders over £30':itemsCost<30?`Spend £${30 - itemsCost} more for free delivery`: 'Delivery is Free!'
}
}


module.exports = {
orderTotals
}
51 changes: 51 additions & 0 deletions database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
DROP TABLE IF EXISTS customer;
DROP TABLE IF EXISTS menu;
DROP TABLE IF EXISTS transaction;
DROP TABLE IF EXISTS transaction_item;



CREATE TABLE public.customer (
id serial,
email character varying(255) NOT NULL,
name character varying(255) NOT NULL,
company_name character varying(255),
street_address character varying(100) NOT NULL,
town character varying(60) NOT NULL,
post_code character varying(9) NOT NULL,
telephone character varying(15) NOT NULL,
delivery_info character varying(255) NOT NULL,
admin boolean
);


CREATE TABLE public.menu (
id serial,
name character varying(50) NOT NULL,
ingredients character varying(200) NOT NULL,
price numeric(5,2) NOT NULL
);


CREATE TABLE public.transaction (
id serial,
customer_id integer NOT NULL,
date_time timestamp without time zone NOT NULL,
status character varying(20) NOT NULL
);


CREATE TABLE public.transaction_item (
id serial,
transaction_id integer NOT NULL,
menu_id integer NOT NULL,
quantity integer NOT NULL
);

INSERT INTO menu (id, name, ingredients, price)
VALUES
(1, 'Marinara', 'Tomato sauce, garlic, basil, oregano, olive oil (v)',8.00),
(2, 'Margherita', 'Tomato sauce, fior di latte, basil, olive oil (v)',9.00),
(3, 'Funghi', 'White sauce, mushrooms, parmesan, aged mozzarella, roasted garlic, arugula (v)',12.00),
(4, 'Carciofi', 'Tomato sauce, artichokes, pancetta, cherry tomatoes, parmesan, aged mozzarella, basil',14.00),
(5, 'Calabrese', 'Tomato sauce, soppressata, fior di latte, nicoise olives, oregano', 14.00)
Loading