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

#41 => done

parent 44aed2d9
Pipeline #2156 passed with stages
in 6 minutes
......@@ -56,7 +56,7 @@ final class InstanceAction extends AbstractAction
$parsedBody = $request->getParsedBody();
// If mandatories empty fields 400
foreach (array('label', 'client_url') as $a) {
foreach (array('label') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
throw new HttpBadRequestException(
$request,
......@@ -89,7 +89,11 @@ final class InstanceAction extends AbstractAction
private function editInstance(Instance $instance, array $parsedBody): void
{
$instance->setLabel($parsedBody['label']);
$instance->setClientUrl($parsedBody['client_url']);
if (!$this->isEmptyField('client_url', $parsedBody)) {
$instance->setClientUrl($parsedBody['client_url']);
} else {
$instance->setClientUrl(null);
}
$this->em->flush();
}
}
......@@ -45,7 +45,7 @@ final class InstanceListAction extends AbstractAction
$parsedBody = $request->getParsedBody();
// To work this action needs user information to update
foreach (array('name', 'label', 'client_url') as $a) {
foreach (array('name', 'label') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
throw new HttpBadRequestException(
$request,
......@@ -71,7 +71,9 @@ final class InstanceListAction extends AbstractAction
private function postInstance(array $parsedBody): Instance
{
$instance = new Instance($parsedBody['name'], $parsedBody['label']);
$instance->setClientUrl($parsedBody['client_url']);
if (!$this->isEmptyField('client_url', $parsedBody)) {
$instance->setClientUrl($parsedBody['client_url']);
}
$this->em->persist($instance);
$this->em->flush();
......
......@@ -46,27 +46,27 @@ class Instance implements \JsonSerializable
$this->label = $label;
}
public function getName(): string
public function getName()
{
return $this->name;
}
public function getLabel(): string
public function getLabel()
{
return $this->label;
}
public function setLabel(string $label): void
public function setLabel(string $label)
{
$this->label = $label;
}
public function getClientUrl(): string
public function getClientUrl()
{
return $this->clientUrl;
}
public function setClientUrl($clientUrl): void
public function setClientUrl($clientUrl)
{
$this->clientUrl = $clientUrl;
}
......
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