Files
svc-essensplanung/src/Data/Essen/Entity/MahlzeitEntity.php
T
jens 1589088379 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).
2026-09-19 08:55:54 +02:00

152 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace App\Data\Essen\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Doctrine-Entity für `essens_mahlzeiten`.
*
* Bewusst "dumm": nur Getter/Setter, keine Fachlogik (die lebt im Rich-Model
* `App\Logic\Essen\Model\Mahlzeit`). `wochentage` wird als CSV-String
* ("mo,di,fr") persistiert – das Mapping ins `Wochentag[]`-Array macht der Mapper.
*/
#[ORM\Entity]
#[ORM\Table(name: 'essens_mahlzeiten')]
#[ORM\Index(columns: ['status'], name: 'idx_status')]
#[ORM\Index(columns: ['sort_order'], name: 'idx_sort_order')]
final class MahlzeitEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
private string $name = '';
#[ORM\Column(type: 'text', nullable: true)]
private ?string $notiz = null;
/** CSV der Wochentag-Kurzformen, z. B. "mo,di,fr". */
#[ORM\Column(type: 'string', length: 32, nullable: true)]
private ?string $wochentage = null;
#[ORM\Column(type: 'integer')]
private int $sortOrder = 0;
#[ORM\Column(type: 'string', length: 32)]
private string $status = 'geplant';
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $gegessenAm = null;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $erstelltAm;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $aktualisiertAm;
public function __construct()
{
$now = new \DateTimeImmutable();
$this->erstelltAm = $now;
$this->aktualisiertAm = $now;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getNotiz(): ?string
{
return $this->notiz;
}
public function setNotiz(?string $notiz): self
{
$this->notiz = $notiz;
return $this;
}
public function getWochentage(): ?string
{
return $this->wochentage;
}
public function setWochentage(?string $wochentage): self
{
$this->wochentage = $wochentage;
return $this;
}
public function getSortOrder(): int
{
return $this->sortOrder;
}
public function setSortOrder(int $sortOrder): self
{
$this->sortOrder = $sortOrder;
return $this;
}
public function getStatus(): string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getGegessenAm(): ?\DateTimeImmutable
{
return $this->gegessenAm;
}
public function setGegessenAm(?\DateTimeImmutable $gegessenAm): self
{
$this->gegessenAm = $gegessenAm;
return $this;
}
public function getErstelltAm(): \DateTimeImmutable
{
return $this->erstelltAm;
}
public function setErstelltAm(\DateTimeImmutable $erstelltAm): self
{
$this->erstelltAm = $erstelltAm;
return $this;
}
public function getAktualisiertAm(): \DateTimeImmutable
{
return $this->aktualisiertAm;
}
public function setAktualisiertAm(\DateTimeImmutable $aktualisiertAm): self
{
$this->aktualisiertAm = $aktualisiertAm;
return $this;
}
}