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

Roland's DeliverEat: Lovely Grubbly #6

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2519181
Database and server.js up and running
rolandjlevy Oct 18, 2018
f1d6f01
Starting with React - creating MenuItem components
rolandjlevy Oct 18, 2018
b47bf30
Working on getPurchaseById
rolandjlevy Oct 19, 2018
cb32087
Working on adding to basket
rolandjlevy Oct 19, 2018
37ec9e5
Planned structure of HTML and created ViewPurchase component
rolandjlevy Oct 19, 2018
0fc946d
Starting on adding current order to basket and add to all orders
rolandjlevy Oct 19, 2018
5957657
Looking into Twillio
rolandjlevy Oct 19, 2018
407cc64
Items being added into basket
rolandjlevy Oct 19, 2018
d4c71fd
Moved functions from App.js into child components
rolandjlevy Oct 19, 2018
36d1d6f
Filtering for menu courses
rolandjlevy Oct 20, 2018
bb32b0d
Filtering for menu courses working
rolandjlevy Oct 20, 2018
2b80808
Basket now working
rolandjlevy Oct 20, 2018
f9ed6d6
Some improvements with styling
rolandjlevy Oct 20, 2018
9cc8857
Changes to CSS
rolandjlevy Oct 20, 2018
b0f7f1d
Working on placing an order. getting order ID back.
rolandjlevy Oct 21, 2018
ff97bff
Viewing by order ID
rolandjlevy Oct 21, 2018
e447be0
Completed viewing orders with ID
rolandjlevy Oct 22, 2018
04ec765
Minor tweaks - no major changes
rolandjlevy Oct 22, 2018
36b9e11
Twillio working
rolandjlevy Oct 22, 2018
e4b46e9
Removed database.sql from .env
rolandjlevy Oct 23, 2018
52baa32
Updated readme
rolandjlevy Nov 30, 2018
870657d
Minor update to readme
rolandjlevy Nov 30, 2018
a587004
Update to readme
rolandjlevy Nov 30, 2018
0568072
Merge pull request #1 from rolandjlevy/staging
rolandjlevy Nov 30, 2018
191e879
Set theme jekyll-theme-minimal
rolandjlevy Dec 2, 2018
0319275
Update README.md
rolandjlevy Dec 2, 2018
127eae5
deleted _config.yml
rolandjlevy Dec 2, 2018
c0d899f
Updated files for Heroku deployment
rolandjlevy Dec 2, 2018
6f54396
Updated server.js with DB_HOST
rolandjlevy Dec 2, 2018
f842033
Fixed security vulnerbility with event-stream
rolandjlevy Dec 2, 2018
ed1d4e1
Updated readme file
rolandjlevy Dec 2, 2018
01b370a
Updated Heroku URL for Twilio integration
rolandjlevy Dec 3, 2018
a28eab3
Updated margins of buttons in ViewPurchases.scss
rolandjlevy Dec 3, 2018
3118afd
Updated images
rolandjlevy Dec 15, 2018
ea036b3
Updated images
rolandjlevy Dec 15, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/node_modules
.env
/dist
/static/images-local
/static/bundle.js
/static/bundle.js.map
.DS_Store
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node server.js
143 changes: 68 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,76 @@
# Delivereat
![Screenshot](./static/images/lovely-grubbly-screen-shots.png)

In this project we will create a database backed version of Delivereat. We will build it as a new project, but feel free to use your original Delivereat project as reference. Be aware that because the data structures we will be working with here are likely to be different, it may not be possible to directly re-use your UI components.
# Lovely Grubbly

A few notes before we get started
## Order takeaway food online for delivery
**Lovely Grubbly** is an online restaurant which brings the best local food to your doorstep. It allows you to browse the menu and add dishes to the shopping basket which shows a full breakdown of costs including dellivery. To place your order you enter your details and immediatly receive confirmation by text with an order ID.

* Fork and clone this repo
* 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
* 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
> [View the live demo](https://lovely-grubbly.herokuapp.com)

## Features
> [View the repo on Github](https://github.com/rolandjlevy/lovely-grubbly)

**Database and API**
---

* Design a database that will allow you to store a menu and orders. Start out with pen and paper first sketching out the tables and columns you will need, as well as the relationships between the tables.
* The database will need to store a menu which will contain item name and price. We will also need to store orders. Each order can have multiple menu items and each menu item can appear in multiple orders. Each menu item ordered will also need to have a quantity.
* Store the SQL commands used to create database and populate with initial data in a `database.sql` file in your repo. It will allow us to review your database code and also make it easy for you to rebuild database.
* Create a RESTful API that will allow you to get the menu and save new orders
* Test the API using Postman

**Menu**
* Design and build a front end UI that will load the menu from the API and display it to the user

**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 functionality to submit orders to the API and display a notification to the user with order id

## Stretch goals

**Own feature**

* Design and implement a feature of your choosing

**SMS notification**

* Add a phone number input to your UI and a column in orders table to store it.
* Update the API to receive the phone number as part of the order
* Sign up for an account with Twilio. It's an API that allows you to send SMS messages and do lots of other cool things with phones. Use the signup code WELOVECODE to receive $20 credit.
* Implement SMS notification using Twilio to send an SMS notification to a user letting them know that the order has been received.

**Unit tests**

* Add unit tests to your application where appropriate

## Technical notes

* Run `npm install` after cloning to download all dependencies
* Use `npm run dev -- --watch` to build React
* You will need to create a `.env` file to store your database credentials. Make sure you add it to `.gitignore` file so that the credentials do not get commit to git and end up in public.
* 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
});
## Installation and set up
+ Clone the project and run `npm install`
+ Create your own local PostreSQL database instance and create the tables by running `pgweb` navigating to localhost:8081 and running the query in the `database.sql` file.
+ Create a `.env` file with the following variables
```
DB_HOST=localhost
DB_NAME=
DB_USERNAME=
DB_PASSWORD=
TWILIO_SID_TEST=
TWILIO_AUTH_TEST=
TWILIO_SID_LIVE=
TWILIO_AUTH_LIVE=
```

* 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
+ Run `npm start` to launch the app and navigate to localhost:8080
+ Use `npm run dev -- --watch` to build React
+ Navigate to `localhost:8080` in your browser to view

### API Keys needed
+ [Twilio API](https://www.twilio.com/docs/libraries/node) - for sending booking confirmation by text

---

### Tech stack
+ React
+ PostgreSQL
+ Node.js
+ Express
+ Handlebars
+ SCSS
+ Classnames
+ Flex-box
+ Git

### Build tools
- Webpack
- Babel

### Stages of development
+ Planned structure of the database tables and their relationships
+ Created database tables, sourced text and image data, entered data into database tables
+ Set up and created the core functionality in React
+ Used SCSS and Flexbox to style the UI
+ Implemented functionality for:
> + menu listing page
> + shopping basket
> + viewing an order

### Functionality and features
+ Food courses, Startes / Mains / Desserts can be filtered
+ Menu items can be added, removed from the basket and increase/decreased in quantity
+ Added menu items can be viewed in the basket menu with a breakdown of costs
+ Each item has an image icon which is a tooltip showing a preview of the menu item
+ A booking can then be make by adding your name and number
+ You receive a booking confirmation by text with your booking ID
+ You can view your order by clicking on the member icon entering your order ID

### Desired features with more time
+ To have a responsive layout for tablet and desktop screen sizes
+ To calculate the estimated time of delivery based on the customer's location
+ To enable customers to track their order on their phone
+ Allow customers to amend their order within a limited time period
16 changes: 16 additions & 0 deletions basket-layout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Your Basket
==============

- 1 + Grilled Mexican Chicken
- 1 + Vegetarian - Tastiest Grilled Fajita
- 1 + Veggies to Ever Grace Your Burrito Meal
- 1 + Southwest, BBQ, Diet Coke, Sprite, Guacamole

Subtotal £39.99
Delivery Fee £2.99
Total £42.97

Name: ____________
Tel: ____________

[ Place Order ]
51 changes: 51 additions & 0 deletions database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
CREATE database cafe

DROP TABLE menu_purchase

-- create tables

CREATE table menu (
id serial PRIMARY KEY,
item text NOT NULL,
price numeric(4,2) NOT NULL,
img text NOT NULL,
course text NOT NULL
);

-- DROP TABLE menu_purchase
-- DROP TABLE purchase

CREATE table purchase (
id serial PRIMARY KEY,
name text NOT NULL,
telephone text NOT NULL,
created_at TIMESTAMP NOT NULL
);

CREATE table menu_purchase (
id serial PRIMARY KEY,
quantity numeric default 0,
menu_id smallint,
purchase_id smallint,
FOREIGN KEY (menu_id) REFERENCES menu (id),
FOREIGN KEY (purchase_id) REFERENCES purchase (id)
);

-- insert items into menu table

INSERT INTO menu (item, price, img, course) VALUES ('Mixed Salad', 6, 'mixed-salad.jpg', 'starter');
INSERT INTO menu (item, price, img, course) VALUES ('Fried Chicken', 7, 'fried-chicken.jpg', 'starter');
INSERT INTO menu (item, price, img, course) VALUES ('Vegetable soup', 5, 'vegetable-soup.jpg', 'starter');
INSERT INTO menu (item, price, img, course) VALUES ('Beef stew', 9, 'beef-stew.jpg', 'main');
INSERT INTO menu (item, price, img, course) VALUES ('Fish & chips', 11, 'fish-chips.jpg', 'main');
INSERT INTO menu (item, price, img, course) VALUES ('Pork chops & vegetables', 9, 'pork-and-veg.jpg', 'main');
INSERT INTO menu (item, price, img, course) VALUES ('Chocolate cake', 4, 'chocolate-cake.jpg', 'dessert');
INSERT INTO menu (item, price, img, course) VALUES ('Blueberry cheesecake', 3.50, 'blueberry-cheesecake.jpg', 'dessert');
INSERT INTO menu (item, price, img, course) VALUES ('Trifle', 3, 'trifle.jpg', 'dessert');

-- update for any changes
-- UPDATE menu SET item = 'Pork chops & vegetables', price = 10, img = 'pork-and-veg.jpg' WHERE id = 6

-- alter columns for any changes
-- ALTER TABLE purchase DROP COLUMN time;
-- ALTER TABLE purchase ADD COLUMN time TIMESTAMP NOT NULL;
32 changes: 32 additions & 0 deletions multiple-promise-jim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const purchases = {
"items": {
"1": {
"id": 1,
"quantity": 2
},
"2": {
"id": 2,
"quantity": 3
}
},
"name": "Matt",
"tel": "07901 972 811"
}

app.post("/order", (req, res) => {
// 1. insert into "order" table
db.one("INSERT INTO order (id) VALUES (DEFAULT) RETURNING id")
.then(result => {
const orderId = result.id;
const { items } = req.body;
// 2. insert into "order_item" table for each item
return Promise.all(items.map(item => {
return db.none(
"INSERT INTO order_item (menu_id, order_id, quantity) VALUES ($1, $2, $3)",
[item.menuItemId, orderId, item.quantity]
);
})).then(() => orderId);
})
.then(orderId => res.json({ orderId: orderId }))
.catch(error => res.json({ error: error.message }));
});
Loading