API updadte

This commit is contained in:
2025-11-09 11:27:21 +01:00
parent 77206224a2
commit 4953d192c0
8 changed files with 2343 additions and 784 deletions

302
docs/development.md Normal file
View File

@@ -0,0 +1,302 @@
# Entwicklung
[← Zurück zur Hauptseite](../README.md)
## Entwickler-Workflow
### Entwicklungsumgebung einrichten
Siehe [Installation](installation.md)
### Code-Änderungen testen
```bash
# Container starten
docker-compose up -d
# In Web-Container einloggen
docker-compose exec web bash
# Cache leeren nach Änderungen
php bin/console cache:clear
```
## Testing
### PHPUnit Tests
Das Projekt verwendet PHPUnit 12.4 für Tests.
#### Alle Tests ausführen
```bash
docker-compose exec web php bin/phpunit
```
#### Spezifische Tests
```bash
# Nur Entity-Tests
docker-compose exec web php bin/phpunit tests/Entity
# Nur API-Tests
docker-compose exec web php bin/phpunit tests/Api
# Einzelne Testklasse
docker-compose exec web php bin/phpunit tests/Entity/UserTest.php
```
#### Mit Details
```bash
docker-compose exec web php bin/phpunit --verbose
```
#### Code Coverage (optional)
```bash
docker-compose exec web php bin/phpunit --coverage-text
```
### Test-Struktur
```
tests/
├── Entity/
│ ├── UserTest.php # User-Entity Tests
│ ├── ImmobilieTest.php # Immobilie-Entity Tests
│ ├── BundeslandTest.php # Bundesland-Entity Tests
│ └── HeizungstypTest.php # Heizungstyp-Entity Tests
└── Api/
├── BundeslandApiTest.php # Bundesländer-API Tests
├── HeizungstypApiTest.php # Heizungstypen-API Tests
└── ApiDocumentationTest.php # API-Docs Tests
```
## Code Quality
### PHP-CS-Fixer
Für konsistenten Code-Style nach Symfony Standards.
#### Code-Style prüfen (Dry-Run)
```bash
docker-compose exec web vendor/bin/php-cs-fixer fix --dry-run --diff
```
#### Code automatisch formatieren
```bash
docker-compose exec web vendor/bin/php-cs-fixer fix
```
#### Bestimmte Verzeichnisse
```bash
# Nur src/
docker-compose exec web vendor/bin/php-cs-fixer fix src
# Nur tests/
docker-compose exec web vendor/bin/php-cs-fixer fix tests
```
### Code-Style Regeln
Konfiguration in `.php-cs-fixer.dist.php`:
- Symfony Coding Standards
- PSR-12 kompatibel
- Short Array Syntax
- Sortierte Imports
- Trailing Commas in Arrays
## Datenbank
### Neue Entity erstellen
```bash
docker-compose exec web php bin/console make:entity
```
### Migration erstellen
Nach Änderungen an Entities:
```bash
docker-compose exec web php bin/console doctrine:migrations:diff
```
### Migration ausführen
```bash
docker-compose exec web php bin/console doctrine:migrations:migrate
```
### Migration rückgängig machen
```bash
# Letzte Migration
docker-compose exec web php bin/console doctrine:migrations:migrate prev
# Zu spezifischer Version
docker-compose exec web php bin/console doctrine:migrations:migrate DoctrineMigrations\\Version20251109100000
```
### Migration-Status
```bash
docker-compose exec web php bin/console doctrine:migrations:status
```
### Datenbank-Schema validieren
```bash
docker-compose exec web php bin/console doctrine:schema:validate
```
## Controller & Routes
### Controller erstellen
```bash
docker-compose exec web php bin/console make:controller
```
### Routes anzeigen
```bash
# Alle Routes
docker-compose exec web php bin/console debug:router
# Spezifische Route
docker-compose exec web php bin/console debug:router app_home
```
## Symfony Console
### Cache
```bash
# Cache leeren
docker-compose exec web php bin/console cache:clear
# Cache warmup
docker-compose exec web php bin/console cache:warmup
```
### Services debuggen
```bash
# Alle Services
docker-compose exec web php bin/console debug:container
# Spezifischer Service
docker-compose exec web php bin/console debug:container UserRepository
```
### Ereignisse anzeigen
```bash
docker-compose exec web php bin/console debug:event-dispatcher
```
### Konfiguration anzeigen
```bash
docker-compose exec web php bin/console debug:config framework
```
## Git Workflow
### Feature-Branch erstellen
```bash
git checkout -b feature/neue-funktion
```
### Änderungen committen
```bash
git add .
git commit -m "Feature: Beschreibung der Änderung"
```
### Pull Request erstellen
1. Push auf Remote Branch
2. Pull Request in GitHub/GitLab erstellen
3. Code Review abwarten
4. Nach Approval mergen
## Best Practices
### Code-Organisation
1. **Controller:** Dünn halten, Logik in Services auslagern
2. **Entities:** Nur Datenmodell, keine Business-Logik
3. **Services:** Wiederverwendbare Business-Logik
4. **Repositories:** Nur Datenbank-Queries
### Namenskonventionen
- **Controller:** `XyzController.php`
- **Entity:** `Xyz.php`
- **Repository:** `XyzRepository.php`
- **Service:** `XyzService.php`
- **Test:** `XyzTest.php`
### Security
- Nie Passwörter im Klartext speichern
- Immer UserPasswordHasher verwenden
- CSRF-Tokens bei allen Forms
- Input-Validierung auf Server-Seite
- Output-Escaping (Twig macht automatisch)
### Performance
- Doctrine Query Cache nutzen
- Eager Loading für Relationen
- Opcache in Produktion aktivieren
- Assets kompilieren für Produktion
## Deployment
### Vorbereitung
```bash
# .env.local für Produktion erstellen
cp .env .env.local
# Produktions-Werte setzen
APP_ENV=prod
APP_SECRET=<neues-secret-generieren>
```
### Build für Produktion
```bash
# Composer Dependencies ohne Dev
composer install --no-dev --optimize-autoloader
# Cache warmup
php bin/console cache:warmup --env=prod
# Assets installieren
php bin/console assets:install public --symlink --relative --env=prod
```
### Database Migration
```bash
php bin/console doctrine:migrations:migrate --no-interaction --env=prod
```
---
**Siehe auch:**
- [Technical](technical.md) - Architektur & Konfiguration
- [Docker](docker.md) - Container-Management
- [Troubleshooting](troubleshooting.md) - Fehler beheben
[← Zurück zur Hauptseite](../README.md)