From 5856e80fcb78446be37456ec1e5c47b2ab02201f Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 9 Apr 2021 17:10:50 +0200 Subject: dprint format :tada: --- api/api.ts | 38 +++++++++++++++++++------------------- api/readme.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 66 insertions(+), 30 deletions(-) (limited to 'api') diff --git a/api/api.ts b/api/api.ts index 320df92..95c63ba 100644 --- a/api/api.ts +++ b/api/api.ts @@ -1,14 +1,14 @@ export interface userInfo { - avatar: string|null, - status: string|null, - coutry: string|null, - id: string, - registered: number, - username: string, - friends: number, - relation?: "none"|"friends"|"incoming"|"outgoing"|"blocked", - rating: number, -}; + avatar: string | null; + status: string | null; + coutry: string | null; + id: string; + registered: number; + username: string; + friends: number; + relation?: 'none' | 'friends' | 'incoming' | 'outgoing' | 'blocked'; + rating: number; +} export type ruleset = { timelimit: { @@ -17,15 +17,15 @@ export type ruleset = { seconds: number; addmove: number; shared: boolean; - }, + }; ranked: boolean; -} +}; export type userColors = { diskA: string; diskB: string; background: string; -} +}; export interface userPreferences { darkMode?: boolean; @@ -34,13 +34,13 @@ export interface userPreferences { } export interface userGameTotals { - draw: number; - games: number; - lose: number; - win: number; + draw: number; + games: number; + lose: number; + win: number; } -export type outcome = "w" | "l" | "d"; +export type outcome = 'w' | 'l' | 'd'; export interface userGames { totals: userGameTotals; @@ -60,5 +60,5 @@ export interface gameInfo { rating_opponent?: number; ruleset: ruleset; started: number; - status: "finished"|"in_progress"|"resign"|"wait_for_opponent"; + status: 'finished' | 'in_progress' | 'resign' | 'wait_for_opponent'; } diff --git a/api/readme.md b/api/readme.md index ab4e1e6..70d9221 100644 --- a/api/readme.md +++ b/api/readme.md @@ -1,6 +1,8 @@ # API -This is the subdirectory for the API. You can find the API reference in [this](https://docs.google.com/spreadsheets/d/1mDN9IUqRIMjr_9RmLxKybjIgVuaUadalmPEFnG-XeJg/edit?usp=sharing) Google Docs document. +This is the subdirectory for the API. You can find the API reference in +[this](https://docs.google.com/spreadsheets/d/1mDN9IUqRIMjr_9RmLxKybjIgVuaUadalmPEFnG-XeJg/edit?usp=sharing) +Google Docs document. ## Endpoint reference (WIP) @@ -33,6 +35,7 @@ API return type classes are mostly defined in api/api.ts games: int } ``` + @@ -48,6 +51,7 @@ API return type classes are mostly defined in api/api.ts password: string } ``` + none empty response with the set_cookie header @@ -66,6 +70,7 @@ API return type classes are mostly defined in api/api.ts password: string } ``` + none empty response with the set_cookie header @@ -83,13 +88,15 @@ API return type classes are mostly defined in api/api.ts id?: userID } ``` + none|user ```ts -userInfo +userInfo; ``` + @@ -102,6 +109,7 @@ userInfo ```ts { id?: userID } ``` + none|user @@ -112,6 +120,7 @@ userInfo totals: userGameTotals } ``` + @@ -124,6 +133,7 @@ userInfo ```ts { id?: userID } ``` + none|user PNG image @@ -137,12 +147,17 @@ update avatar note: avatar is a client-resized 256x256 .png base64-encoded image, request returns error when image is not .png or larger than 256x256 + ```ts -{ image: base64PNG } +{ + image: + base64PNG; +} ``` + user none @@ -157,8 +172,12 @@ returns error when image is not .png or larger than 256x256 ```ts -{ preferences: userPreferences } +{ + preferences: + userPreferences; +} ``` + @@ -169,8 +188,12 @@ returns error when image is not .png or larger than 256x256 ```ts -{ newPreferences: userPreferences } +{ + newPreferences: + userPreferences; +} ``` + user none @@ -188,6 +211,7 @@ returns error when image is not .png or larger than 256x256 newPassword: string, } ``` + user none @@ -205,6 +229,7 @@ returns error when image is not .png or larger than 256x256 email: string, } ``` + user none @@ -222,6 +247,7 @@ returns error when image is not .png or larger than 256x256 username: string, } ``` + user none @@ -234,8 +260,12 @@ returns error when image is not .png or larger than 256x256 ```ts -{ status: string } +{ + status: + string; +} ``` + user none @@ -459,6 +489,7 @@ These are events that are fired by the socket.io connection ## How to test API endpoints + ```sh # If you're running the standalone flask server: curl http://localhost:5000/ @@ -471,10 +502,16 @@ curl http://localhost:2080/api/ Please follow these rules when creating new API endpoints: -1. Endpoints should always return a valid JSON object and an appropriate [http code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) -2. Endpoints that are in a namespace should get their own directory in this folder, eg. http://localhost:5000/status is defined in api/status.py, http://localhost:5000/auth/signup is defined in api/auth/signup.py etc. -3. Endpoints that take data should verify that the data is present and valid, and return an empty JSON object with http code 400 (bad request) if the data isn't valid. -4. Endpoints that require database access should get the cursor/connection object from api/db.py +1. Endpoints should always return a valid JSON object and an appropriate + [http code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) +2. Endpoints that are in a namespace should get their own directory in this + folder, eg. http://localhost:5000/status is defined in api/status.py, + http://localhost:5000/auth/signup is defined in api/auth/signup.py etc. +3. Endpoints that take data should verify that the data is present and valid, + and return an empty JSON object with http code 400 (bad request) if the data + isn't valid. +4. Endpoints that require database access should get the cursor/connection + object from api/db.py ## Example endpoint @@ -503,4 +540,3 @@ dynamic_route = ["/tests", status] # | # namespace (defined in dynamic_route variable) ``` - -- cgit v1.2.3