Extend database with more tables, rewrite API doc, improve API endpoints

This commit is contained in:
2024-09-23 21:22:45 +02:00
parent 6aae064902
commit 87f3516b54
41 changed files with 1345 additions and 1126 deletions

821
README.md
View File

@@ -48,678 +48,241 @@ TODO
The application host it's data in a SQLite database. The access is managed by an [ExpressJs](https://expressjs.com/) server which offers many REST-API endpoints for the frontend. The REST-API server runs on port 3000.
#### `/api`
---
<details style="border: solid; border-radius: 10px; border-color: #70AFFD; margin-bottom: 20px">
<summary style="background-color: #70AFFD; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Server check</summary>
<div style="padding: 0px 20px 10px">
#### Validate
<h4>Description</h4>
Check if server is available
<details>
<summary><code style="background-color:#69CA92"><b>POST</b></code> <code><b>/accounts/login</b></code> <code> (Login for user)</code></summary>
<h4>Request</h4>
<code>GET /api</code>
##### Parameters
> | name | type | data type | description |
> | --- | --- | --- | --- |
> | username | required | string | Username of the account |
> | password | required | string | Password of the account |
<br>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | `AccountObject` + `Addresses`, `Payments`, `AccountRole` |
> | `400` | `application/json` | `{code: 400, message: "Bad Request"}` |
> | `401` | `application/json` | `{code: 401, message: "Unauthorized"}` |
</details>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
</div>
---
#### Listing existing
<details>
<summary><code style="background-color:#70AFFD"><b>GET</b></code> <code><b>/products/</b></code> <code> (Get all products)</code>
</summary>
##### Parameters
> None
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | `Array<ProductModel>` + `Category`, `Brand` |
</details>
<details>
<summary><code style="background-color:#70AFFD"><b>GET</b></code> <code><b>/products/:id</b></code> <code> (Get a product by it's id)</code>
</summary>
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | `id` | required | string | ID of product in the database |
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | `ProductModel` + `Category`, `Brand` |
</details>
<details>
<summary><code style="background-color:#70AFFD"><b>GET</b></code> <code><b>/orders/:id</b></code> <code> (Get all orders of an user)</code>
</summary>
##### Parameters
> | name | type | data type | description |
> | --- | --- | --- | --- |
> | `id` | required | string | ID of userAccount in the database |
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | `ProductModel` + `Order`, `OrderItem`, `Product` |
</details>
<details>
<summary><code style="background-color:#70AFFD"><b>GET</b></code> <code><b>/categories/</b></code> <code> (Get all Categories)</code>
</summary>
##### Parameters
> None
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | `Array<Categories>` |
</details>
---
#### Creating new
<details>
<summary><code style="background-color:#69CA92"><b>POST</b></code> <code><b>/accounts/</b></code> <code> (Create a new account)</code>
</summary>
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | None | required | object (JSON) | Model of an Account |
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `201` | `application/json` | `AccountModel` |
> | `400` | `application/json` | `{code: 400, message: "Username too short!"}` |
> | `400` | `application/json` | `{code: 400, message: "Password too short!"}` |
> | `409` | `application/json` | `{code: 409, message: "Username already in use"}` |
</details>
<details style="border: solid; border-radius: 10px; border-color: #70AFFD; margin-bottom: 20px">
<summary style="background-color: #70AFFD; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Database reset</summary>
<div style="padding: 0px 20px 10px">
<details>
<summary><code style="background-color:#69CA92"><b>POST</b></code> <code><b>/products/</b></code> <code> (Create a new product)</code>
</summary>
<h4>Description</h4>
Delete and refill the database with example values
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | None | required | object (JSON) | Model of a Product |
<h4>Request</h4>
<code>GET /api/resetdatabase</code>
<br>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
</div>
</details>
#### `/categories`
<details style="border: solid; border-radius: 10px; border-color: #70AFFD; margin-bottom: 20px">
<summary style="background-color: #70AFFD; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">All categories</summary>
<div style="padding: 0px 20px 10px">
<h4>Description</h4>
Get all categories
<h4>Request</h4>
<code>GET /categories</code>
<br>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
<h4>Example Response</h4>
```json
[
{
"id": 0,
"name": "Electronic",
"icon": "mdi-chip",
"createdAt": "2024-09-13T07:51:40.118Z",
"updatedAt": "2024-09-13T07:51:40.118Z"
},
{
"id": 1,
"name": "Sports",
"icon": "mdi-soccer",
"createdAt": "2024-09-13T07:51:40.118Z",
"updatedAt": "2024-09-13T07:51:40.118Z"
}
]
```
</div>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `201` | `application/json` | `ProductModel` |
> | `400` | `application/json` | `{code: 400, message: "..."}` |
</details>
<details style="border: solid; border-radius: 10px; border-color: #69CA92; margin-bottom: 20px">
<summary style="background-color: #69CA92; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Add new category</summary>
<div style="padding: 0px 20px 10px">
<details>
<summary><code style="background-color:#69CA92"><b>POST</b></code> <code><b>/orders/</b></code> <code> (Create a new order)</code>
</summary>
<h4>Description</h4>
Add a new category
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | None | required | object (JSON) | Model of an Order |
<h4>Request</h4>
<code>POST /categories</code>
<br>
<table>
<header>
<th>Body Parameters</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>name</code></td>
<td>Yes</td>
<td>Name of the category</td>
</tr>
<tr>
<td><code>icon</code></td>
<td>Yes</td>
<td>Material Design Icon</td>
</tr>
</tbody>
</table>
</div>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `201` | `application/json` | `OrderModel` |
</details>
<details style="border: solid; border-radius: 10px; border-color: #EB5246; margin-bottom: 20px">
<summary style="background-color: #EB5246; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Delete category</summary>
<div style="padding: 0px 20px 10px">
<details>
<summary><code style="background-color:#69CA92"><b>POST</b></code> <code><b>/categories/</b></code> <code> (Create a new category)</code>
</summary>
<h4>Description</h4>
Delete a category by it's id
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | None | required | object (JSON) | Model of a Category |
<h4>Request</h4>
<code>DELETE /categories/:id</code>
<br>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>id</code></td>
<td>Yes</td>
<td>Database ID of CategoryModel</td>
</tr>
</tbody>
</table>
</div>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `201` | `application/json` | `OrderModel` |
> | `400` | `application/json` | `{code: 400, message: "..."}` |
</details>
#### `/products`
---
<details style="border: solid; border-radius: 10px; border-color: #70AFFD; margin-bottom: 20px">
<summary style="background-color: #70AFFD; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">All products</summary>
<div style="padding: 0px 20px 10px">
#### Updating existing
<h4>Description</h4>
Get all products
<details>
<summary><code style="background-color:#F3A63D"><b>PATCH</b></code> <code><b>/accounts/</b></code> <code> (Update data of an existing account)</code>
</summary>
<h4>Request</h4>
<code>GET /products</code>
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | None | required | object (JSON) | Model of an Account |
<br>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
<h4>Example Response</h4>
```json
[
{
"id": 0,
"brand": "Lenovo",
"name": "Thinkpad T14",
"categoryId": 0,
"price": 799.99,
"discount": 10,
"rating": 4.6,
"imageUrl": "thinkpad-t14s.jpg",
"description": "Die stabile Arbeitsmaschine. Mit AMD Ryzen 7 89029U, 128 GB RAM und 8 TB M.2 SSD!",
"createdAt": "2024-09-13T07:51:40.119Z",
"updatedAt": "2024-09-13T07:51:40.119Z",
"category": {
"id": 0,
"name": "Electronic",
"icon": "mdi-chip",
"createdAt": "2024-09-13T07:51:40.118Z",
"updatedAt": "2024-09-13T07:51:40.118Z"
}
}
]
```
</div>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | AccountModel |
> | `400` | `application/json` | `{code: 400, message: "..."}` |
</details>
---
<details style="border: solid; border-radius: 10px; border-color: #70AFFD; margin-bottom: 20px">
<summary style="background-color: #70AFFD; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Request one product</summary>
<div style="padding: 0px 20px 10px">
#### Delete existing
<h4>Description</h4>
Get a specific product by it's id
<details>
<summary><code style="background-color:#EB5246"><b>DELETE</b></code> <code><b>/product/:id</b></code> <code> (Delete a product)</code>
</summary>
<h4>Request</h4>
<code>GET /products/:id</code>
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | `id` | required | string | ID of product in the database |
<br>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>id</code></td>
<td>Yes</td>
<td>ID of the product in the database table</td>
</tr>
</tbody>
</table>
<h4>Example Response</h4>
```json
{
"id": 0,
"brand": "Lenovo",
"name": "Thinkpad T14",
"categoryId": 0,
"price": 799.99,
"discount": 10,
"rating": 4.6,
"imageUrl": "thinkpad-t14s.jpg",
"description": "Die stabile Arbeitsmaschine. Mit AMD Ryzen 7 89029U, 128 GB RAM und 8 TB M.2 SSD!",
"createdAt": "2024-09-13T07:51:40.119Z",
"updatedAt": "2024-09-13T07:51:40.119Z",
"category": {
"id": 0,
"name": "Electronic",
"icon": "mdi-chip",
"createdAt": "2024-09-13T07:51:40.118Z",
"updatedAt": "2024-09-13T07:51:40.118Z"
}
}
```
</div>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | `ProductModel` |
> | `400` | `application/json` | `{code: 400, message: "..."}` |
</details>
<details style="border: solid; border-radius: 10px; border-color: #69CA92; margin-bottom: 20px">
<summary style="background-color: #69CA92; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Add new product</summary>
<div style="padding: 0px 20px 10px">
<details>
<summary><code style="background-color:#EB5246"><b>DELETE</b></code> <code><b>/categories/:id</b></code> <code> (Delete a category)</code>
</summary>
<h4>Description</h4>
Add a new product to the database
##### Parameters
> | name | type | data type | description |
> | :---: | --- | --- | --- |
> | `id` | required | string | ID of category in the database |
<h4>Request</h4>
<code>POST /products</code>
<br>
<table>
<header>
<th>Body Parameters</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>brand</code></td>
<td>Yes</td>
<td>Brand of the product</td>
</tr>
<tr>
<td><code>name</code></td>
<td>Yes</td>
<td>Name of the product</td>
</tr>
<tr>
<td><code>description</code></td>
<td>No</td>
<td>Description of the product</td>
</tr>
<tr>
<td><code>categoryId</code></td>
<td>Yes</td>
<td>ID of a Category from database</td>
</tr>
<tr>
<td><code>price</code></td>
<td>No</td>
<td>Name of the product</td>
</tr>
<tr>
<td><code>discount</code></td>
<td>No</td>
<td>Procentual discount, 0 to 100</td>
</tr>
<tr>
<td><code>rating</code></td>
<td>No</td>
<td>Product rating from 1 to 5</td>
</tr>
<tr>
<td><code>imageUrl</code></td>
<td>No</td>
<td>Name of the uploaded image file</td>
</tr>
</tbody>
</table>
</div>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | `application/json` | `CategoryModel` |
> | `400` | `application/json` | `{code: 400, message: "..."}` |
</details>
---
<details style="border: solid; border-radius: 10px; border-color: #EB5246; margin-bottom: 20px">
<summary style="background-color: #EB5246; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Delete product</summary>
<div style="padding: 0px 20px 10px">
#### Miscs
<h4>Description</h4>
Delete a product by it's id
<details>
<summary><code style="background-color:#70AFFD"><b>GET</b></code> <code><b>/api/</b></code> <code> (Check if server runs)</code>
</summary>
<h4>Request</h4>
<code>DELETE /products/:id</code>
##### Parameters
> None
<br>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>id</code></td>
<td>Yes</td>
<td>Database ID of ProductModel</td>
</tr>
</tbody>
</table>
</div>
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | None | None |
</details>
<details>
<summary><code style="background-color:#70AFFD"><b>GET</b></code> <code><b>/resetDatabase/</b></code> <code> (Reset the database to it's default values)</code>
</summary>
#### `/orders`
<details style="border: solid; border-radius: 10px; border-color: #70AFFD; margin-bottom: 20px">
<summary style="background-color: #70AFFD; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Request orders of user</summary>
<div style="padding: 0px 20px 10px">
<h4>Description</h4>
Get all orders from a user
<h4>Request</h4>
<code>GET /orders/:id</code>
<br>
<table>
<header>
<th>Parameter</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>id</code></td>
<td>Yes</td>
<td>ID of the user in the database table</td>
</tr>
</tbody>
</table>
<h4>Example Response</h4>
```json
[
{
"id": 1,
"accountId": 3,
"totalPrice": 7.99,
"shippingProgress": 5,
"createdAt": "2024-09-09T12:24:24.225Z",
"updatedAt": "2024-09-13T07:51:40.120Z",
"orderItem": [
{
"id": 1,
"orderId": 1,
"quantity": 1,
"productId": 6,
"createdAt": "2024-09-13T07:51:40.120Z",
"updatedAt": "2024-09-13T07:51:40.120Z",
"product": {
"id": 6,
"brand": "Aldous Huxley",
"name": "Brave New World",
"categoryId": 3,
"price": 7.99,
"discount": 0,
"rating": 4.4,
"imageUrl": "brave-new-world.jpg",
"description": "Brave New World beschreibt eine genormte Gesellschaft, in der Föten genetisch manipuliert und Menschen konditioniert werden. Ziel des Staates ist Zufriedenheit und Stabilität, und dies wird durch Gleichheit, Drogen und Propaganda erreicht. Gott und Religion...",
"createdAt": "2024-09-13T07:51:40.119Z",
"updatedAt": "2024-09-13T07:51:40.119Z"
}
}
]
}
]
```
</div>
</details>
<details style="border: solid; border-radius: 10px; border-color: #69CA92; margin-bottom: 20px">
<summary style="background-color: #69CA92; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Place a new order</summary>
<div style="padding: 0px 20px 10px">
<h4>Description</h4>
Place a new order to the database
<h4>Request</h4>
<code>POST /orders</code>
<br>
<table>
<header>
<th>Query Parameters</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>accountId</code></td>
<td>Yes</td>
<td>ID of account who created this order</td>
</tr>
<tr>
<td><code>shippingProgress</code></td>
<td>No</td>
<td>Progress of shipping, 1 to 5</td>
</tr>
<tr>
<td><code>orderItem</code></td>
<td>Yes</td>
<td>List of ordered items (objects). Needs parameter <code>quantity</code> and <code>productId</code></td>
</tr>
</tbody>
</table>
</div>
</details>
#### `/accounts`
<details style="border: solid; border-radius: 10px; border-color: #70AFFD; margin-bottom: 20px">
<summary style="background-color: #70AFFD; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Login user</summary>
<div style="padding: 0px 20px 10px">
<h4>Description</h4>
Login process for user
<h4>Request</h4>
<code>GET /accounts</code>
<br>
<table>
<header>
<th>Query Parameters</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>username</code></td>
<td>Yes</td>
<td>Name of user account</td>
</tr>
<tr>
<td><code>password</code></td>
<td>Yes</td>
<td>Password of user account</td>
</tr>
</tbody>
</table>
<h4>Example Response</h4>
```json
{
"loginSuccessful": true,
"userId": 3,
"message": ""
}
```
</div>
</details>
<details style="border: solid; border-radius: 10px; border-color: #69CA92; margin-bottom: 20px">
<summary style="background-color: #69CA92; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Add an user</summary>
<div style="padding: 0px 20px 10px">
<h4>Description</h4>
Place a new account to the database
<h4>Request</h4>
<code>POST /accounts</code>
<br>
<table>
<header>
<th>Body Parameters</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>username</code></td>
<td>Yes</td>
<td>Login username</td>
</tr>
<tr>
<td><code>password</code></td>
<td>Yes</td>
<td>Login password</td>
</tr>
<tr>
<td><code>firstName</code></td>
<td>No</td>
<td>First name of user</td>
</tr>
<tr>
<td><code>lastName</code></td>
<td>No</td>
<td>Last name of user</td>
</tr>
<tr>
<td><code>street</code></td>
<td>No</td>
<td>Street where the user lives</td>
</tr>
<tr>
<td><code>houseNumber</code></td>
<td>No</td>
<td>House number of user</td>
</tr>
<tr>
<td><code>postalCode</code></td>
<td>No</td>
<td>Postal code of users home</td>
</tr>
<tr>
<td><code>city</code></td>
<td>No</td>
<td>Name of users city</td>
</tr>
</tbody>
</table>
</div>
</details>
<details style="border: solid; border-radius: 10px; border-color: #F3A63D; margin-bottom: 20px">
<summary style="background-color: #F3A63D; color: #FFFFFF; border: none; padding: 10px 20px; border-radius: 6px 6px 0px 0px; font-weight: bold">Update account</summary>
<div style="padding: 0px 20px 10px">
<h4>Description</h4>
Updating values of an existing account
<h4>Request</h4>
<code>PATCH /account</code>
<br>
<table>
<header>
<th>Body Parameters</th>
<th>Required?</th>
<th>Description</th>
</header>
<tbody>
<tr>
<td><code>id</code></td>
<td>Yes</td>
<td>Identifier of dataset</td>
</tr>
<tr>
<td><code>username</code></td>
<td>No</td>
<td>Login username</td>
</tr>
<tr>
<td><code>password</code></td>
<td>No</td>
<td>Login password</td>
</tr>
<tr>
<td><code>firstName</code></td>
<td>No</td>
<td>First name of user</td>
</tr>
<tr>
<td><code>lastName</code></td>
<td>No</td>
<td>Last name of user</td>
</tr>
<tr>
<td><code>street</code></td>
<td>No</td>
<td>Street where the user lives</td>
</tr>
<tr>
<td><code>houseNumber</code></td>
<td>No</td>
<td>House number of user</td>
</tr>
<tr>
<td><code>postalCode</code></td>
<td>No</td>
<td>Postal code of users home</td>
</tr>
<tr>
<td><code>city</code></td>
<td>No</td>
<td>Name of users city</td>
</tr>
</tbody>
</table>
</div>
</details>
##### Parameters
> None
##### Responses
> | http code | content-type | response |
> | :---: | --- | --- |
> | `200` | None | None |
</details>