chore: created FrontendController
This commit is contained in:
parent
7311f038e9
commit
e6a3fd881a
@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
<data-source source="LOCAL" name="DDEV" uuid="07604630-4c95-4340-b0eb-dede0a6f4b43">
|
<data-source source="LOCAL" name="DDEV" uuid="11dee234-3cff-45c8-be13-0ecab2b9c755">
|
||||||
<driver-ref>mariadb</driver-ref>
|
<driver-ref>mariadb</driver-ref>
|
||||||
<synchronize>true</synchronize>
|
<synchronize>true</synchronize>
|
||||||
<configured-by-url>true</configured-by-url>
|
<configured-by-url>true</configured-by-url>
|
||||||
<remarks>DDEV generated data source</remarks>
|
<remarks>DDEV generated data source</remarks>
|
||||||
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
|
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
|
||||||
<jdbc-url>jdbc:mariadb://127.0.0.1:27702/db?user=db&password=db</jdbc-url>
|
<jdbc-url>jdbc:mariadb://127.0.0.1:32794/db?user=db&password=db</jdbc-url>
|
||||||
<working-dir>$ProjectFileDir$</working-dir>
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
</data-source>
|
</data-source>
|
||||||
</component>
|
</component>
|
||||||
|
@ -97,6 +97,13 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" />
|
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" />
|
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" />
|
||||||
<path value="$PROJECT_DIR$/vendor/webmozart/assert" />
|
<path value="$PROJECT_DIR$/vendor/webmozart/assert" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/security-http" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/security-csrf" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/security-core" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/password-hasher" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/clock" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/security-bundle" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/clock" />
|
||||||
</include_path>
|
</include_path>
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpInterpreters">
|
<component name="PhpInterpreters">
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-timer" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-timer" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/cache" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/cache" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/clock" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/event-dispatcher" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/event-dispatcher" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
|
||||||
@ -57,6 +58,7 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache-contracts" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/cache-contracts" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/clock" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/config" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/config" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/console" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/console" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/dependency-injection" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/dependency-injection" />
|
||||||
@ -73,6 +75,7 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-foundation" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-foundation" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-kernel" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-kernel" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/maker-bundle" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/maker-bundle" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/password-hasher" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-grapheme" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-grapheme" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-normalizer" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-normalizer" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||||
@ -82,6 +85,10 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/property-info" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/property-info" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/routing" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/routing" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/runtime" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/runtime" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/security-bundle" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/security-core" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/security-csrf" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/security-http" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/serializer" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/serializer" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/stopwatch" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/stopwatch" />
|
||||||
|
@ -12,7 +12,6 @@ security:
|
|||||||
main:
|
main:
|
||||||
lazy: true
|
lazy: true
|
||||||
provider: users_in_memory
|
provider: users_in_memory
|
||||||
custom_authenticator: App\Security\PrinterAuthenticator
|
|
||||||
|
|
||||||
# activate different ways to authenticate
|
# activate different ways to authenticate
|
||||||
# https://symfony.com/doc/current/security.html#the-firewall
|
# https://symfony.com/doc/current/security.html#the-firewall
|
||||||
|
19
src/Controller/FrontendController.php
Normal file
19
src/Controller/FrontendController.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
class FrontendController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/frontend', name: 'app_frontend')]
|
||||||
|
public function index(): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->json([
|
||||||
|
'message' => 'Welcome to your new controller!',
|
||||||
|
'path' => 'src/Controller/FrontendController.php',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -77,12 +77,9 @@ class PrinterCrudController extends AbstractController
|
|||||||
'message' => ErrorMessages::DOESNT_EXIST->value,
|
'message' => ErrorMessages::DOESNT_EXIST->value,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if (!$this->printerService->validateJson($request->getContent())) {
|
|
||||||
return $this->json([
|
|
||||||
'message' => ErrorMessages::DATA_INCOMPLETE,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$this->printerService->editPrinter($printer, $request->getContent());
|
||||||
|
|
||||||
|
return $this->json($printer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ use Symfony\Component\Serializer\SerializerInterface;
|
|||||||
|
|
||||||
class PrinterService
|
class PrinterService
|
||||||
{
|
{
|
||||||
|
private const REQUIRED_PROPERTIES = ['name', 'price', 'build_volume', 'max_speed'];
|
||||||
|
|
||||||
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly SerializerInterface $serializer)
|
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly SerializerInterface $serializer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -30,6 +32,20 @@ class PrinterService
|
|||||||
public function validateJson(string $jsonString): bool
|
public function validateJson(string $jsonString): bool
|
||||||
{
|
{
|
||||||
$array = json_decode($jsonString, true);
|
$array = json_decode($jsonString, true);
|
||||||
return isset($array['name'], $array['price'], $array['max_speed'], $array['build_volume']);
|
return array_keys($array) == self::REQUIRED_PROPERTIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editPrinter(Printer $printer, string $json): Printer
|
||||||
|
{
|
||||||
|
$jsonArray = json_decode($json, true);
|
||||||
|
|
||||||
|
$printer->setName($jsonArray['name'] ?? $printer->getName());
|
||||||
|
$printer->setPrice($jsonArray['price'] ?? $printer->getPrice());
|
||||||
|
$printer->setBuildVolume($jsonArray['build_volume'] ?? $printer->getBuildVolume());
|
||||||
|
$printer->setMaxSpeed($jsonArray['max_speed'] ?? $printer->getMaxSpeed());
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
return $printer;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -80,4 +80,30 @@ class PrinterServiceTest extends TestCase
|
|||||||
|
|
||||||
$this->printerService->createPrinter($json);
|
$this->printerService->createPrinter($json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function editPrinterShouldUpdatePrinterWithJsonContent(){
|
||||||
|
$json = '{
|
||||||
|
"name": "Bambu A1 Mini",
|
||||||
|
}';
|
||||||
|
|
||||||
|
$printer = new Printer();
|
||||||
|
$printer
|
||||||
|
->setName('Bambu A1')
|
||||||
|
->setPrice(10.50)
|
||||||
|
->setBuildVolume('180x180x180')
|
||||||
|
->setMaxSpeed(1000);
|
||||||
|
|
||||||
|
|
||||||
|
$expectedPrinter = new Printer();
|
||||||
|
$expectedPrinter
|
||||||
|
->setName('Bambu A1 Mini')
|
||||||
|
->setPrice(10.50)
|
||||||
|
->setBuildVolume('180x180x180')
|
||||||
|
->setMaxSpeed(1000);
|
||||||
|
|
||||||
|
$this->entityManager->expects(self::once())->method('flush');
|
||||||
|
|
||||||
|
self::assertEquals($expectedPrinter, $this->printerService->editPrinter($printer, $json));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user