2024-11-03 16:46:37 +00:00
|
|
|
## setup
|
2024-11-02 17:34:53 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
cargo install sea-orm-cli
|
|
|
|
sea-orm-cli generate entity -o src/db/models # do this every time you edit the migrations, or first time on clone
|
|
|
|
cargo build
|
|
|
|
```
|
|
|
|
|
2024-11-03 16:46:37 +00:00
|
|
|
## api docs
|
2024-11-02 17:34:53 +00:00
|
|
|
|
2024-11-03 16:46:37 +00:00
|
|
|
u-token = user token
|
|
|
|
p-token = pc token
|
|
|
|
a-token = u-token or p-token
|
|
|
|
pid = cc:t pc id
|
2024-11-02 17:34:53 +00:00
|
|
|
|
2024-11-03 16:46:37 +00:00
|
|
|
| method | path | Description |
|
|
|
|
|--------|-----------------------------------|-------------------------------------------------------------------------|
|
|
|
|
| GET | /ws | nothing required on first req, see ws docs for more info |
|
|
|
|
| POST | /api/user/login | no token (duh), json body with email, pwd, returns json with token |
|
|
|
|
| POST | /api/user/add | u-token in header, json body with full user info |
|
|
|
|
| POST | /api/user/:id/edit | u-token in header, json body with data to replace with |
|
|
|
|
| POST | /api/user/:id/remove | u-token in header, no body required |
|
|
|
|
| GET | /api/user/:id/info | u-token in header, get back json |
|
|
|
|
| GET | /api/cct/ | a-token in header, gets a list of all groups |
|
|
|
|
| GET | /api/cct/:group/ | a-token in header, gets a list of all pid's |
|
|
|
|
| GET | /api/cct/:group/:pid/ | a-token in header, gets a list of all values for that pc |
|
|
|
|
| GET | /api/cct/:group/:pid/:val | a-token in header, gets a value from a pc in a group |
|
|
|
|
| POST | /api/cct/group/add | a-token in header, adds a group |
|
|
|
|
| POST | /api/cct/:group/edit | a-token in header, edits a group |
|
|
|
|
| POST | /api/cct/:group/pc/add | a-token in header, adds a pc to a group |
|
|
|
|
| POST | /api/cct/:group/:pid/edit | a-token in header, edits a pc in a group |
|
|
|
|
| POST | /api/cct/:group/:pid/val/add | a-token in header, adds a value to a pc in a group |
|
|
|
|
| POST | /api/cct/:group/:pid/:val/edit | a-token in header, edits value info in a pc in a group |
|
|
|
|
| POST | /api/cct/:group/:pid/:val/set | a-token in header, sets a value in a pc in a group |
|
2024-11-02 17:34:53 +00:00
|
|
|
|
2024-11-03 16:46:37 +00:00
|
|
|
### returned json examples
|
2024-11-02 17:34:53 +00:00
|
|
|
|
2024-11-03 16:46:37 +00:00
|
|
|
- POST /api/user/login
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"email": "mcorange@mcorangehq.xyz",
|
2024-11-03 16:52:17 +00:00
|
|
|
"password": "password123"
|
2024-11-03 16:46:37 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
returns:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"token": "677c4ae4-5c8f-41a7-9ee1-880e3a4305b7",
|
|
|
|
"valid_until": "1730652061630495114", // TODO: not yet implemented
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- GET /api/user/:id/info
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"id": "3536719e-f0cf-44ce-b4d2-3400bba0c220",
|
|
|
|
"username": "MCorange",
|
|
|
|
"email": "mcorange@mcorangehq.xyz",
|
|
|
|
"is_administrator": true,
|
|
|
|
"created_at": "1730651496386373948", // nanoseconds
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- GET /api/cct/
|
|
|
|
|
|
|
|
```json
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"id": "3536719e-f0cf-44ce-b4d2-3400bba0c220",
|
|
|
|
"name": "Keypad",
|
|
|
|
"available_actions": "{\"restart\":{\"lua_command\": \"os.restart()\"}}"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
- GET /api/cct/:group/
|
|
|
|
|
|
|
|
```json
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"id": "ea6608dd-5c03-4af8-93e7-3eddd15decbe",
|
|
|
|
"name": "Autocrafter Access Door",
|
|
|
|
"group": "3536719e-f0cf-44ce-b4d2-3400bba0c220",
|
|
|
|
"type": "Keypad",
|
|
|
|
"access_token": "f2ae4755-7a19-4a4e-9f24-b4bfd5a6f588",
|
|
|
|
"created_at": "1730652061630495114"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
- GET /api/cct/:group/:pid/
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"id": "ea6608dd-5c03-4af8-93e7-3eddd15decbe",
|
|
|
|
"name": "Autocrafter Access Door",
|
|
|
|
"group": "3536719e-f0cf-44ce-b4d2-3400bba0c220",
|
|
|
|
"type": "Keypad",
|
|
|
|
"access_token": "f2ae4755-7a19-4a4e-9f24-b4bfd5a6f588",
|
|
|
|
"created_at": "1730652061630495114",
|
|
|
|
"values": {
|
|
|
|
"times_opened": "34543"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
```
|
|
|
|
|
|
|
|
- GET /api/cct/:group/:pid/:val
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"times_opened": "23432"
|
|
|
|
}
|
|
|
|
```
|
2024-11-02 17:34:53 +00:00
|
|
|
|
|
|
|
|
2024-11-03 16:46:37 +00:00
|
|
|
## ws
|
2024-11-02 17:34:53 +00:00
|
|
|
|
|
|
|
`ws_msg_t`:
|
|
|
|
0: heartbeat ping
|
|
|
|
1: server to client
|
|
|
|
2: client to server
|
|
|
|
`msg_t`:
|
|
|
|
TODO!
|
|
|
|
|
|
|
|
```json
|
|
|
|
{ // low level message
|
2024-11-03 16:46:37 +00:00
|
|
|
"ws_msg_t": 2, // `ws_msg_t`
|
2024-11-02 17:34:53 +00:00
|
|
|
"ws_msg": { // high level message
|
2024-11-03 16:46:37 +00:00
|
|
|
"auth": "3536719e-f0cf-44ce-b4d2-3400bba0c220", // Auth token
|
2024-11-02 17:34:53 +00:00
|
|
|
"msg": { // Data field
|
2024-11-03 16:46:37 +00:00
|
|
|
"Keypad": {
|
2024-11-02 17:34:53 +00:00
|
|
|
"DoorOpenEv": { // "DataType": "Value, can be a struct or anything"
|
2024-11-03 16:46:37 +00:00
|
|
|
"user": "3536719e-f0cf-44ce-b4d2-3400bba0c220",
|
2024-11-02 17:34:53 +00:00
|
|
|
"timestamp": 123456,
|
2024-11-03 16:46:37 +00:00
|
|
|
"door_id": "478fb503-dd05-4a1a-9292-8a5822dfed9d"
|
2024-11-02 17:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|