diff --git a/.http b/.http index 2501ca3..0032bca 100644 --- a/.http +++ b/.http @@ -14,5 +14,6 @@ Content-Type: application/json X-AUTH-TOKEN: {{apiKey}} { - "content": "snip api test push number 3 without name" + "name": "new snip name", + "content": "new snip content" } diff --git a/src/Controller/Api/ApiController.php b/src/Controller/Api/ApiController.php index 7f129c4..8a33b68 100644 --- a/src/Controller/Api/ApiController.php +++ b/src/Controller/Api/ApiController.php @@ -57,20 +57,11 @@ class ApiController extends AbstractApiController return $this->errorResponse('Snip is not the latest version'); } - if ($request->name) { - $snip->setName($request->name); - } - if ($request->content) { + $request->pushToSnip($snip); + $repo->save($snip); + if ($request->content !== null) { $cs->update($snip, $request->content); } - if ($request->public !== null) { - $snip->setPublic($request->public); - } - if ($request->visible !== null) { - $snip->setVisible($request->visible); - } - - $repo->save($snip); return $this->successResponse([ 'id' => $snip->getId(), diff --git a/src/Dto/SnipPostRequest.php b/src/Dto/SnipPostRequest.php index 2dc0862..f479e69 100644 --- a/src/Dto/SnipPostRequest.php +++ b/src/Dto/SnipPostRequest.php @@ -2,6 +2,8 @@ namespace App\Dto; +use App\Entity\Snip; + class SnipPostRequest { public function __construct( @@ -10,4 +12,17 @@ class SnipPostRequest public ?bool $public = null, public ?bool $visible = null, ) {} + + public function pushToSnip(Snip $snip): void + { + if ($this->name !== null) { + $snip->setName($this->name); + } + if ($this->public !== null) { + $snip->setPublic($this->public); + } + if ($this->visible !== null) { + $snip->setVisible($this->visible); + } + } } \ No newline at end of file diff --git a/src/Entity/Snip.php b/src/Entity/Snip.php index 26851d7..39d4a38 100644 --- a/src/Entity/Snip.php +++ b/src/Entity/Snip.php @@ -22,7 +22,7 @@ class Snip private ?string $name = null; #[ORM\Column] - private ?bool $public = null; + private bool $public = false; #[ORM\OneToMany(mappedBy: 'snip', targetEntity: SnipContent::class, orphanRemoval: true)] private Collection $snipContents;