plan schedules all nodes of text - impl of use case
This commit is contained in:
parent
0d00254e5f
commit
a606ceadaa
2 changed files with 23 additions and 3 deletions
|
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
namespace App\Plan\UseCases;
|
namespace App\Plan\UseCases;
|
||||||
|
|
||||||
|
use App\Node\NodeRepository;
|
||||||
use App\Plan\CreatePlanDto;
|
use App\Plan\CreatePlanDto;
|
||||||
use App\Plan\Plan;
|
use App\Plan\Plan;
|
||||||
use App\Plan\PlanRepository;
|
use App\Plan\PlanRepository;
|
||||||
|
use App\ScheduledNode\UseCases\CreateScheduledNode;
|
||||||
|
use App\ScheduledNode\UseCases\CreateScheduledNodeRequest;
|
||||||
|
use App\Text\TextRepository;
|
||||||
use App\User\UserRepository;
|
use App\User\UserRepository;
|
||||||
|
use DateTimeImmutable;
|
||||||
use DomainException;
|
use DomainException;
|
||||||
|
|
||||||
class CreatePlan
|
class CreatePlan
|
||||||
|
|
@ -13,6 +18,9 @@ class CreatePlan
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private PlanRepository $planRepo,
|
private PlanRepository $planRepo,
|
||||||
private UserRepository $userRepo,
|
private UserRepository $userRepo,
|
||||||
|
private TextRepository $textRepo,
|
||||||
|
private NodeRepository $nodeRepo,
|
||||||
|
private CreateScheduledNode $createScheduledNode,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,14 +30,25 @@ class CreatePlan
|
||||||
{
|
{
|
||||||
$userId = $request->userId;
|
$userId = $request->userId;
|
||||||
$user = $this->userRepo->find($userId);
|
$user = $this->userRepo->find($userId);
|
||||||
|
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
throw new DomainException("User with id: $userId doesnt exist");
|
throw new DomainException("User with id: $userId doesnt exist");
|
||||||
}
|
}
|
||||||
|
$textId = $request->textId;
|
||||||
return $this->planRepo->create(new CreatePlanDto(
|
$text = $this->textRepo->find($textId);
|
||||||
|
$nodesOfText = $this->nodeRepo->findByTextId($textId);
|
||||||
|
$plan = $this->planRepo->create(new CreatePlanDto(
|
||||||
name: $request->name,
|
name: $request->name,
|
||||||
user: $user,
|
user: $user,
|
||||||
));
|
));
|
||||||
|
foreach ($nodesOfText as $node) {
|
||||||
|
$this->createScheduledNode->execute(
|
||||||
|
new CreateScheduledNodeRequest(
|
||||||
|
date: new DateTimeImmutable(),
|
||||||
|
planId: $plan->getId(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $plan;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ class CreatePlanRequest
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public int $userId,
|
public int $userId,
|
||||||
|
public int $textId,
|
||||||
public string $name,
|
public string $name,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue