Merge branch 'master' of https://forge.cadoles.com/wpetit/react-logo
This commit is contained in:
commit
dc741916c4
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Http\DataResponse;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Route("/api/v1/projects", name="api_v1_list_projects")
|
||||
*/
|
||||
public function listProjects()
|
||||
{
|
||||
/** @var array */
|
||||
$projects = $this->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,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,9 @@ class RequestController
|
|||
*/
|
||||
public function listRequests()
|
||||
{
|
||||
return new DataResponse([]);
|
||||
return new DataResponse([
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
class ProjectFixtures extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
|
||||
$dev1 = $manager
|
||||
->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,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
TRUSTED_HOSTS='^(localhost|127.0.0.1)$'
|
||||
DATABASE_URL=mysql://logo:logo@database:3306/logo?server_version=mariadb-10.4.12
|
||||
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
|
Loading…
Reference in New Issue