Linedance API
FastAPI backend med MySQL, JWT auth og WebSocket live-opdateringer.
Opsætning på VPS
1. Klon og installer
git clone <dit-repo>
cd linedance-api
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
2. Konfigurer miljøvariabler
cp .env.example .env
nano .env
Udfyld disse værdier:
DATABASE_URL=mysql+pymysql://BRUGER:KODEORD@localhost:3306/linedance
SECRET_KEY=<lang tilfældig streng — kør: openssl rand -hex 32>
ACCESS_TOKEN_EXPIRE_MINUTES=10080
3. Opret MySQL-database
CREATE DATABASE linedance CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'linedance'@'localhost' IDENTIFIED BY 'dit-kodeord';
GRANT ALL PRIVILEGES ON linedance.* TO 'linedance'@'localhost';
FLUSH PRIVILEGES;
4. Start API (udvikling)
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
5. Start API (produktion med systemd)
Opret /etc/systemd/system/linedance.service:
[Unit]
Description=Linedance API
After=network.target
[Service]
User=www-data
WorkingDirectory=/var/www/linedance-api
Environment="PATH=/var/www/linedance-api/venv/bin"
ExecStart=/var/www/linedance-api/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2
Restart=always
[Install]
WantedBy=multi-user.target
systemctl enable linedance
systemctl start linedance
API-oversigt
| Metode | Sti | Beskrivelse |
|---|---|---|
| POST | /auth/register |
Opret bruger |
| POST | /auth/login |
Log ind, få token |
| GET | /projects/ |
Mine projekter |
| POST | /projects/ |
Opret projekt |
| PATCH | /projects/{id} |
Rediger projekt |
| POST | /projects/{id}/invite |
Inviter bruger |
| GET | /projects/invitations/pending |
Afventende invitationer |
| POST | /projects/invitations/{id}/accept |
Accepter invitation |
| GET | /projects/{id}/songs |
Danseliste |
| POST | /projects/{id}/songs |
Tilføj sang |
| PATCH | /projects/{id}/songs/{ps_id}/status |
Opdater status (playing/played/skipped) |
| GET | /songs/ |
Mine sange |
| POST | /songs/ |
Opret sang |
| POST | /songs/{id}/dances |
Tilføj dans til sang |
| POST | /songs/{id}/dances/{did}/alternatives |
Tilføj alternativ-dans |
| WS | /ws/{project_id} |
Live opdateringer |
Interaktiv dokumentation
Åbn http://din-server:8000/docs i browseren.