add user to plan

This commit is contained in:
Yisroel Baum 2026-02-23 10:58:37 +02:00
parent 9c2f95eda1
commit 547558d850
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 18 additions and 0 deletions

View file

@ -2,9 +2,12 @@
namespace App\Plan; namespace App\Plan;
use App\User\User;
class CreatePlanDto class CreatePlanDto
{ {
public function __construct( public function __construct(
public string $name, public string $name,
public User $user,
) {} ) {}
} }

View file

@ -2,11 +2,14 @@
namespace App\Plan; namespace App\Plan;
use App\User\User;
class Plan class Plan
{ {
public function __construct( public function __construct(
private int $id, private int $id,
private string $name, private string $name,
private User $user,
) {} ) {}
public function getId(): int public function getId(): int
@ -18,4 +21,9 @@ class Plan
{ {
return $this->name; return $this->name;
} }
public function getUser(): User
{
return $this->user;
}
} }

View file

@ -5,17 +5,22 @@ namespace App\Plan\UseCases;
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\User\UserRepository;
class CreatePlan class CreatePlan
{ {
public function __construct( public function __construct(
private PlanRepository $planRepo, private PlanRepository $planRepo,
private UserRepository $userRepo,
) {} ) {}
public function execute(CreatePlanRequest $request): Plan public function execute(CreatePlanRequest $request): Plan
{ {
$user = $this->userRepo->find($request->userId);
return $this->planRepo->create(new CreatePlanDto( return $this->planRepo->create(new CreatePlanDto(
name: $request->name, name: $request->name,
user: $user,
)); ));
} }
} }

View file

@ -5,6 +5,7 @@ namespace App\Plan\UseCases;
class CreatePlanRequest class CreatePlanRequest
{ {
public function __construct( public function __construct(
public int $userId,
public string $name, public string $name,
) {} ) {}
} }

View file

@ -16,6 +16,7 @@ class FakePlanRepository implements PlanRepository
$plan = new Plan( $plan = new Plan(
id: $id, id: $id,
name: $dto->name, name: $dto->name,
user: $dto->user,
); );
$this->existingPlans[$id] = $plan; $this->existingPlans[$id] = $plan;