This commit is contained in:
Jan Klattenhoff 2024-03-13 06:43:01 +01:00
parent 2a1ce070a2
commit fe4e4fa940
11 changed files with 100 additions and 6 deletions

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PhpCSFixerValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>

9
assets/app.js Normal file

@ -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! 🎉');

3
assets/styles/app.css Normal file

@ -0,0 +1,3 @@
body {
background-color: skyblue;
}

@ -78,6 +78,7 @@
}
},
"require-dev": {
"deployer/deployer": "^7.3",
"phpunit/phpunit": "10.*",
"symfony/maker-bundle": "^1.52"
}

45
composer.lock generated

@ -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",

@ -0,0 +1,5 @@
framework:
asset_mapper:
# The paths to make available to the asset mapper.
paths:
- assets/

21
importmap.php Normal file

@ -0,0 +1,21 @@
<?php
/**
* Returns the importmap for this application.
*
* - "path" is a path inside the asset mapper system. Use the
* "debug:asset-map" command to see the full list of paths.
*
* - "entrypoint" (JavaScript only) set to true for any module that will
* be used as an "entrypoint" (and passed to the importmap() Twig function).
*
* The "importmap:require" command can be used to add new entries to this file.
*
* This file has been auto-generated by the importmap commands.
*/
return [
'frontend' => [
'path' => './public/js/frontend.js',
'entrypoint' => true,
],
];

@ -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());

@ -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;

@ -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());

@ -84,7 +84,7 @@ class PrinterServiceTest extends TestCase
#[Test]
public function editPrinterShouldUpdatePrinterWithJsonContent(){
$json = '{
"name": "Bambu A1 Mini",
"name": "Bambu A1 Mini"
}';
$printer = new Printer();