Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改 /api/factories 的回傳格式,一次回傳 factories, documents 與 report_records 減少前端需要的 query 次數 #491

Merged
merged 1 commit into from Feb 4, 2021

Conversation

Swind
Copy link
Contributor

@Swind Swind commented Feb 3, 2021

image

/api/statistics/factories

參數有

  • townname
  • source
  • display_status
  • level

前三個是之前就有的就不多解釋,最主要就是多了一個 level
level 可以接受的值是 citytown
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
    }
  }
}

@Swind Swind requested a review from stegben February 3, 2021 09:14
Copy link
Contributor

@stegben stegben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@stegben stegben merged commit d63e93f into master Feb 4, 2021
@stegben stegben deleted the statistics_api_v2 branch February 4, 2021 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants