This commit is contained in:
Marek Lenczewski
2026-03-30 23:08:24 +02:00
parent 2f96caaa23
commit 7b58e68ecb
31 changed files with 637 additions and 431 deletions

View File

@@ -3,10 +3,11 @@
namespace App\DTO\Request;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class CreateSchemaRequest
{
use SchemaValidationTrait;
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
public ?string $name = null;
@@ -20,40 +21,4 @@ class CreateSchemaRequest
public ?array $weekdays = null;
public ?array $monthDays = null;
public ?array $yearDays = null;
#[Assert\Callback]
public function validate(ExecutionContextInterface $context): void
{
if ($this->taskType !== null && $this->taskType !== 'einzel') {
if ($this->startDate !== null && $this->endDate !== null && $this->endDate < $this->startDate) {
$context->buildViolation('endDate muss >= startDate sein.')
->atPath('endDate')
->addViolation();
}
}
if ($this->taskType === 'woechentlich') {
if (empty($this->weekdays)) {
$context->buildViolation('weekdays darf nicht leer sein.')
->atPath('weekdays')
->addViolation();
}
}
if ($this->taskType === 'monatlich') {
if (empty($this->monthDays)) {
$context->buildViolation('monthDays darf nicht leer sein.')
->atPath('monthDays')
->addViolation();
}
}
if ($this->taskType === 'multi' || $this->taskType === 'jaehrlich') {
if (empty($this->yearDays)) {
$context->buildViolation('yearDays darf nicht leer sein.')
->atPath('yearDays')
->addViolation();
}
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\DTO\Request;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
trait SchemaValidationTrait
{
public function validate(ExecutionContextInterface $context): void
{
if ($this->taskType !== null && $this->taskType !== 'einzel') {
if ($this->startDate !== null && $this->endDate !== null && $this->endDate < $this->startDate) {
$context->buildViolation('endDate muss >= startDate sein.')
->atPath('endDate')
->addViolation();
}
}
if ($this->taskType === 'woechentlich') {
if (empty($this->weekdays)) {
$context->buildViolation('weekdays darf nicht leer sein.')
->atPath('weekdays')
->addViolation();
}
}
if ($this->taskType === 'monatlich') {
if (empty($this->monthDays)) {
$context->buildViolation('monthDays darf nicht leer sein.')
->atPath('monthDays')
->addViolation();
}
}
if ($this->taskType === 'multi' || $this->taskType === 'jaehrlich') {
if (empty($this->yearDays)) {
$context->buildViolation('yearDays darf nicht leer sein.')
->atPath('yearDays')
->addViolation();
}
}
}
}

View File

@@ -3,10 +3,11 @@
namespace App\DTO\Request;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class UpdateSchemaRequest
{
use SchemaValidationTrait;
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
public ?string $name = null;
@@ -21,40 +22,4 @@ class UpdateSchemaRequest
public ?array $weekdays = null;
public ?array $monthDays = null;
public ?array $yearDays = null;
#[Assert\Callback]
public function validate(ExecutionContextInterface $context): void
{
if ($this->taskType !== null && $this->taskType !== 'einzel') {
if ($this->startDate !== null && $this->endDate !== null && $this->endDate < $this->startDate) {
$context->buildViolation('endDate muss >= startDate sein.')
->atPath('endDate')
->addViolation();
}
}
if ($this->taskType === 'woechentlich') {
if (empty($this->weekdays)) {
$context->buildViolation('weekdays darf nicht leer sein.')
->atPath('weekdays')
->addViolation();
}
}
if ($this->taskType === 'monatlich') {
if (empty($this->monthDays)) {
$context->buildViolation('monthDays darf nicht leer sein.')
->atPath('monthDays')
->addViolation();
}
}
if ($this->taskType === 'multi' || $this->taskType === 'jaehrlich') {
if (empty($this->yearDays)) {
$context->buildViolation('yearDays darf nicht leer sein.')
->atPath('yearDays')
->addViolation();
}
}
}
}