pp-planer/app/Cts/CtsApiSpikeSync.php
Thorsten Bus 1756473701 feat: Laravel 12 scaffolding with Breeze Vue + Docker setup
- Install Laravel 12 with Breeze (Vue stack + Inertia.js)
- Configure Pest testing framework (5 tests passing)
- Add Docker multi-stage build (PHP 8.3 + LibreOffice + ImageMagick)
- Create docker-compose.yml with app + node services
- Configure Vite for Docker hot-reload
- Set app locale to 'de' (German)
- Add Vue packages: @vueuse/core, vue-draggable-plus, vue3-dropzone
- Update .env.example with all project vars
- Relocate spike files: src/Cts/ → app/Cts/ (Laravel autoload)
- Tests: 5 passed (14 assertions)
- Vite build: successful
- Docker: app container running

Task: T1 - Laravel Scaffolding + Breeze Vue + Docker
2026-03-01 19:25:32 +01:00

98 lines
3.3 KiB
PHP

<?php
namespace App\Cts;
use CTApi\CTClient;
use CTApi\CTConfig;
use CTApi\Models\Events\Event\EventRequest;
use CTApi\Models\Events\Song\Song;
use CTApi\Utils\CTResponseUtil;
use Throwable;
final class CtsApiSpikeSync
{
public static function run(
string $apiUrl,
string $apiToken,
string $fromDate,
int $songId,
?CTClient $client = null,
): array {
if (trim($apiToken) === '') {
return [
'auth' => [
'ok' => false,
'method' => 'none',
'blocker' => 'CTS_API_TOKEN fehlt; Authentifizierung nicht moeglich.',
],
'events' => ['count' => 0, 'first' => null],
'song' => ['hasCcli' => false, 'hasLyrics' => false, 'arrangements_count' => 0],
];
}
CTConfig::clearConfig();
CTConfig::setApiUrl(rtrim($apiUrl, '/'));
$legacyApiKeySetter = 'setApiKey';
$authMethod = 'raw-http-authorization-header';
if (method_exists(CTConfig::class, $legacyApiKeySetter)) {
CTConfig::{$legacyApiKeySetter}($apiToken);
$authMethod = 'setApiKey';
} elseif (method_exists(CTConfig::class, 'authWithLoginToken')) {
CTConfig::authWithLoginToken($apiToken);
$authMethod = 'authWithLoginToken';
}
if ($client !== null) {
CTClient::setClient($client);
}
try {
$events = EventRequest::where('from', $fromDate)->get();
$songResponse = CTClient::getClient()->get('/api/songs/' . $songId);
$songRaw = CTResponseUtil::dataAsArray($songResponse);
$song = Song::createModelFromData($songRaw);
} catch (Throwable $throwable) {
return [
'auth' => [
'ok' => false,
'method' => $authMethod,
'blocker' => $throwable->getMessage(),
],
'events' => ['count' => 0, 'first' => null],
'song' => ['hasCcli' => false, 'hasLyrics' => false, 'arrangements_count' => 0],
];
}
$firstEvent = $events[0] ?? null;
return [
'auth' => [
'ok' => true,
'method' => $authMethod,
'blocker' => null,
],
'events' => [
'count' => count($events),
'first' => $firstEvent === null ? null : [
'id' => $firstEvent->getId(),
'title' => $firstEvent->getName(),
'start_date' => $firstEvent->getStartDate(),
'note' => $firstEvent->getNote(),
],
],
'song' => [
'hasCcli' => $song !== null && trim((string) $song->getCcli()) !== '',
'ccli' => $song?->getCcli(),
'hasLyrics' => array_key_exists('lyrics', $songRaw),
'lyrics_type' => is_array($songRaw['lyrics'] ?? null) ? ($songRaw['lyrics']['type'] ?? null) : null,
'arrangements_count' => $song === null ? 0 : count($song->getArrangements()),
],
'raw_shapes' => [
'song_keys' => array_keys($songRaw),
],
];
}
}