Commit de89156e authored by François Agneray's avatar François Agneray
Browse files

Add nb_datasets for project entity

parent a2da1b6c
Pipeline #4938 passed with stages
in 2 minutes and 57 seconds
...@@ -251,7 +251,7 @@ class Attribute implements \JsonSerializable ...@@ -251,7 +251,7 @@ class Attribute implements \JsonSerializable
* @var App\Entity\CriteriaFamily * @var App\Entity\CriteriaFamily
* *
* @ManyToOne(targetEntity="CriteriaFamily") * @ManyToOne(targetEntity="CriteriaFamily")
* @JoinColumn(name="criteria_family", referencedColumnName="id", nullable=true) * @JoinColumn(name="criteria_family", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/ */
protected $criteriaFamily; protected $criteriaFamily;
...@@ -259,7 +259,7 @@ class Attribute implements \JsonSerializable ...@@ -259,7 +259,7 @@ class Attribute implements \JsonSerializable
* @var App\Entity\OutputCategory * @var App\Entity\OutputCategory
* *
* @ManyToOne(targetEntity="OutputCategory") * @ManyToOne(targetEntity="OutputCategory")
* @JoinColumn(name="output_category", referencedColumnName="id", nullable=true) * @JoinColumn(name="output_category", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/ */
protected $outputCategory; protected $outputCategory;
......
...@@ -94,7 +94,7 @@ class Dataset implements \JsonSerializable ...@@ -94,7 +94,7 @@ class Dataset implements \JsonSerializable
/** /**
* @var Anis\Entity\Project * @var Anis\Entity\Project
* *
* @ManyToOne(targetEntity="Project") * @ManyToOne(targetEntity="Project", inversedBy="datasets")
* @JoinColumn(name="project_name", referencedColumnName="name", nullable=false) * @JoinColumn(name="project_name", referencedColumnName="name", nullable=false)
*/ */
protected $project; protected $project;
......
...@@ -62,9 +62,17 @@ class Project implements \JsonSerializable ...@@ -62,9 +62,17 @@ class Project implements \JsonSerializable
*/ */
protected $database; protected $database;
/**
* @var Anis\Entity\Dataset[]
*
* @OneToMany(targetEntity="Dataset", mappedBy="project")
*/
protected $datasets;
public function __construct(string $name) public function __construct(string $name)
{ {
$this->name = $name; $this->name = $name;
$this->datasets = new \Doctrine\Common\Collections\ArrayCollection();
} }
public function getName() public function getName()
...@@ -122,6 +130,11 @@ class Project implements \JsonSerializable ...@@ -122,6 +130,11 @@ class Project implements \JsonSerializable
return $this->database; return $this->database;
} }
public function getDatasets()
{
return $this->datasets;
}
public function jsonSerialize() public function jsonSerialize()
{ {
return [ return [
...@@ -130,7 +143,8 @@ class Project implements \JsonSerializable ...@@ -130,7 +143,8 @@ class Project implements \JsonSerializable
'description' => $this->getDescription(), 'description' => $this->getDescription(),
'link' => $this->getLink(), 'link' => $this->getLink(),
'manager' => $this->getManager(), 'manager' => $this->getManager(),
'id_database' => $this->getDatabase()->getId() 'id_database' => $this->getDatabase()->getId(),
'nb_datasets' => count($this->getDatasets())
]; ];
} }
} }
...@@ -85,7 +85,7 @@ final class ProjectActionTest extends TestCase ...@@ -85,7 +85,7 @@ final class ProjectActionTest extends TestCase
$request = $this->getRequest('PUT')->withParsedBody($fields); $request = $this->getRequest('PUT')->withParsedBody($fields);
$response = ($this->action)($request, new Response(), array('name' => 'anis_project')); $response = ($this->action)($request, new Response(), array('name' => 'anis_project'));
$this->assertSame( $this->assertSame(
json_encode(array_merge(['name' => 'anis_project'], $fields), JSON_UNESCAPED_SLASHES), json_encode(array_merge(['name' => 'anis_project'], $fields, ['nb_datasets' => 0]), JSON_UNESCAPED_SLASHES),
(string) $response->getBody() (string) $response->getBody()
); );
} }
......
...@@ -71,7 +71,7 @@ final class ProjectListActionTest extends TestCase ...@@ -71,7 +71,7 @@ final class ProjectListActionTest extends TestCase
public function testAddANewProject(): void public function testAddANewProject(): void
{ {
$this->addDatabase(); $this->addDatabase();
$fields = $this->getNewProjectFields(); $fields = array_merge($this->getNewProjectFields(), ['nb_datasets' => 0]);
$request = $this->getRequest('POST')->withParsedBody($fields); $request = $this->getRequest('POST')->withParsedBody($fields);
$response = ($this->action)($request, new Response(), array()); $response = ($this->action)($request, new Response(), array());
$this->assertSame( $this->assertSame(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment