add user to plan
This commit is contained in:
parent
9c2f95eda1
commit
547558d850
5 changed files with 18 additions and 0 deletions
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
namespace App\Plan;
|
||||
|
||||
use App\User\User;
|
||||
|
||||
class CreatePlanDto
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public User $user,
|
||||
) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
namespace App\Plan;
|
||||
|
||||
use App\User\User;
|
||||
|
||||
class Plan
|
||||
{
|
||||
public function __construct(
|
||||
private int $id,
|
||||
private string $name,
|
||||
private User $user,
|
||||
) {}
|
||||
|
||||
public function getId(): int
|
||||
|
|
@ -18,4 +21,9 @@ class Plan
|
|||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,17 +5,22 @@ namespace App\Plan\UseCases;
|
|||
use App\Plan\CreatePlanDto;
|
||||
use App\Plan\Plan;
|
||||
use App\Plan\PlanRepository;
|
||||
use App\User\UserRepository;
|
||||
|
||||
class CreatePlan
|
||||
{
|
||||
public function __construct(
|
||||
private PlanRepository $planRepo,
|
||||
private UserRepository $userRepo,
|
||||
) {}
|
||||
|
||||
public function execute(CreatePlanRequest $request): Plan
|
||||
{
|
||||
$user = $this->userRepo->find($request->userId);
|
||||
|
||||
return $this->planRepo->create(new CreatePlanDto(
|
||||
name: $request->name,
|
||||
user: $user,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Plan\UseCases;
|
|||
class CreatePlanRequest
|
||||
{
|
||||
public function __construct(
|
||||
public int $userId,
|
||||
public string $name,
|
||||
) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue