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