Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed May 22, 2024
1 parent bfc3794 commit 39840b7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Note/Controller/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use OpenApi\Attributes\Delete;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\IdJson;
Expand All @@ -44,6 +45,9 @@ public function __construct(
parent::__construct($serializer);
}

/**
* @throws ElementNotFoundException
*/
#[Route('/notes/{id}', name: 'pimcore_studio_api_delete_note', methods: ['DELETE'])]
#[IsGranted(UserPermissions::NOTES_EVENTS->value)]
#[Delete(
Expand Down
4 changes: 4 additions & 0 deletions src/Note/Controller/Element/CreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Note\Attributes\Request\CreateNoteRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\CreateNote;
Expand Down Expand Up @@ -47,6 +48,9 @@ public function __construct(
parent::__construct($serializer);
}

/**
* @throws ElementSavingFailedException
*/
#[Route('/notes/{elementType}/{id}', name: 'pimcore_studio_api_create_element_note', methods: ['POST'])]
#[IsGranted(UserPermissions::NOTES_EVENTS->value)]
#[Post(
Expand Down
12 changes: 11 additions & 1 deletion src/Note/Repository/NoteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

namespace Pimcore\Bundle\StudioBackendBundle\Note\Repository;

use Exception;
use Pimcore\Bundle\StaticResolverBundle\Models\Element\NoteResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteParameters;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\CreateNote;
Expand All @@ -33,6 +35,9 @@ public function __construct(private NoteResolverInterface $noteResolver)
{
}

/**
* @throws ElementSavingFailedException
*/
public function createNote(NoteElement $noteElement, CreateNote $createNote): Note
{
$note = new Note();
Expand All @@ -43,7 +48,12 @@ public function createNote(NoteElement $noteElement, CreateNote $createNote): No
$note->setDescription($createNote->getDescription());
$note->setType($createNote->getType());
$note->setLocked(false);
$note->save();

try {
$note->save();
} catch (Exception $e) {
throw new ElementSavingFailedException(0, $e->getTraceAsString());
}

return $note;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Note/Repository/NoteRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Pimcore\Bundle\StudioBackendBundle\Note\Repository;

use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteParameters;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\CreateNote;
Expand All @@ -28,6 +29,9 @@
*/
interface NoteRepositoryInterface
{
/**
* @throws ElementSavingFailedException
*/
public function createNote(NoteElement $noteElement, CreateNote $createNote): Note;

public function getNote(int $id): Note;
Expand Down
1 change: 0 additions & 1 deletion src/Note/Request/NoteParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace Pimcore\Bundle\StudioBackendBundle\Note\Request;

use Pimcore\Bundle\StudioBackendBundle\Request\CollectionParameters;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes;

/**
* @internal
Expand Down
11 changes: 7 additions & 4 deletions src/Note/Service/NoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
namespace Pimcore\Bundle\StudioBackendBundle\Note\Service;

use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Note\Hydrator\NoteHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Repository\NoteRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElementInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteParameters;
use Pimcore\Bundle\StudioBackendBundle\Note\Response\Collection;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\CreateNote;
Expand All @@ -29,16 +29,19 @@
/**
* @internal
*/
final class NoteService implements NoteServiceInterface
final readonly class NoteService implements NoteServiceInterface
{

public function __construct(
private readonly NoteRepositoryInterface $noteRepository,
private readonly NoteHydratorInterface $noteHydrator
private NoteRepositoryInterface $noteRepository,
private NoteHydratorInterface $noteHydrator
)
{
}

/**
* @throws ElementSavingFailedException
*/
public function createNote(NoteElement $noteElement, CreateNote $createNote): Note
{
$note = $this->noteRepository->createNote($noteElement, $createNote);
Expand Down
4 changes: 4 additions & 0 deletions src/Note/Service/NoteServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Pimcore\Bundle\StudioBackendBundle\Note\Service;

use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement;
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteParameters;
use Pimcore\Bundle\StudioBackendBundle\Note\Response\Collection;
Expand All @@ -28,6 +29,9 @@
*/
interface NoteServiceInterface
{
/**
* @throws ElementSavingFailedException
*/
public function createNote(NoteElement $noteElement, CreateNote $createNote): Note;

public function listNotes(NoteElement $noteElement, NoteParameters $parameters): Collection;
Expand Down

0 comments on commit 39840b7

Please sign in to comment.