* changed routes while debuging endpoints
* added corsmiddlewarefactory * changing teams is now possible
This commit is contained in:
parent
1143075e17
commit
117c10a56a
@ -21,6 +21,7 @@ return [
|
|||||||
// Use 'factories' for services provided by callbacks/factory classes.
|
// Use 'factories' for services provided by callbacks/factory classes.
|
||||||
'factories' => [
|
'factories' => [
|
||||||
// Fully\Qualified\ClassName::class => Fully\Qualified\FactoryName::class,
|
// Fully\Qualified\ClassName::class => Fully\Qualified\FactoryName::class,
|
||||||
|
Tuupola\Middleware\CorsMiddleware::class => DoctrineExpressiveModule\Middleware\CorsMiddlewareFactory::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@ -36,6 +36,11 @@ return function (Application $app, MiddlewareFactory $factory, ContainerInterfac
|
|||||||
$app->get('/', App\Handler\HomePageHandler::class, 'home');
|
$app->get('/', App\Handler\HomePageHandler::class, 'home');
|
||||||
$app->get('/api/ping', App\Handler\PingHandler::class, 'api.ping');
|
$app->get('/api/ping', App\Handler\PingHandler::class, 'api.ping');
|
||||||
|
|
||||||
$app->route('/api/team[/{id:\d+}]', App\Handler\TeamHandler::class)->setName('api.team');
|
$app->get('/api/team', App\Handler\TeamHandler::class,'api.team.list');
|
||||||
|
$app->get('/api/team/{id:\d+}', App\Handler\TeamHandler::class,'api.team.get');
|
||||||
|
$app->post('/api/team', App\Handler\TeamHandler::class,'api.team.add');
|
||||||
|
$app->put('/api/team[/{id:\d+}]', App\Handler\TeamHandler::class,'api.team.change');
|
||||||
|
$app->delete('/api/team/{id:\d+}', App\Handler\TeamHandler::class,'api.team.delete');
|
||||||
|
|
||||||
$app->route('/api/slide[/{id:\d+}]', App\Handler\SlideHandler::class)->setName('api.slide');
|
$app->route('/api/slide[/{id:\d+}]', App\Handler\SlideHandler::class)->setName('api.slide');
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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
|
* @param ServerRequestInterface $request
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
|||||||
@ -63,7 +63,8 @@ class TeamService
|
|||||||
$this->em->persist($entity);
|
$this->em->persist($entity);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
return $entity;
|
return $entity;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
$messages = $this->form->getMessages();
|
$messages = $this->form->getMessages();
|
||||||
$fields = array_keys($messages);
|
$fields = array_keys($messages);
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
@ -71,7 +72,6 @@ class TeamService
|
|||||||
implode(", ", $fields)
|
implode(", ", $fields)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
@ -93,7 +93,13 @@ class TeamService
|
|||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
return true;
|
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"],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user