* changed routes while debuging endpoints
* added corsmiddlewarefactory * changing teams is now possible
This commit is contained in:
@@ -60,6 +60,29 @@ class TeamHandler extends AbstractCrudHandler
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return JsonResponse
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
public function update(ServerRequestInterface $request)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
try {
|
||||
return new JsonResponse($this->teamService->changeTeam((int)$id, $data));
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
return new JsonResponse([
|
||||
'message' => 'The field `name` must be unique',
|
||||
], 500);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return JsonResponse
|
||||
|
||||
@@ -63,14 +63,14 @@ class TeamService
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
return $entity;
|
||||
} else {
|
||||
$messages = $this->form->getMessages();
|
||||
$fields = array_keys($messages);
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
"The following fields are invalid: (%s)",
|
||||
implode(", ", $fields)
|
||||
));
|
||||
}
|
||||
|
||||
$messages = $this->form->getMessages();
|
||||
$fields = array_keys($messages);
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
"The following fields are invalid: (%s)",
|
||||
implode(", ", $fields)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,13 @@ class TeamService
|
||||
$this->em->flush();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
$messages = $this->form->getMessages();
|
||||
$fields = array_keys($messages);
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
"The following fields are invalid: (%s)",
|
||||
implode(", ", $fields)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineExpressiveModule\Middleware;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Tuupola\Middleware\CorsMiddleware;
|
||||
|
||||
class CorsMiddlewareFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container) : CorsMiddleware
|
||||
{
|
||||
return new CorsMiddleware([
|
||||
"headers.allow" => ["Authorization", "If-Match", "If-Unmodified-Since", "Content-type"],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user