#491 修改 /api/factories 的回傳格式,一次回傳 factories, documents 與 report_records 減少前端需要的 query 次數
<https://user-images.githubusercontent.com/126123/106724389-22588280-6643-11eb-8067-11d53535f842.png|image>
`/api/statistics/factories`
參數有
• townname
• source
• display_status
• level
前三個是之前就有的就不多解釋,最主要就是多了一個 level
level 可以接受的值是 `city` 與 `town`
e.g.
`/api/statistics/factories`
回傳全台灣的資料,但是不會有縣市與鄉鎮市區的資料
```
{
"factories": 53914,
"documents": 200,
"report_records": 0
}
```
`/api/statistics/factories?level=city`
回傳全台灣與縣市資料
```
{
"factories": 53914,
"documents": 200,
"report_records": 0,
"cities": {
"基隆市": {
"factories": 0,
"documents": 0,
"report_records": 0
},
"臺北市": {
"factories": 0,
"documents": 0,
"report_records": 0
},
...
}
```
`/api/statistics/factories?level=town`
回傳全台灣, 縣市與鄉鎮市區的資料
```
{
"factories": 53914,
"documents": 200,
"report_records": 0,
"cities": {
"基隆市": {
"factories": 0,
"documents": 0,
"report_records": 0,
"towns": {
"仁愛區": {
"factories": 0,
"documents": 0,
"report_records": 0
},
....
}
```
如果跟 townname 結合的話
`/api/statistics/factories?townname=臺南市&level=town`
```
{
"factories": 53914,
"documents": 200,
"report_records": 0,
"cities": {
"臺南市": {
"factories": 5732,
"documents": 100,
"report_records": 0,
"towns": {
"中西區": {
"factories": 0,
"documents": 0,
"report_records": 0
},
....
```
`/api/statistics/factories?townname=臺南市善化區`
```
{
"factories": 53914,
"documents": 200,
"report_records": 0,
"cities": {
"臺南市": {
"factories": 5732,
"documents": 100,
"report_records": 0,
"towns": {
"善化區": {
"factories": 238,
"documents": 0,
"report_records": 0
}
}
}
}
}
```
`/api/statistics/factories?townname=臺南市`
```
{
"factories": 53914,
"documents": 200,
"report_records": 0,
"cities": {
"臺南市": {
"factories": 5732,
"documents": 100,
"report_records": 0
}
}
}
```
:white_check_mark: All checks have passed