Sfoglia il codice sorgente

some more docs updates

Alexander Belanger 5 anni fa
parent
commit
003b49ce3a
3 ha cambiato i file con 129 aggiunte e 32 eliminazioni
  1. 126 29
      docs/API.md
  2. 1 1
      server/api/errors.go
  3. 2 2
      server/api/user_handler_test.go

+ 126 - 29
docs/API.md

@@ -94,33 +94,13 @@ User{
 
 **Errors:**
 
-- Invalid email (example: `{"email": "notanemail"}`)
-  - Status Code: `422`
+- Invalid `id` URL parameter
+  - Status Code: `400`
   - Request Body:
     ```json
     {
-        "code":601,
-        "errors":["email validation failed"]
-    }
-    ```
-
-- Missing field
-  - Status Code: `422`
-  - Request Body:
-    ```json
-    {
-        "code":601,
-        "errors":["required validation failed"]
-    }`
-    ```
-
-- Email already taken 
-  - Status Code: `422`
-  - Request Body:
-    ```json
-    {
-        "code":601,
-        "errors":["email already taken"]
+        "code":600,
+        "errors":["could not process request"]
     }
     ```
 
@@ -149,7 +129,17 @@ User{
 }
 ```
 
-**Errors:** TBD
+**Errors:** 
+
+- Invalid `id` URL parameter
+  - Status Code: `400`
+  - Request Body:
+    ```json
+    {
+        "code":600,
+        "errors":["could not process request"]
+    }
+    ```
 
 #### `GET /api/users/{id}/clusters/all`
 
@@ -163,7 +153,7 @@ User{
 
 **Request Body**: N/A
 
-**Response Body**: 
+**Successful Response Body**: 
 
 ```js
 {
@@ -176,13 +166,120 @@ User{
 }
 ```
 
-**Errors:** TBD
+**Errors:** 
+
+- Invalid `id` URL parameter
+  - Status Code: `400`
+  - Request Body:
+    ```json
+    {
+        "code":600,
+        "errors":["could not process request"]
+    }
+    ```
 
-#### `POST /api/users/{id}`
+#### `POST /api/users`
+
+**Description:** Creates a new user with a given email and password.
+
+**URL parameters:** 
+
+- `id` The user's ID. 
+
+**Query parameters:** N/A
 
-#### `POST /api/users/{id}/clusters`
+**Request Body**: 
+
+```js
+{
+    "email": String,
+    "password": String,
+}
+```
+
+**Successful Response Body**: N/A
+
+**Errors:**
+
+- Invalid email (example: `{"email": "notanemail"}`)
+  - Status Code: `422`
+  - Request Body:
+    ```json
+    {
+        "code":601,
+        "errors":["email validation failed"]
+    }
+    ```
+
+- Missing field
+  - Status Code: `422`
+  - Request Body:
+    ```json
+    {
+        "code":601,
+        "errors":["required validation failed"]
+    }`
+    ```
+
+- Email already taken 
+  - Status Code: `422`
+  - Request Body:
+    ```json
+    {
+        "code":601,
+        "errors":["email already taken"]
+    }
+    ```
 
 #### `PUT /api/users/{id}`
 
+**Description:** Updates an existing user
+
+**URL parameters:** 
+
+- `id` The user's ID. 
+
+**Query parameters:** N/A
+
+**Request body:**
+
+**Successful Response Body**: N/A
+
+**Errors:** 
+
+- Invalid `id` URL parameter
+  - Status Code: `400`
+  - Request Body:
+    ```json
+    {
+        "code":600,
+        "errors":["could not process request"]
+    }
+    ```
+
 #### `DELETE /api/users/{id}`
 
+**Description:** Deletes an existing user
+
+**URL parameters:** 
+
+- `id` The user's ID. 
+
+**Query parameters:** N/A
+
+**Request body:**
+
+**Successful Response Body**: N/A
+
+**Errors:** 
+
+- Invalid `id` URL parameter
+  - Status Code: `400`
+  - Request Body:
+    ```json
+    {
+        "code":600,
+        "errors":["could not process request"]
+    }
+    ```
+

+ 1 - 1
server/api/errors.go

@@ -76,7 +76,7 @@ func (app *App) sendExternalError(
 func (app *App) handleErrorFormDecoding(err error, code ErrorCode, w http.ResponseWriter) {
 	errExt := HTTPError{
 		Code:   code,
-		Errors: []string{"Could not process JSON body"},
+		Errors: []string{"Could not process request"},
 	}
 
 	app.sendExternalError(err, http.StatusBadRequest, errExt, w)

+ 2 - 2
server/api/user_handler_test.go

@@ -185,7 +185,7 @@ var readUserTests = []userTest{
 		endpoint:  "/api/users/aldkfjas",
 		body:      "",
 		expStatus: http.StatusBadRequest,
-		expBody:   `{"code":600,"errors":["Could not process JSON body"]}`,
+		expBody:   `{"code":600,"errors":["Could not process request"]}`,
 		canQuery:  true,
 	},
 	userTest{
@@ -200,7 +200,7 @@ var readUserTests = []userTest{
 		endpoint:  "/api/users/2",
 		body:      "",
 		expStatus: http.StatusNotFound,
-		expBody:   `{"code":603,"errors":["Could not find requested object"]}`,
+		expBody:   `{"code":602,"errors":["Could not find requested object"]}`,
 		canQuery:  true,
 	},
 }