Schema & API === # Database Schema ## User – 存放 Firestore - id (string): 使用者身分證字號 - password (string): 密碼 - username (string): 名稱 - id_photo (string): 身分證照片 - avatar (string): 身分證裁切後的頭像照片 - infected (JSON): 感染疾病種類 (from 政府、醫院資料) ``` [ { diseaseId (int): 疾病 id date (string): 患病日期 # ISO format recover (boolean): 是否已康復 }, ] ``` - departures (JSON) (from 政府) ``` [ { date (string): 出境日期 # ISO format to (string): 目的地 # regionId }, ] ``` - arrivals (JSON) (from 政府) ``` [ { date (string): 入境日期 # ISO format from (string): 來源地 # regionId }, ] ``` - quarantine (boolean) ``` [ { start (string): 隔離開始日期 # ISO format end (string): 隔離結束日期 # ISO format }, ] ``` - footprints (JSON): ``` [ { longitude (float): 經度 latitude (float): 緯度 location (string): 地名 address (string): 地址 time (string): 日期時間 }, ] ``` ## Admin - id (string): 管理者名稱 - password (string): 密碼 ## Diseases - id (int): 疾病 id (識別用) - name (string): 疾病名稱 ## Regions - id (int): 地區 id (識別用) - name (string): 地區名稱 - code (string): 國際使用之三碼地區代碼 ## Rules - light (string): 燈號 - diseaseIds ( [int] ): 屬於該燈號之疾病 id - regionIds ( [int] ): 屬於該燈號之地區 id - quarantine (int): 屬於該燈號之隔離天數(以內) # API #### _所有 API 都需要帶 x-api-key_ ## 前端 GET ### 取得 configuration GET /configuration - [x] 完成 #### Body ```None``` #### Returns ``` { diseases: [ { id: int, name: string } ], regions: [ { id: int, name: string, code: string } ], rules: { red: { diseases: { [id]: int }, regions: { [id]: int }, quarantine: int }, yellow: { ... } } } ``` ## User 操作 ### 註冊 POST /register - [x] 完成 #### Body ``` { id: string, # 身分證字號 password: string, # 密碼 username: string, # 使用者名稱 id_photo: binary, # 身分證照片 avatar: binary # 頭貼照片 } ``` #### Returns ``` { user: { ... }, token: string # jwt } ``` ### 登入 POST /login - [x] 完成 #### Body ``` { id: string, # 身分證字號 password: string # 密碼 } ``` #### Returns ``` { user: { ... }, token: string # jwt } ``` ### 取得使用者資料 GET /user - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ```None``` #### Returns ``` { user: { ... } } ``` ### 打卡 POST /user/footprints - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ``` { longitude: float, # 經度 latitude: float, # 緯度 location: string, # 地名 address: string } ``` #### Returns ``` { footprints: [ { longitude: float, latitude: float, location: string, address: string, time: string } ] } ``` ### 取得足跡 GET /user/footprints - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ```None``` #### Returns ``` { footprints: [ { longitude: float, latitude: float, location: string, time: string } ] } ``` ## Admin 操作 ### 登入 POST /admin/login - [x] 完成 #### Body ``` { id: string, # 管理者帳號 password: string # 密碼 } ``` #### Returns ``` { token: string # jwt } ``` ### 新增 admin 帳號 POST /admin - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ``` { newAdminId: string, # 新建帳號 id newAdminPassword: string # 新建帳號密碼 } ``` #### Returns ``` { message: '成功新增管理者帳號' } ``` ### 取得現在燈號規則 GET /rules - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ```None``` #### Returns ``` { rules: { red: { diseaseIds: [int], # 歸類為紅燈的疾病 id regionIds: [int], # 歸類為紅燈的地區 id quarantine: int # 歸類為紅燈的隔離天數(幾天以內) }, yellow: { ... } } } ``` ### 修改燈號規則 POST /rules - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ``` { rules: { red: { # 不是只含要新增的 rule,是整個新的 rule diseases: { # 歸類為紅燈的疾病 [id]: int, # key 是疾病 id (string),value 是該疾病的限制天數 } , regions: { # 歸類為紅燈的地區 id [id]: int, # key 是地區 id (string),value 是該地區的限制天數 }, quarantine: int # 歸類為紅燈的隔離天數(幾天以內) }, yellow: { ... } } } ``` #### Returns ``` { rules: { red: { diseases: { [id]: int, } , regions: { [id]: int, }, quarantine: int }, yellow: { ... } } } ``` ### 新增疾病 POST /disease - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ``` { name: string # 疾病名稱 } ``` #### Returns ``` { diseases: [...] # 疾病列表 } ``` ### 修改疾病 PATCH /disease - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ``` { id: int # 疾病 id name: string # 新名稱 } ``` #### Returns ``` { diseases: [...] # 疾病列表 } ``` ### 新增地區 POST /region - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ``` { name: string, # 地區名稱 code: string # 地區代碼 } ``` #### Returns ``` { regions: [...] # 地區列表 } ``` ### 修改地區 PATCH /region - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ``` { id: int # 地區 id name: string, # 新名稱 code: string # 新代碼 } ``` #### Returns ``` { regions: [...] # 疾病列表 } ``` ### 搜尋使用者資料 GET /user/:id - [x] 完成 #### Header `Authrorization: Bearer <token>` #### Body ```None``` #### Returns ``` { user: { ... } } ``` ### FORMAT ``` { red: { diseases: { [diseaseId]: boolean } } yellow: {} } ``