47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?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,
|
|
]);
|
|
}
|
|
|
|
} |