2022-09-26 01:18:55 +08:00
|
|
|
# Modeling for simple shop scenario
|
|
|
|
|
2022-09-26 15:18:20 +08:00
|
|
|
## Register
|
2022-09-26 01:18:55 +08:00
|
|
|
|
2022-09-26 15:18:20 +08:00
|
|
|
```ts
|
2022-09-26 01:18:55 +08:00
|
|
|
yarn pm add sample-shop-modeling
|
|
|
|
```
|
|
|
|
|
2022-09-26 15:18:20 +08:00
|
|
|
## Activate
|
|
|
|
|
|
|
|
```bash
|
|
|
|
yarn pm enable sample-shop-modeling
|
|
|
|
```
|
2022-09-26 01:18:55 +08:00
|
|
|
|
2022-09-26 15:18:20 +08:00
|
|
|
## Launch the app
|
2022-09-26 01:18:55 +08:00
|
|
|
|
|
|
|
```bash
|
2022-09-26 15:18:20 +08:00
|
|
|
# for development
|
|
|
|
yarn dev
|
|
|
|
|
|
|
|
# for production
|
2022-09-26 23:47:07 +08:00
|
|
|
yarn build
|
2022-09-26 15:18:20 +08:00
|
|
|
yarn start
|
2022-09-26 01:18:55 +08:00
|
|
|
```
|
|
|
|
|
2022-09-26 15:18:20 +08:00
|
|
|
## Connect to the API
|
|
|
|
|
2022-09-26 01:18:55 +08:00
|
|
|
### Products API
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# create a product
|
2022-09-29 21:03:35 +08:00
|
|
|
curl -X POST -H "Content-Type: application/json" -d '{"title": "iPhone 14 Pro", "price": "7999", "enabled": true, "inventory": 10}' "http://localhost:13000/api/products"
|
2022-09-26 01:18:55 +08:00
|
|
|
|
|
|
|
# list products
|
|
|
|
curl "http://localhost:13000/api/products"
|
|
|
|
|
|
|
|
# get product which id=1
|
|
|
|
curl "http://localhost:13000/api/products?filterByTk=1"
|
|
|
|
```
|
|
|
|
|
|
|
|
### Orders API
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# create a order
|
2022-09-29 21:03:35 +08:00
|
|
|
curl -X POST -H "Content-Type: application/json" -d '{"productId": 1, "quantity": 1, "totalPrice": "7999", "userId": 1}' 'http://localhost:13000/api/orders'
|
2022-09-26 01:18:55 +08:00
|
|
|
|
|
|
|
# list orders which userId=1 with product
|
|
|
|
curl 'http://localhost:13000/api/orders?filter={"userId":1}&appends=product'
|
|
|
|
```
|