-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from jaljo/feat/patch-endpoint
[RFR] add an update endpoint
- Loading branch information
Showing
11 changed files
with
205 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Domain\Command; | ||
|
||
use App\Domain\Model\Article; | ||
|
||
class EditArticle | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $title; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $content; | ||
|
||
public function __construct(Article $article) | ||
{ | ||
$this->id = $article->getId(); | ||
$this->title = $article->getTitle(); | ||
$this->content = $article->getContent(); | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function setTitle(string $title) | ||
{ | ||
$this->title = $title; | ||
} | ||
|
||
public function getContent(): string | ||
{ | ||
return $this->content; | ||
} | ||
|
||
public function setContent(string $content) | ||
{ | ||
$this->content = $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Domain\Command\Handler; | ||
|
||
use App\Domain\Command\EditArticle as EditArticleCommand; | ||
use App\Domain\Exception\ResourceNotFoundException; | ||
use App\Domain\Model\Article; | ||
use App\Domain\Repository\ArticleRepository; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
|
||
class EditArticle | ||
{ | ||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $manager; | ||
|
||
/** | ||
* @var ArticleRepository | ||
*/ | ||
private $repository; | ||
|
||
public function __construct( | ||
ObjectManager $manager, | ||
ArticleRepository $repository | ||
) { | ||
$this->manager = $manager; | ||
$this->repository = $repository; | ||
} | ||
|
||
/** | ||
* @throws ResourceNotFoundException | ||
*/ | ||
public function __invoke(EditArticleCommand $command): Article | ||
{ | ||
$article = $this->repository->findOneById($command->getId()); | ||
|
||
if ($article === null) { | ||
throw new ResourceNotFoundException(); | ||
} | ||
|
||
$article->edit( | ||
$command->getTitle(), | ||
$command->getContent() | ||
); | ||
|
||
$this->manager->persist($article); | ||
$this->manager->flush(); | ||
|
||
return $article; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters