Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
scrum-app-sample-php/src/packages/scrum/Application/Service/BackLog/BackLogApplicationService.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
68 lines (59 sloc)
2.13 KB
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
<?php | |
namespace Scrum\Application\Service\BackLog; | |
use Basic\Exception\NotFoundException; | |
use Basic\Transaction\Transaction; | |
use Scrum\Domain\Models\User\UserContextInterface; | |
use Scrum\Domain\Models\UserStories\UserStory; | |
use Scrum\Domain\Models\UserStories\UserStoryId; | |
use Scrum\Domain\Models\UserStories\UserStoryRepositoryInterface; | |
class BackLogApplicationService | |
{ | |
/** @var Transaction */ | |
private $transaction; | |
/** @var UserContextInterface */ | |
private $userContext; | |
/** @var UserStoryRepositoryInterface */ | |
private $userStoryRepository; | |
/** | |
* BackLogApplicationService constructor. | |
* @param UserStoryRepositoryInterface $userStoryRepository | |
* @param Transaction $transaction | |
* @param UserContextInterface $userContext | |
*/ | |
public function __construct(Transaction $transaction, UserContextInterface $userContext, UserStoryRepositoryInterface $userStoryRepository) | |
{ | |
$this->transaction = $transaction; | |
$this->userContext = $userContext; | |
$this->userStoryRepository = $userStoryRepository; | |
} | |
public function getUserStory(string $aId): ?UserStory | |
{ | |
$id = new UserStoryId($aId); | |
return $this->userStoryRepository->find($id); | |
} | |
public function addUserStory(AddUserStoryCommand $command): void | |
{ | |
$this->transaction->scope(function () use ($command) { | |
$id = new UserStoryId(uniqid()); | |
$story = new UserStory( | |
$id, | |
$command->getStory(), | |
$this->userContext->getId(), | |
$command->getDemo() | |
); | |
$this->userStoryRepository->save($story); | |
}); | |
} | |
public function estimateUserStory(string $aId, int $estimation): void | |
{ | |
$this->transaction->scope(function () use ($aId, $estimation) { | |
$id = new UserStoryId($aId); | |
$story = $this->userStoryRepository->find($id); | |
if (is_null($story)) { | |
throw new NotFoundException($aId . " not found."); | |
} | |
$story->estimate($estimation); | |
$this->userStoryRepository->save($story); | |
}); | |
} | |
} |