Skip to content

Commit

Permalink
fix(errs): fixing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreimus committed Sep 4, 2024
1 parent 6386c29 commit c06f175
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
28 changes: 28 additions & 0 deletions src/Controller/Api/BlockController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace PrestaSafe\PrettyBlocks\Controller\Api;

use PrestaSafe\PrettyBlocks\Registry\EntityRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;

class BlockController extends AbstractController
{
protected EntityRegistry $entityRegistry;

public function __construct(EntityRegistry $entityRegistry)
{
$this->entityRegistry = $entityRegistry;
}

/**
* Endpoint to list all available blocks
*/
public function listBlocks(): JsonResponse
{
$this->entityRegistry->getAvailableBlockTypes();
}

}
1 change: 1 addition & 0 deletions src/Controller/Api/ZoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ public function updateZone(Request $request, string $id): JsonResponse

return new JsonResponse(['status' => 'Zone updated successfully']);
}

}
5 changes: 5 additions & 0 deletions src/Registry/EntityRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public function getFieldClass(string $type): ?string
{
return $this->fieldTypes[$type] ?? null;
}

public function getAvailableBlock(): BlockCollection
{

}
}
2 changes: 2 additions & 0 deletions src/Resources/editor/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { buildNewBlockContentFromBlockStructure } from "./core-logic/utils/build
const zoneStore = useZoneStore();
onMounted(() => {
// @todo: get the content from the server instead of using the test data
const columnContent = buildNewBlockContentFromBlockStructure(columnStructure);
const allFieldsContent =
buildNewBlockContentFromBlockStructure(allFieldsStructure);
zoneStore.$patch({
availableBlocks: [columnStructure, allFieldsStructure],
content: [columnContent, allFieldsContent],
Expand Down
19 changes: 11 additions & 8 deletions src/Service/ZoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

namespace PrestaSafe\PrettyBlocks\Service;

use PrestaSafe\PrettyBlocks\Entity\Component\AbstractComponent;
use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\AbstractPrimitiveField;
use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\TextField;
use PrestaSafe\PrettyBlocks\Entity\Block\BlockInterface;
use PrestaSafe\PrettyBlocks\Entity\Zone;
use PrestaSafe\PrettyBlocks\Factory\EntityFactory;
use PrestaSafe\PrettyBlocks\Repository\ZoneRepository;
use PrestaSafe\PrettyBlocks\Entity\Block\BlockInterface;

class ZoneService
{
Expand Down Expand Up @@ -42,16 +39,22 @@ public function updateZone(Zone $zone, array $blocks): void

// Add new blocks
foreach ($blocks as $blockData) {
$block = $this->hydrateBlockFromData($blockData);
$block = $this->hydrateBlockFromDataStructure($blockData);
$zone->addBlock($block);
}

$this->zoneRepository->save($zone);
}

private function hydrateBlockFromData(array $data): BlockInterface
private function hydrateBlockFromDataStructure(array $data): BlockInterface
{
return $this->entityFactory->createBlock($data);
}
$block = $this->entityFactory->createBlock($data);
// Hydrater les champs du bloc
foreach ($data['fields'] as $fieldData) {
$field = $this->entityFactory->createField($fieldData);
$block->addField($field);
}

return $block;
}
}

0 comments on commit c06f175

Please sign in to comment.