Design a food delivery system:

Functional Requirements:

User can search a restaurant based on restaurant name. Then user can order food by choosing different menu item, quantity and add a note about his/her diet restrictions and etc. User can also fills in the delivery address. After user places an order, the order should contain food items user ordered, quantity, price and order time. User then needs to pay for his/her order by providing credit card number, expiration date, and security code. After payment is made successfully, it should return payment ID, timestamp and then the order is considered as completed so the user can see the estimated delivery time.

Non-Functional Requirements:

Solution:

using four micro services:

  1. MenuDisplay Service
  2. OrderService: frontend

MenuDisplay Service

  1. MenuDisplay Service: frontend发送get请求后可以获取菜单(menu)。
    datatypes:
  • Menu: menuName, id, menuItems,
  • MenuItem: itemname, price, id

一直有个疑问:如果object内部自带list of object; e.g.: menuclass,Jackson (json <=>object) 和Spring data (object<=>database)能不能做自动转换:

image.png

答案是可以的!
用的是mongodb。

menuItem完全是正常的class
.

testing:

  1. post + http://localhost:9010/menu/upload to upload a list of menus.
  2. get + http://localhost:9010/menu/search/?menuName=Beijing Restaurant to search for a specific menu
  3. delete + http://localhost:9010/purge to completely delete the data.

Jackson 测试时几个工具:
ObjectMapper: 将jsonfile转化成object,详情见spring-cloud-running-service
Repository:可以越过service layer在rest api里面直接调用repository。便于调试。
其实直接写一个jackson的deserializer也不是很复杂:https://stackoverflow.com/questions/35724693/jackson-deserialize-object-with-list-of-springs-interface
这里有各种Jackson的notation的用例: http://www.baeldung.com/jackson-annotations

  1. OrderService: frontend发送post请求可以提交order--将点单放到
  • order:

bug 1

今天写food-delivery service时遇到这个问题:

** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

在网上查了相关资料原因如下

You need to move your code into a package of its own. For example, move your .java files into src/main/java/com/example and add package com.example; to the top of each file.

结论:因为application.java文件不能直接放在main/java文件夹下,必须要建一个包把他放进去

Ref: http://kingschan.51so.info/entry/8af4dd795a08145a015a11829d0f0965

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。