add find by user method in plan repo

This commit is contained in:
Yisroel Baum 2026-05-01 09:02:34 +03:00
parent ec4dca87a6
commit 07e34ffd46
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 55 additions and 0 deletions

View file

@ -90,4 +90,29 @@ class JsonPlanRepository implements PlanRepository
return $maxId + 1;
}
public function findByUser(User $user): array
{
$plans = array_filter(
$this->readPlans(),
function ($data) use ($user) {
return $data['userId'] === $user->getId();
}
);
return array_map(
function ($data) {
$user = $this->userRepository->find($data['userId']);
if ($user === null) {
return null;
}
return new Plan(
id: $data['id'],
name: $data['name'],
user: $user,
);
},
$plans
);
}
}

View file

@ -2,8 +2,14 @@
namespace App\Plan;
use App\User\User;
interface PlanRepository
{
public function create(CreatePlanDto $dto): Plan;
public function find(int $id): ?Plan;
/**
* @return Plan[]
*/
public function findByUser(User $user): array;
}