@@ -17,38 +17,38 @@ |
||
| 17 | 17 | |
| 18 | 18 | class AddDeviceConfigAction |
| 19 | 19 | { |
| 20 | - public function __construct( |
|
| 20 | + public function __construct( |
|
| 21 | 21 | private Security $security, |
| 22 | 22 | private EntityManagerInterface $manager, |
| 23 | 23 | private ConfigService $configService, |
| 24 | 24 | private HydratorService $hydratorService |
| 25 | - ) {} |
|
| 25 | + ) {} |
|
| 26 | 26 | |
| 27 | - public function __invoke(Request $request): JsonResponse |
|
| 28 | - { |
|
| 27 | + public function __invoke(Request $request): JsonResponse |
|
| 28 | + { |
|
| 29 | 29 | try { |
| 30 | - $json = json_decode($request->getContent(), true); |
|
| 31 | - $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
| 32 | - $configs = json_decode($json['configs'], true); |
|
| 33 | - $device = $this->manager->getRepository(Device::class)->findOneBy([ |
|
| 30 | + $json = json_decode($request->getContent(), true); |
|
| 31 | + $people = $this->manager->getRepository(People::class)->find(preg_replace("/[^0-9]/", "", $json['people'])); |
|
| 32 | + $configs = json_decode($json['configs'], true); |
|
| 33 | + $device = $this->manager->getRepository(Device::class)->findOneBy([ |
|
| 34 | 34 | 'people' => $people, |
| 35 | 35 | 'device' => $json['device'] |
| 36 | - ]); |
|
| 37 | - if (!$device) |
|
| 36 | + ]); |
|
| 37 | + if (!$device) |
|
| 38 | 38 | $device = new Device(); |
| 39 | 39 | |
| 40 | - foreach ($configs as $key => $config) |
|
| 40 | + foreach ($configs as $key => $config) |
|
| 41 | 41 | $device->addConfigs($key, $config); |
| 42 | - $device->setPeople($people); |
|
| 43 | - $device->setDevice($json['device']); |
|
| 42 | + $device->setPeople($people); |
|
| 43 | + $device->setDevice($json['device']); |
|
| 44 | 44 | |
| 45 | - $this->manager->persist($device); |
|
| 46 | - $this->manager->flush(); |
|
| 45 | + $this->manager->persist($device); |
|
| 46 | + $this->manager->flush(); |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - return new JsonResponse($this->hydratorService->item(Device::class, $device->getId(), "device:read"), Response::HTTP_OK); |
|
| 49 | + return new JsonResponse($this->hydratorService->item(Device::class, $device->getId(), "device:read"), Response::HTTP_OK); |
|
| 50 | 50 | } catch (Exception $e) { |
| 51 | - return new JsonResponse($this->hydratorService->error($e)); |
|
| 51 | + return new JsonResponse($this->hydratorService->error($e)); |
|
| 52 | + } |
|
| 52 | 53 | } |
| 53 | - } |
|
| 54 | 54 | } |