Skip to content

Commit

Permalink
Fixed the soa categories batch creation, added the scale comment inde…
Browse files Browse the repository at this point in the history
…x validation in the service.
  • Loading branch information
ruslanbaidan committed Sep 23, 2024
1 parent b1f16f5 commit 145e488
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Controller/ApiSoaCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ public function create($data)
{
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');
$this->validatePostParams($this->postSoaCategoryDataInputValidator, $data);

$isBatchData = $this->isBatchData($data);
$this->validatePostParams($this->postSoaCategoryDataInputValidator, $data, $isBatchData);

if ($isBatchData) {
return $this->getSuccessfulJsonResponse([
'id' => $this->soaCategoryService
->createList($anr, $this->postSoaCategoryDataInputValidator->getValidDataSets()),
]);
}

return $this->getSuccessfulJsonResponse([
'id' => $this->soaCategoryService->create(
$anr,
$this->postSoaCategoryDataInputValidator->getValidData()
)->getId(),
'id' => $this->soaCategoryService->create($anr, $this->postSoaCategoryDataInputValidator->getValidData())
->getId(),
]);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Service/AnrScaleCommentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Monarc\FrontOffice\Service;

use Monarc\Core\Entity\ScaleCommentSuperClass;
use Monarc\Core\InputFormatter\FormattedInputParams;
use Monarc\Core\Entity\UserSuperClass;
use Monarc\Core\Service\ConnectedUserService;
Expand Down Expand Up @@ -52,6 +53,8 @@ public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Ent
? $data['scale']
: $this->scaleTable->findByIdAndAnr($data['scaleId'], $anr);

ScaleCommentSuperClass::validateScaleIndexValue($scale, $data['scaleIndex']);

/** @var Entity\ScaleComment $scaleComment */
$scaleComment = (new Entity\ScaleComment())
->setAnr($anr)
Expand Down
11 changes: 11 additions & 0 deletions src/Service/SoaCategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Ent
return $soaCategory;
}

public function createList(Entity\Anr $anr, array $data): array
{
$createdIds = [];
foreach ($data as $datum) {
$createdIds[] = $this->create($anr, $datum, false)->getId();
}
$this->soaCategoryTable->flush();

return $createdIds;
}

public function update(Entity\Anr $anr, int $id, array $data): Entity\SoaCategory
{
/** @var Entity\SoaCategory $soaCategory */
Expand Down

0 comments on commit 145e488

Please sign in to comment.