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
* @var App\Entity\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;
......@@ -259,7 +259,7 @@ class Attribute implements \JsonSerializable
* @var App\Entity\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;
......
......@@ -94,7 +94,7 @@ class Dataset implements \JsonSerializable
/**
* @var Anis\Entity\Project
*
* @ManyToOne(targetEntity="Project")
* @ManyToOne(targetEntity="Project", inversedBy="datasets")
* @JoinColumn(name="project_name", referencedColumnName="name", nullable=false)
*/
protected $project;
......
......@@ -62,9 +62,17 @@ class Project implements \JsonSerializable
*/
protected $database;
/**
* @var Anis\Entity\Dataset[]
*
* @OneToMany(targetEntity="Dataset", mappedBy="project")
*/
protected $datasets;
public function __construct(string $name)
{
$this->name = $name;
$this->datasets = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getName()
......@@ -122,6 +130,11 @@ class Project implements \JsonSerializable
return $this->database;
}
public function getDatasets()
{
return $this->datasets;
}
public function jsonSerialize()
{
return [
......@@ -130,7 +143,8 @@ class Project implements \JsonSerializable
'description' => $this->getDescription(),
'link' => $this->getLink(),
'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
$request = $this->getRequest('PUT')->withParsedBody($fields);
$response = ($this->action)($request, new Response(), array('name' => 'anis_project'));
$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()
);
}
......
......@@ -71,7 +71,7 @@ final class ProjectListActionTest extends TestCase
public function testAddANewProject(): void
{
$this->addDatabase();
$fields = $this->getNewProjectFields();
$fields = array_merge($this->getNewProjectFields(), ['nb_datasets' => 0]);
$request = $this->getRequest('POST')->withParsedBody($fields);
$response = ($this->action)($request, new Response(), array());
$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