M1: CRUD-Slice 'Mahlzeit' Schritt 1 – Logik + Daten + Tests

Rich-Model Mahlzeit (MahlzeitStatus, Wochentag) mit Invarianten und
Zustandsübergängen; DTOs + MahlzeitFactory (reine Mapping-Funktionen);
Manager (create hängt an Ende an: maxSortOrder+1, find → 404) und
Create/Update/Delete-UseCases mit Transaktion + Events nach Commit.

Data-Layer: MahlzeitEntity (Tabelle essens_mahlzeiten, wochentage als
CSV), Mapper (CSV/Enum/null), Provider (find/list/maxSortOrder),
Processor (create/save/delete). DI-Bindings in services.yaml.
ClockInterface (Logic) + SystemClock (Data).

Tests: Model/Factory/UseCase-Unit + Provider/Processor/Mapper-Integration
(In-Mem-SQLite). composer test grün (53 Tests, 161 Assertions).
This commit is contained in:
2026-09-19 08:55:54 +02:00
parent cb3cbfb394
commit 1589088379
42 changed files with 2493 additions and 138 deletions
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace App\Logic\Essen\Manager;
use App\Logic\Essen\Exception\MahlzeitNotFoundException;
use App\Logic\Essen\MahlzeitProviderInterface;
use App\Logic\Essen\MahlzeitProcessorInterface;
use App\Logic\Essen\Model\Mahlzeit;
use App\Logic\Essen\Model\MahlzeitStatus;
/**
* Standard-Implementierung: kombiniert Provider (Read) + Processor (Write).
*
* @see MahlzeitManagerInterface
*/
final class MahlzeitManager implements MahlzeitManagerInterface
{
public function __construct(
private readonly MahlzeitProviderInterface $provider,
private readonly MahlzeitProcessorInterface $processor,
) {
}
public function create(Mahlzeit $mahlzeit): Mahlzeit
{
$mahlzeit = $mahlzeit->mitSortOrder($this->provider->maxSortOrder() + 1);
return $this->processor->create($mahlzeit);
}
public function update(Mahlzeit $mahlzeit): Mahlzeit
{
return $this->processor->save($mahlzeit);
}
public function delete(int $id): void
{
$this->find($id);
$mahlzeit = $this->provider->find($id);
if ($mahlzeit !== null) {
$this->processor->delete($mahlzeit);
}
}
public function find(int $id): Mahlzeit
{
return $this->provider->find($id) ?? throw new MahlzeitNotFoundException($id);
}
/** @return list<Mahlzeit> */
public function list(?MahlzeitStatus $status = null): array
{
return $this->provider->list($status);
}
}