From fe4e4fa940c1517e8e36eabf5c7a375c9fae5bcc Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 13 Mar 2024 06:43:01 +0100 Subject: [PATCH] initial --- .idea/inspectionProfiles/Project_Default.xml | 6 +++ assets/app.js | 9 ++++ assets/styles/app.css | 3 ++ composer.json | 1 + composer.lock | 45 +++++++++++++++++++- config/packages/asset_mapper.yaml | 5 +++ importmap.php | 21 +++++++++ src/Controller/PrinterCrudController.php | 10 +++-- src/Entity/Printer.php | 1 + src/Service/PrinterService.php | 3 ++ tests/Service/PrinterServiceTest.php | 2 +- 11 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 assets/app.js create mode 100644 assets/styles/app.css create mode 100644 config/packages/asset_mapper.yaml create mode 100644 importmap.php diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..d829d01 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/assets/app.js b/assets/app.js new file mode 100644 index 0000000..6174cc6 --- /dev/null +++ b/assets/app.js @@ -0,0 +1,9 @@ +/* + * Welcome to your app's main JavaScript file! + * + * This file will be included onto the page via the importmap() Twig function, + * which should already be in your base.html.twig. + */ +import './styles/app.css'; + +console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉'); diff --git a/assets/styles/app.css b/assets/styles/app.css new file mode 100644 index 0000000..dd6181a --- /dev/null +++ b/assets/styles/app.css @@ -0,0 +1,3 @@ +body { + background-color: skyblue; +} diff --git a/composer.json b/composer.json index d0d3a86..1d09755 100644 --- a/composer.json +++ b/composer.json @@ -78,6 +78,7 @@ } }, "require-dev": { + "deployer/deployer": "^7.3", "phpunit/phpunit": "10.*", "symfony/maker-bundle": "^1.52" } diff --git a/composer.lock b/composer.lock index c537f68..fc35481 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "717ed6c3538dfaff4c72623709f0f132", + "content-hash": "4e665d72a03b66f5922cfc55b5e1410d", "packages": [ { "name": "composer/semver", @@ -5714,6 +5714,49 @@ } ], "packages-dev": [ + { + "name": "deployer/deployer", + "version": "v7.3.3", + "source": { + "type": "git", + "url": "https://github.com/deployphp/deployer.git", + "reference": "3535bdb2f6360662bd95f6e26fce31dbc269af64" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/deployphp/deployer/zipball/3535bdb2f6360662bd95f6e26fce31dbc269af64", + "reference": "3535bdb2f6360662bd95f6e26fce31dbc269af64", + "shasum": "" + }, + "bin": [ + "dep" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anton Medvedev", + "email": "anton@medv.io" + } + ], + "description": "Deployment Tool", + "homepage": "https://deployer.org", + "support": { + "docs": "https://deployer.org/docs", + "issues": "https://github.com/deployphp/deployer/issues", + "source": "https://github.com/deployphp/deployer" + }, + "funding": [ + { + "url": "https://github.com/sponsors/antonmedv", + "type": "github" + } + ], + "time": "2023-11-07T10:27:12+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.11.1", diff --git a/config/packages/asset_mapper.yaml b/config/packages/asset_mapper.yaml new file mode 100644 index 0000000..d1ac653 --- /dev/null +++ b/config/packages/asset_mapper.yaml @@ -0,0 +1,5 @@ +framework: + asset_mapper: + # The paths to make available to the asset mapper. + paths: + - assets/ diff --git a/importmap.php b/importmap.php new file mode 100644 index 0000000..c29b9d6 --- /dev/null +++ b/importmap.php @@ -0,0 +1,21 @@ + [ + 'path' => './public/js/frontend.js', + 'entrypoint' => true, + ], +]; diff --git a/src/Controller/PrinterCrudController.php b/src/Controller/PrinterCrudController.php index 1736e7d..aba3347 100644 --- a/src/Controller/PrinterCrudController.php +++ b/src/Controller/PrinterCrudController.php @@ -9,6 +9,7 @@ use App\Service\PrinterService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class PrinterCrudController extends AbstractController @@ -29,10 +30,11 @@ class PrinterCrudController extends AbstractController #[Route('/printer/{id}', name: 'get_printer', methods: ['GET'])] public function getPrinter(?Printer $printer): JsonResponse { + //TODO: ungleich null und in funktion auslagern if (!$printer) { return $this->json([ 'message' => ErrorMessages::DOESNT_EXIST->value, - ]); + ], Response::HTTP_NOT_FOUND); } return $this->json($printer); @@ -44,7 +46,7 @@ class PrinterCrudController extends AbstractController if (!$printer) { return $this->json([ 'message' => ErrorMessages::DOESNT_EXIST->value, - ]); + ], Response::HTTP_NOT_FOUND); } $this->printerService->deletePrinter($printer); @@ -61,7 +63,7 @@ class PrinterCrudController extends AbstractController if (!$this->printerService->validateJson($jsonContent)) { return $this->json([ 'message' => ErrorMessages::DATA_INCOMPLETE->value, - ]); + ], Response::HTTP_NOT_FOUND); } $printer = $this->printerService->createPrinter($jsonContent); @@ -75,7 +77,7 @@ class PrinterCrudController extends AbstractController if (!$printer) { return $this->json([ 'message' => ErrorMessages::DOESNT_EXIST->value, - ]); + ], Response::HTTP_NOT_FOUND); } $this->printerService->editPrinter($printer, $request->getContent()); diff --git a/src/Entity/Printer.php b/src/Entity/Printer.php index 5c15ffc..d2e3c49 100644 --- a/src/Entity/Printer.php +++ b/src/Entity/Printer.php @@ -15,6 +15,7 @@ class Printer implements JsonSerializable #[ORM\Column] private ?int $id = null; + //TODO doctrine required #[ORM\Column(length: 255)] private ?string $name = null; diff --git a/src/Service/PrinterService.php b/src/Service/PrinterService.php index f6dae75..3662cb3 100644 --- a/src/Service/PrinterService.php +++ b/src/Service/PrinterService.php @@ -22,6 +22,7 @@ class PrinterService public function createPrinter(string $jsonString): Printer { + //TODO use serializer for validation $printer = $this->serializer->deserialize($jsonString, Printer::class, 'json'); $this->entityManager->persist($printer); @@ -33,11 +34,13 @@ class PrinterService public function validateJson(string $jsonString): bool { $array = json_decode($jsonString, true); + //TODO: find another way return array_keys($array) == self::REQUIRED_PROPERTIES; } public function editPrinter(Printer $printer, string $json): Printer { + //TODO use deserialize $jsonArray = json_decode($json, true); $printer->setName($jsonArray['name'] ?? $printer->getName()); diff --git a/tests/Service/PrinterServiceTest.php b/tests/Service/PrinterServiceTest.php index 6e76f39..5d1da17 100644 --- a/tests/Service/PrinterServiceTest.php +++ b/tests/Service/PrinterServiceTest.php @@ -84,7 +84,7 @@ class PrinterServiceTest extends TestCase #[Test] public function editPrinterShouldUpdatePrinterWithJsonContent(){ $json = '{ - "name": "Bambu A1 Mini", + "name": "Bambu A1 Mini" }'; $printer = new Printer();