Bagel Site



Create a web site that allows customers from all over the country to order New York Bagels and have them delivered to their door the next day,

The site will have 3 Tables

Customer Table

 Name, address, phone

This will be a web form and store data into a dynamoDB table called Customer

Product Table

File will contain the product name and price of product

This will be maintained directly on the DynamoDB Services menu



Order Table

File will contain
Date order taken
Customer Name from Customer table
Product Name from Product table
amount of bagels
total amount of order

Customers must create a customer account with shipping information

Once order is created a formatted order form will display in the customers browser window

const AWS = require('aws-sdk');
const querystring = require('querystring');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

// Set this to the region you upload the Lambda function to.
AWS.config.region = 'us-east-1';

exports.handler = function(evt, context, callback) {
    // Our raw request body will be in evt.body.
    const params = querystring.parse(evt.body);

    // Our field from the request.
    const my_name = params['my-name'];
    const my_bagel = params['my-bagel'];
    const my_number = params['my-number'];

 
    var newrec = {
        Item: {
            date: Date.now(),
            name: my_name,
            bagel: my_bagel,
            phone: my_number
        },
        TableName: 'Orders'
        };
 
        docClient.put(newrec, function(err, data){
        if (err){
            callback(err, null);
        }else{
           const html = `<!DOCTYPE html><p>Customer Name: ` + my_name + ` <br> Bagel Type :
        ` + my_bagel + `<br> Order Amt`+  my_number + `</p>`;     
            callback(null, html);
         
        }
        });
        };

Order.html

<html>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: black;}
</style>
<h1>
</h1>
<h1 style="font-family: Verdana, sans-serif;">Order form</h1>
<br>
<br>
<form method="POST" action="https://j8tnvd2drf.execute-api.us-east-1.amazonaws.com/prod">
Name: <input type="text" name="my-name"><br><br>
Bagel:
<select name="my-bagel">
<option value="volvo">plain</option>
<option value="saab">wheat</option>
<option value="fiat">sesame seed</option>
<option value="audi">cinnamon raisin</option>
<option value="audi">poppy seed</option>
<option value="audi">everything</option>
</select>
<br><br>
Number: <input type="text" name="my-number">
<input type="submit" value="Submit form">
</form>
<img src="images/Bagel-Plain-Alt.jpg" alt="Plain Bagel" width="300" height="300">
</html>


No comments:

Post a Comment

To All, If you are working in starter accounts please move the work into the classroom account so I can review. For the previous ...