The source code of the catering ordering and delivery applet (source code of the takeaway ordering system)

  Using the catering ordering applet source code, you can build a system that allows your restaurant or cafe to take orders and accept payments remotely - online and in person. With this system, customers simply access the menu via mobile ordering. This can be done by scanning a QR code or entering a link in the search bar. Once your customers make their selections, they submit their order and make a one-time payment. Once the order is received at the restaurant end, all that remains is to bring the order to the customer's table or pack it up for delivery. This greatly speeds up the entire online ordering process. Everything happens via smartphone instead of constant back and forth with employees.
  
  The source code development environment of the catering ordering and delivery applet
  
  Demo: c.ymzan.top
  
  The source code of the catering ordering and delivery applet runs on docker, the image is specified in the docker-compose.yml file, and is started by docker -compose.
  
  Spring Data Rest for fast database access and authentication.
  
  Spring Boot for rapid REST API development and standalone deployment.
  
  Spring Boot Actuator is used to provide monitoring information.
  
  HAL browser for fast repository exploration.
  
  Lombok is used to eliminate constructors and getter/setter implementations for a cleaner coding style.
  
  Spring Cloud is used to provide infrastructure services.
  
  Eureka is used for microservice registration and discovery.
  
  Hystrix acts as a circuit breaker when the system fails in an avalanche.
  
  RabbitMQ is used to decouple microservices.
  
  WebSocket is used to send messages to UI.
  
  RestTemplate is used to communicate between microservices.
  
  restaurant service
  
  Search restaurants by name

  GET localhost:8001/api/restaurants?name=<restaurant_name>
Return
{
    "id": <restaurant_id>,
    "name": <restaurant_name>
}

  create restaurant

POST localhost:8001/api/restaurants
Request Body
{
    "name": <restaurant_name>
}
Return HttpStatus.CREATED

  Get all menu items by restaurant id

GET localhost:8001/api/restaurants/{restaurantId}/menuItems
Return
[
    {
        "id": <menu_item_id>,
        "restaurantId": <restaurantId>,
        "name": <menu_item_name>,
        "description": <menu_item_description>,
        "price": <menu_item_price>
    },
    ...
]  

  Create menu items 

POST localhost:8001/api/restaurants/{restaurantId>/menuItems
Request Body
{
        "restaurantId": <restaurantId>,
        "name": <menu_item_name>,
        "description": <menu_item_description>,
        "price": <menu_item_price>
}
Return HttpStatus.CREATED

  Bulk upload menu items

POST localhost:8001/api/restaurants/bulk/menuItems
Request Body
[
    {
        "restaurantId": <restaurantId>,
        "name": <menu_item_name>,
        "description": <menu_item_description>,
        "price": <menu_item_price>
    }
]
Return HttpStatus.CREATED

  Order service
  
  Create order 

POST localhost:8002/api/restaurants/{rid}/orders
{
    "restaurantId": <restaurant_id>,
    "items":
    [
        {
            "name": <menu_item_name>,
            "price": <menu_item_price>,
            "quantity": <# of items>
        },
        ...
    ],
    "userInfo":
    {
        "firstName": <customer_first_name>,
        "lastName": <customer_last_name>,
        "phone": <customer_phone>,
        "address": <customer_address>
    },
    "specialNote": <special_note>
}
Return:
HttpStatus.CREATED
{
    "id": <order_id>,
    "restaurantId": <restaurant_id>,
    "items":
    [
        {
            "name": <menu_item_name>,
            "price": <menu_item_price>,
            "quantity": <# of items>
        },
        ...
    ],
    "userInfo":
    {
        "firstName": <customer_first_name>,
        "lastName": <customer_last_name>,
        "phone": <customer_phone>,
        "address": <customer_address>
    },
    "specialNote": <special_note>,
    "totalPrice": <total_price>,
    "orderTime": <order_time_in_milliseconds>
}  

  Payment distribution service
  
  Payment distribution 

POST localhost:8003/api/payments
{
    "orderId": <order_id>,
    "amount": <payment_amount>,
    "creditCardInfo": 
    {
        "firstName": <first_name>,
        "lastName": <lastName>,
        "expiredMonth": <month>,
        "expiredYear": <year>,
        "securityCode": <security_code>
    }
}

Note: Since payment process can be slow and become a bottleneck in a busy environment, this API will send the payment information to message queue for Payment Service to process.

  Payment Services
  
  Process Payments 

POST localhost:8004/api/payments
{
    "orderId": <order_id>,
    "amount": <payment_amount>,
    "creditCardInfo": 
    {
        "firstName": <first_name>,
        "lastName": <lastName>,
        "expiredMonth": <month>,
        "expiredYear": <year>,
        "securityCode": <security_code>
    }
}
Return
HttpStatus.CREATED

Note: **Hystrix** fallbackMethod is added in case processPayment() fails.
Note: this API will store the payment into DB, find the matching order and update the order paymentId, deliveryTime, and notify Order Complete Service with RestTemplate. 

  Order Complete Updater Service
  
  Order Complete  

POST localhost:8005/api/orders
{
    "id": <order_id>,
    "items":
    [
        {
            "name": <menu_item_name>,
            "price": <menu_item_price>,
            "quantity": <# of items>
        },
        ...
    ],
    "userInfo":
    {
        "firstName": <customer_first_name>,
        "lastName": <customer_last_name>,
        "phone": <customer_phone>,
        "address": <customer_address>
    },
    "specialNote": <special_note>,
    "totalPrice": <total_order_price>,
    "orderTime": <order_time>,
    "deliveryTime": <food_delivery_time>,
    "paymentId": <payment_id>
}

Note: This API will serialize the order to WebSocket channel: "topic/orders", UI can subscribe to this channel to receive message and display to user. 

  getting Started

  docker-compose up -d

  Start MongoDB on Docker, RabbitMQ
  
  checks the data in MongoDB
  
  Find the mongodb container id

 docker ps

  Enter the mongodb container by typing the first 3 characters of the container id (eg: '9cd'), then type mongo inside the container to use the mongodb shell command.  

docker exec -it 9cd bash
# mongo                             // open mongo shell
> use test                          // Spring boot use test db as default
> show collections                  // show all collections inside test db
> db.restaurant.find().pretty()     // show all data inside restaurant table
> exit                              // quit mongo shell
> exit                              // exit container shell

  Install

mvn clean install

  start up

sh ./start-eureka.sh

  Start Hystrix

sh ./start-hystrix.sh

  start restaurant service

sh ./start-restaurant-service.sh

  Start order service

sh ./start-order-service.sh

  Start payment allocation  

 sh ./start-payment-distribution.sh

  Start payment service

sh ./start-payment-service.sh

  Start the order fulfillment update process

sh ./start-order-complete-updater.sh

  Upload test menu item

cd restaurant-service
sh ./upload-menu-items.sh

Note: default restaurant id for testing: "11111111-1111-1111-11111111111111111".

  Explore with the HAL browser

http://localhost:8001/browser/index.html

port: 8001 can be changed for different services.

  Investigate registry services in Eureka

http://localhost:8761

  Investigate message queues in RabbitMQ

http://localhost:15762
Go to Queues -> binder.payments

  Checkout Application Metrics

http://localhost:8005/health
http://localhost:8005/env
http://localhost:8005/metrics
http://localhost:8005/mappings

Note: 8005 can be changed for different services. 

  Test the workflow with PostMan
  
  Create an order 

POST localhost:8002/api/restaurants/11111111-1111-1111-11111111111111111/orders
{
    "restaurantId": "11111111-1111-1111-11111111111111111",
    "items": [
        {
            "name": "menuItem 1",
            "price": 11,
            "quantity": 2
        },
        {
            "name": "menuItem 2",
            "price": 12,
            "quantity": 3
        }
    ],
    "userInfo": {
        "firstName": "first1",
        "lastName": "last1",
        "phone": "14081234567",
        "address": "123 stree1 ave, San Jose, CA 95123"
    }
}
Returns:
Returns:
{
    "id": "5903e81327b884525eb9a5be",
    ...
    "totalPrice": 58,
    ...
}

  post order payment

POST localhost:8003/api/payments
{
    "amount": 58,
    "orderId": "5903e81327b884525eb9a5be",
    "creditCardInfo": {
        "firstName": "first 1",
        "lastName": "last 1",
        "expiredMonth": "02",
        "expiredYear": "2019",
        "securityCode": "231"
    }
}  

  Check RabbitMQ and you'll see a message queued by payment-distribution and consumed by payment-service.
  
  In the log of order-complet-updater you will see the following message: "Receive order = Order(id=5903e81327b884525eb9a5be, ..." "WebSocketSession[1 current WS(1)-HttpStream(0)-HttpPoll(0) , a total of 3..."
  
  So the message has been sent by the order-complete-updater via WebSocket.
  
  To see the message with the test UI:

localhost:8005
Click on "Subscribe to Order Complete Updates" to subscribe the channel.
Click on "Send Test Message" to send out the test JSON object. 

  Review the message received in the bottom text box. 

Subscribed to /topic/orders
sendMessage triggered
{
  "id": "5903e81327b884525eb9a5be",
  "restaurantId": "11111111-1111-1111-11111111111111111",
  "items": [
     {
       "name": "menuItem 1",
       "price": 11,
       "quantity": 2
     },
     {
       "name": "menuItem 2",
       "price": 12,
       "quantity": 3
     }
  "totalPrice": 58,
  "orderTime": 1493428243933,
  "specialNote": "",
  "deliveryTime": 1493486808730,
  "paymentId": "",
  "userInfo": {
     "id": "",
     "firstName": "first1",
     "lastName": "last1",
     "phone": "14081234567",
     "address": "123 stree1 ave, San Jose, CA 95123"
  }
}  

  Test the fallback
  
  Open the Hystrix Dashboard

localhost:7979

  Monitor Order Completion Update Program  

http://localhost:8004/hystrix.stream

  Stop the order completion updater. Post the payment to the payment service. The error rate jumped from 0.0 to 100%. Look in the logs for error messages from fallback methods. Post the same payment over and over again, and eventually, see the circuit status change from "closed" to "open".
  
  Features of the source code of the catering ordering and delivery applet
  
  Users can search for restaurants by restaurant name.
  
  A user can order food by selecting different menu items, quantities and adding notes about his/her dietary restrictions etc.
  
  Users can fill in the delivery address.
  
  After the user places an order, the order should include the food ordered by the user, quantity, price and order time.
  
  User needs to pay for his/her order by providing credit card number, expiry date and security code.
  
  After the payment is successful, return the payment ID, timesatmp, then the order is considered complete and the user can see the estimated delivery time.
  
  Estimated delivery time is a random time between 5 minutes and 1 hour.  



  
  1. Safer and healthier To   reopen
  
  , food businesses need to open a store to meet health and safety regulations. Owners must maintain social distancing, use contactless ordering/payment methods, and ensure surfaces are cleaned regularly.
  
  Even if you run a small business, social distancing doesn't have to be stressful. Moving to online ordering sites for businesses means that new customers who walk in can order and pay outside the store or at a table inside the store.
  
  2. Less room for error
  
  One of the advantages of the source code of the food ordering applet is that it can ensure that the price is accurate and there is less room for error at the checkout. This is because customers need to physically select the correspondingly priced item from the menu to ensure they always pay the correct amount. This has some benefits for your business. Less chance of being billed incorrectly, less time wasted cleaning up mistakes, and less free product handed out to appease customers!
  
  3. More customers
  
  As social distancing continues, online ordering and payment is becoming more accepted and expected. If your menu and payment system work without any hassle, your regular customers will recommend you to their friends and share it on social media. Simply provide a seamless customer experience, sending orders to your backend team in real-time, and you can grow customers and profits.
  
  4. Increase customer loyalty Customers
  
  will choose your store over your competitors' stores if you give them a reason to keep coming back. Great products might be the reason, but you can also encourage their loyalty with a rewards program on your ordering app. With the catering applet source code, you can send personalized offers, request reviews to improve your rating, and receive feedback on your service.
  
  5. Higher customer spend
  
  We know that more customers than ever before are engaging with digital products and services. When customers order online, the order value increases. That's because learning the online menu is different than standing in line. Customers have more time to make informed decisions. Those with food intolerances can clearly read all the necessary information and take their time.
  
  6. Highly Customizable
  
  The menu app is highly customizable, so you can easily promote your logo, brand colors, or other features that make your business unique. Plus, if you want to remove or add items to your menu, all you have to do is log in, make your changes and you're done!
  
  7. Reduce costs
  
  With card terminals, you're looking at some accompanying fees that can seriously dent your bottom line. Small business ordering systems are much cheaper because it's all digital, and in many cases the only cost is a small processing fee for the transaction.

 

Guess you like

Origin blog.csdn.net/momoxio/article/details/127769465