## setup ```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 ``` ## api docs u-token = user token p-token = pc token a-token = u-token or p-token pid = cc:t pc id | 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 | ### returned json examples - POST /api/user/login ```json { "email": "mcorange@mcorangehq.xyz", "password": "password123" } ``` 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" } ``` ## ws `ws_msg_t`: 0: heartbeat ping 1: server to client 2: client to server `msg_t`: TODO! ```json { // low level message "ws_msg_t": 2, // `ws_msg_t` "ws_msg": { // high level message "auth": "3536719e-f0cf-44ce-b4d2-3400bba0c220", // Auth token "msg": { // Data field "Keypad": { "DoorOpenEv": { // "DataType": "Value, can be a struct or anything" "user": "3536719e-f0cf-44ce-b4d2-3400bba0c220", "timestamp": 123456, "door_id": "478fb503-dd05-4a1a-9292-8a5822dfed9d" } } }, } } ```