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