Update api snip update
This commit is contained in:
parent
74154e240f
commit
e2c8376482
3
.http
3
.http
@ -14,5 +14,6 @@ Content-Type: application/json
|
|||||||
X-AUTH-TOKEN: {{apiKey}}
|
X-AUTH-TOKEN: {{apiKey}}
|
||||||
|
|
||||||
{
|
{
|
||||||
"content": "snip api test push number 3 without name"
|
"name": "new snip name",
|
||||||
|
"content": "new snip content"
|
||||||
}
|
}
|
||||||
|
@ -57,20 +57,11 @@ class ApiController extends AbstractApiController
|
|||||||
return $this->errorResponse('Snip is not the latest version');
|
return $this->errorResponse('Snip is not the latest version');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->name) {
|
$request->pushToSnip($snip);
|
||||||
$snip->setName($request->name);
|
$repo->save($snip);
|
||||||
}
|
if ($request->content !== null) {
|
||||||
if ($request->content) {
|
|
||||||
$cs->update($snip, $request->content);
|
$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([
|
return $this->successResponse([
|
||||||
'id' => $snip->getId(),
|
'id' => $snip->getId(),
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Dto;
|
namespace App\Dto;
|
||||||
|
|
||||||
|
use App\Entity\Snip;
|
||||||
|
|
||||||
class SnipPostRequest
|
class SnipPostRequest
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@ -10,4 +12,17 @@ class SnipPostRequest
|
|||||||
public ?bool $public = null,
|
public ?bool $public = null,
|
||||||
public ?bool $visible = 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,7 +22,7 @@ class Snip
|
|||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
private ?bool $public = null;
|
private bool $public = false;
|
||||||
|
|
||||||
#[ORM\OneToMany(mappedBy: 'snip', targetEntity: SnipContent::class, orphanRemoval: true)]
|
#[ORM\OneToMany(mappedBy: 'snip', targetEntity: SnipContent::class, orphanRemoval: true)]
|
||||||
private Collection $snipContents;
|
private Collection $snipContents;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user