This commit is contained in:
2026-04-12 11:34:09 +02:00
parent 57f3c913b4
commit 99cab7be86
15 changed files with 635 additions and 281 deletions

View File

@@ -1,87 +1,39 @@
# Linedance API
# LineDance API
FastAPI backend med MySQL, JWT auth og WebSocket live-opdateringer.
## Hurtig start med Docker
## Opsætning på VPS
### 1. Klon og installer
```bash
git clone <dit-repo>
cd linedance-api
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
### 2. Konfigurer miljøvariabler
```bash
# 1. Kopiér miljøfil
cp .env.example .env
# 2. Rediger .env — sæt stærke kodeord
nano .env
# 3. Start hele stacken
docker compose up -d
# 4. Tjek at alt kører
docker compose ps
docker compose logs api
```
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
```
## Tilgængelige services
### 3. Opret MySQL-database
```sql
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;
```
| Service | URL | Beskrivelse |
|----------|----------------------------|--------------------------|
| API | http://localhost:8000 | FastAPI |
| Docs | http://localhost:8000/docs | Swagger UI |
| Adminer | http://localhost:8080 | Database admin |
| MailHog | http://localhost:8025 | Test-mails |
### 4. Start API (udvikling)
```bash
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
```
## Adminer login
- Server: `db`
- Bruger: `linedance`
- Kodeord: (fra .env MYSQL_PASSWORD)
- Database: `linedance`
### 5. Start API (produktion med systemd)
Opret `/etc/systemd/system/linedance.service`:
```ini
[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
```
```bash
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.
## Produktion
- Skift `MAIL_HOST` til rigtig SMTP-server
- Sæt `BASE_URL` til dit domæne
- Brug `SECRET_KEY` med mindst 32 tilfældige tegn
- Fjern `adminer` og `mailhog` fra docker-compose