diff --git a/backend/src/Controller/ProjectController.php b/backend/src/Controller/ProjectController.php new file mode 100644 index 0000000..8dcf325 --- /dev/null +++ b/backend/src/Controller/ProjectController.php @@ -0,0 +1,47 @@ +getDoctrine() + ->getRepository(Project::class) + ->findAll() + ; + + $results = []; + foreach($projects as $p) { + $project = [ + 'id' => $p->getId(), + 'name' => $p->getName(), + ]; + + $project['users'] = $p->getUsers()->map(function($user) { + return ['id' => $user->getId(), 'username' => $user->getUsername()]; + })->toArray(); + + $project['requests'] = $p->getRequests()->map(function($req) { + return ['id' => $req->getId()]; + })->toArray(); + + + $results[] = $project; + } + + return new DataResponse([ + 'projects' => $results, + ]); + } + +} \ No newline at end of file diff --git a/backend/src/Controller/RequestController.php b/backend/src/Controller/RequestController.php index 23f3c5e..a800465 100644 --- a/backend/src/Controller/RequestController.php +++ b/backend/src/Controller/RequestController.php @@ -12,7 +12,9 @@ class RequestController */ public function listRequests() { - return new DataResponse([]); + return new DataResponse([ + + ]); } } \ No newline at end of file diff --git a/backend/src/DataFixtures/ProjectFixtures.php b/backend/src/DataFixtures/ProjectFixtures.php new file mode 100644 index 0000000..2ce92ad --- /dev/null +++ b/backend/src/DataFixtures/ProjectFixtures.php @@ -0,0 +1,39 @@ +getRepository(User::class) + ->findOneByUsername('dev1') + ; + + $project1 = new Project(); + $project1->setName("Test"); + $project1->addUser($dev1); + $manager->persist($project1); + + $manager->flush(); + + } + + public function getDependencies() + { + return [ + UserFixtures::class, + ]; + } + + +} diff --git a/backend/src/Entity/Project.php b/backend/src/Entity/Project.php index 725c7b2..16e1e30 100644 --- a/backend/src/Entity/Project.php +++ b/backend/src/Entity/Project.php @@ -19,12 +19,12 @@ class Project private $id; /** - * @ORM\OneToMany(targetEntity="App\Entity\Request", mappedBy="project", orphanRemoval=true) + * @ORM\OneToMany(targetEntity="App\Entity\Request", mappedBy="project", orphanRemoval=true, fetch="LAZY") */ - private $request; + private $requests; /** - * @ORM\ManyToMany(targetEntity="App\Entity\User", inversedBy="projects") + * @ORM\ManyToMany(targetEntity="App\Entity\User", inversedBy="projects", fetch="LAZY") */ private $users; @@ -35,7 +35,7 @@ class Project public function __construct() { - $this->request = new ArrayCollection(); + $this->requests = new ArrayCollection(); $this->users = new ArrayCollection(); } @@ -47,15 +47,15 @@ class Project /** * @return Collection|Request[] */ - public function getRequest(): Collection + public function getRequests(): Collection { - return $this->request; + return $this->requests; } public function addRequest(Request $request): self { - if (!$this->request->contains($request)) { - $this->request[] = $request; + if (!$this->requests->contains($request)) { + $this->requests[] = $request; $request->setProject($this); } @@ -64,8 +64,8 @@ class Project public function removeRequest(Request $request): self { - if ($this->request->contains($request)) { - $this->request->removeElement($request); + if ($this->requests->contains($request)) { + $this->requests->removeElement($request); // set the owning side to null (unless already changed) if ($request->getProject() === $this) { $request->setProject(null);