2022-09-25 17:18:55 +00:00
|
|
|
# Modeling for simple shop scenario
|
|
|
|
|
2022-09-26 07:18:20 +00:00
|
|
|
## Register
|
2022-09-25 17:18:55 +00:00
|
|
|
|
2022-09-26 07:18:20 +00:00
|
|
|
```ts
|
2022-09-25 17:18:55 +00:00
|
|
|
yarn pm add sample-shop-modeling
|
|
|
|
```
|
|
|
|
|
2022-09-26 07:18:20 +00:00
|
|
|
## Activate
|
|
|
|
|
|
|
|
```bash
|
|
|
|
yarn pm enable sample-shop-modeling
|
|
|
|
```
|
2022-09-25 17:18:55 +00:00
|
|
|
|
2022-09-26 07:18:20 +00:00
|
|
|
## Launch the app
|
2022-09-25 17:18:55 +00:00
|
|
|
|
|
|
|
```bash
|
2022-09-26 07:18:20 +00:00
|
|
|
# for development
|
|
|
|
yarn dev
|
|
|
|
|
|
|
|
# for production
|
2022-09-26 15:47:07 +00:00
|
|
|
yarn build
|
2022-09-26 07:18:20 +00:00
|
|
|
yarn start
|
2022-09-25 17:18:55 +00:00
|
|
|
```
|
|
|
|
|
2022-09-26 07:18:20 +00:00
|
|
|
## Connect to the API
|
|
|
|
|
2022-09-25 17:18:55 +00:00
|
|
|
### Products API
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# create a product
|
2022-09-29 13:03:35 +00: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-25 17:18:55 +00: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 13:03:35 +00: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-25 17:18:55 +00:00
|
|
|
|
|
|
|
# list orders which userId=1 with product
|
|
|
|
curl 'http://localhost:13000/api/orders?filter={"userId":1}&appends=product'
|
|
|
|
```
|