|
20 | 20 |
|
21 | 21 | use DateTime;
|
22 | 22 | use Ramsey\Uuid\Uuid;
|
| 23 | +use Surfnet\Stepup\Helper\JsonHelper; |
| 24 | +use Surfnet\StepupMiddleware\ApiBundle\Exception\BadCommandRequestException; |
23 | 25 | use Surfnet\StepupMiddleware\CommandHandlingBundle\Command\AbstractCommand;
|
24 | 26 | use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\UpdateConfigurationCommand;
|
25 | 27 | use Surfnet\StepupMiddleware\CommandHandlingBundle\Pipeline\TransactionAwarePipeline;
|
| 28 | +use Surfnet\StepupMiddleware\ManagementBundle\Validator\Constraints\HasValidConfigurationStructure; |
26 | 29 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
27 | 30 | use Symfony\Component\HttpFoundation\JsonResponse;
|
28 | 31 | use Symfony\Component\HttpFoundation\Request;
|
| 32 | +use Symfony\Component\Validator\Validator\ValidatorInterface; |
29 | 33 |
|
30 | 34 | class ConfigurationController extends AbstractController
|
31 | 35 | {
|
32 | 36 | public function __construct(
|
33 | 37 | private readonly TransactionAwarePipeline $pipeline,
|
| 38 | + private readonly ValidatorInterface $validator, |
34 | 39 | ) {
|
35 | 40 | }
|
36 | 41 |
|
37 | 42 | public function update(Request $request): JsonResponse
|
38 | 43 | {
|
39 | 44 | $this->denyAccessUnlessGranted('ROLE_MANAGEMENT');
|
40 | 45 |
|
| 46 | + $violations = $this->validator->validate($request->getContent(), new HasValidConfigurationStructure()); |
| 47 | + if ($violations->count() > 0) { |
| 48 | + throw BadCommandRequestException::withViolations('Invalid configure institutions request', $violations); |
| 49 | + } |
| 50 | + |
41 | 51 | $command = new UpdateConfigurationCommand();
|
42 | 52 | $command->configuration = $request->getContent();
|
43 | 53 | $command->UUID = (string)Uuid::uuid4();
|
|
0 commit comments