From 1472eb3da80223470bb9da733aee04032a442b27 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Mon, 5 May 2025 09:37:01 +0200 Subject: [PATCH] Validate single submission to call per project --- .../MatchCallSubmissionCreationDto.php | 2 ++ .../SingleProjectSubmissionPerCall.php | 24 +++++++++++++ ...ingleProjectSubmissionPerCallValidator.php | 34 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/Validator/SingleProjectSubmissionPerCall.php create mode 100644 src/Validator/SingleProjectSubmissionPerCallValidator.php diff --git a/src/Dto/Matchfunding/MatchCallSubmissionCreationDto.php b/src/Dto/Matchfunding/MatchCallSubmissionCreationDto.php index 64827d8..9299538 100644 --- a/src/Dto/Matchfunding/MatchCallSubmissionCreationDto.php +++ b/src/Dto/Matchfunding/MatchCallSubmissionCreationDto.php @@ -4,8 +4,10 @@ namespace App\Dto\Matchfunding; use App\ApiResource\Matchfunding\MatchCallApiResource; use App\ApiResource\Project\ProjectApiResource; +use App\Validator\SingleProjectSubmissionPerCall; use Symfony\Component\Validator\Constraints as Assert; +#[SingleProjectSubmissionPerCall()] class MatchCallSubmissionCreationDto { /** diff --git a/src/Validator/SingleProjectSubmissionPerCall.php b/src/Validator/SingleProjectSubmissionPerCall.php new file mode 100644 index 0000000..573374a --- /dev/null +++ b/src/Validator/SingleProjectSubmissionPerCall.php @@ -0,0 +1,24 @@ +matchCallSubmissionRepository->findOneBy([ + 'call' => $value->call->id, + 'project' => $value->project->id + ]); + + if ($submission === null) { + return; + } + + $this->context->buildViolation($constraint->message) + ->addViolation() + ; + } +}