# Sportguru Admin API [toc] ## 文件更新紀錄 | date | name | desc | |:----------:|:----- |:------| | 2021-10-01 | Vicky |建立文件框架| | 2021-10-01 | Vicky |新增API: 登入/更新token/廣告&廣告區域APIs| | 2021-10-06 | Vicky |新增API: 查看 指定區域隨機廣告| | 2021-10-12 | Vicky |更新API: 查看 區域廣告新增param 'is_open'| 查看 指定區域隨機廣告 ## 測試帳號 | id | username | password | |:---:|:------- |:--------:| | 1 |fillygaming | 11111111 | ## 定義 - PlatformType ```python= ANDROID = 1 IOS = 2 ``` ## HOST - 測試機: + API :http://sportguru-admin-api.votefair365.net + 網頁 :http://sportguru-admin.votefair365.net ## 授權 ### 登入 `POST /sign-in` + payload ```json { "username": "fillygaming", "password": "11111111" } ``` + response ```json { "data": { "id": 1, "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJmaWxseWdhbWluZyIsInJvbGUiOjEsImV4cCI6MTYzMzY3NDE5M30.Fg0WOk5bt_YMGorse29Q1bZ2DeYuCltF3rVekv3UodQ", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJmaWxseWdhbWluZyIsInJvbGUiOjEsImV4cCI6MTYzMzE1NTc5M30.7FiNafdRQ1V1MimT18bUlQznikMJGiRTOGDZGRVYEhQ", "username": "fillygaming" }, "pager": null } ``` ### 更新token `POST /refresh-token` + payload ```json { "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJmaWxseWdhbWluZyIsInJvbGUiOjEsImV4cCI6MTYzMzY3NDE5M30.Fg0WOk5bt_YMGorse29Q1bZ2DeYuCltF3rVekv3UodQ" } ``` + response ```json { "data": { "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJmaWxseWdhbWluZyIsInJvbGUiOjEsImV4cCI6MTYzMzE2Mzg4MH0.M0EC0oXRp3OuneCq1gyvxWof3pE0EpjvBE_DMjiSGEE" }, "pager": null } ``` ## 廣告 ### 查看 `GET /ad` | args | def. | required | |:-----------:|:----------:|:--------:| | id | | | | area_id | | | | page | default=1 | | | per_page | default=10 | | + response ```json { "data": [ { "area_id": 1, "click_times": 0, "content": "image_base64_text", "create_datetime": "2021-10-01 14:28:59", "id": 2, "is_open": true, "name": "廣告2", "platform_type": 1, "update_datetime": "2021-10-01 14:28:59", "url": "http://23456" }, ... ... ], "pager": { "page": 1, "pages": 1, "per_page": 10, "total": 3 } } ``` ### 新增 `POST /ad` | args | def. | required | |:-----------:|:----------:|:--------:| | area_id | int * 由GET/ad_area取得 | V | | name | str | V | | url | str | V | | content | str (image base64 text) | V | | is_open | bool | V | | platform_type | *參照定義 | V | + payload ```json { "area_id": 2, "name": "廣告3", "url": "http://34567", "content": "image_base64_text", "is_open": true, "platform_type": 2 } ``` + response ```json { "data": { "area_id": 2, "click_times": 0, "content": "image_base64_text", "create_datetime": "2021-10-01 16:49:16", "id": 5, "is_open": true, "name": "廣告3", "platform_type": 2, "update_datetime": "2021-10-01 16:49:16", "url": "http://34567" }, "pager": null } ``` ### 修改 `PUT /ad/<int:ad_id>` | args | def. | required | |:-----------:|:----------:|:--------:| | area_id | int * 由GET/ad_area取得 | | | name | str | | | url | str | | | content | str (image base64 text) | | | is_open | bool | | | platform_type | *參照定義 | | + payload ```json { "content": "image_base64_text" } ``` + response ```json { "data": { "area_id": 1, "click_times": 0, "content": "image_base64_text", "create_datetime": "2021-10-01 14:28:59", "id": 2, "is_open": true, "name": "廣告2", "platform_type": 1, "update_datetime": "2021-10-01 14:28:59", "url": "http://23456" }, "pager": null } ``` ### 刪除 `DELETE /ad/<int:ad_id>` + response ```json { "succeed": true } ``` ## 廣告區域 ### 查看 `GET /ad_area` | args | def. | required | |:-----------:|:----------:|:--------:| | id | | | | is_open | 是否開放(int: 1=是, 0=否) | | | page | default=1 | | | per_page | default=10 | | + response ```json { "data": [ { "content": "image_base64_text", "create_datetime": "2021-10-01 14:26:17", "height": 375, "id": 1, "is_open": true, "name": "area1", "remark": "測試修改", "update_datetime": "2021-10-01 14:26:17", "width": 90 }, ... ... ], "pager": { "page": 1, "pages": 1, "per_page": 10, "total": 3 } } ``` ### 修改 `PUT /ad_area/<int:area_id>` | args | def. | required | |:-----------:|:----------:|:--------:| | name | str | | | height | int | | | width | int | | | reamrk | str | | | content | str (image base64 text) | | | is_open | bool | | + payload ```json { "remark": "測試修改" } ``` + response ```json { "data": { "content": "image_base64_text", "create_datetime": "2021-10-01 14:26:17", "height": 375, "id": 1, "is_open": true, "name": "area1", "remark": "測試修改", "update_datetime": "2021-10-01 14:26:17", "width": 90 }, "pager": null } ```