Moved most of rest routes config to their actions

This commit is contained in:
Alejandro Celaya 2018-05-01 18:28:37 +02:00
parent c9ce56eea5
commit ef3c4aadf2
12 changed files with 42 additions and 62 deletions

View file

@ -7,12 +7,7 @@ use Shlinkio\Shlink\Rest\Action;
return [ return [
'routes' => [ 'routes' => [
[ Action\AuthenticateAction::getRouteDef(),
'name' => Action\AuthenticateAction::class,
'path' => '/authenticate',
'middleware' => Action\AuthenticateAction::class,
'allowed_methods' => [RequestMethod::METHOD_POST],
],
// Short codes // Short codes
[ [
@ -27,64 +22,19 @@ return [
// 'middleware' => Action\CreateShortcodeAction::class, // 'middleware' => Action\CreateShortcodeAction::class,
// 'allowed_methods' => [RequestMethod::METHOD_GET], // 'allowed_methods' => [RequestMethod::METHOD_GET],
// ], // ],
[ Action\EditShortCodeAction::getRouteDef(),
'name' => Action\EditShortCodeAction::class, Action\ResolveUrlAction::getRouteDef(),
'path' => '/short-codes/{shortCode}', Action\ListShortcodesAction::getRouteDef(),
'middleware' => Action\EditShortCodeAction::class, Action\EditShortcodeTagsAction::getRouteDef(),
'allowed_methods' => [RequestMethod::METHOD_PUT],
],
[
'name' => Action\ResolveUrlAction::class,
'path' => '/short-codes/{shortCode}',
'middleware' => Action\ResolveUrlAction::class,
'allowed_methods' => [RequestMethod::METHOD_GET],
],
[
'name' => Action\ListShortcodesAction::class,
'path' => '/short-codes',
'middleware' => Action\ListShortcodesAction::class,
'allowed_methods' => [RequestMethod::METHOD_GET],
],
[
'name' => Action\EditShortcodeTagsAction::class,
'path' => '/short-codes/{shortCode}/tags',
'middleware' => Action\EditShortcodeTagsAction::class,
'allowed_methods' => [RequestMethod::METHOD_PUT],
],
// Visits // Visits
[ Action\GetVisitsAction::getRouteDef(),
'name' => Action\GetVisitsAction::class,
'path' => '/short-codes/{shortCode}/visits',
'middleware' => Action\GetVisitsAction::class,
'allowed_methods' => [RequestMethod::METHOD_GET],
],
// Tags // Tags
[ Action\Tag\ListTagsAction::getRouteDef(),
'name' => Action\Tag\ListTagsAction::class, Action\Tag\DeleteTagsAction::getRouteDef(),
'path' => '/tags', Action\Tag\CreateTagsAction::getRouteDef(),
'middleware' => Action\Tag\ListTagsAction::class, Action\Tag\UpdateTagAction::getRouteDef(),
'allowed_methods' => [RequestMethod::METHOD_GET],
],
[
'name' => Action\Tag\DeleteTagsAction::class,
'path' => '/tags',
'middleware' => Action\Tag\DeleteTagsAction::class,
'allowed_methods' => [RequestMethod::METHOD_DELETE],
],
[
'name' => Action\Tag\CreateTagsAction::class,
'path' => '/tags',
'middleware' => Action\Tag\CreateTagsAction::class,
'allowed_methods' => [RequestMethod::METHOD_POST],
],
[
'name' => Action\Tag\UpdateTagAction::class,
'path' => '/tags',
'middleware' => Action\Tag\UpdateTagAction::class,
'allowed_methods' => [RequestMethod::METHOD_PUT],
],
], ],
]; ];

View file

@ -12,7 +12,7 @@ use Psr\Log\NullLogger;
abstract class AbstractRestAction implements RequestHandlerInterface, RequestMethodInterface, StatusCodeInterface abstract class AbstractRestAction implements RequestHandlerInterface, RequestMethodInterface, StatusCodeInterface
{ {
protected const ROUTE_PATH = ''; protected const ROUTE_PATH = '';
protected const ALLOWED_METHODS = []; protected const ROUTE_ALLOWED_METHODS = [];
/** /**
* @var LoggerInterface * @var LoggerInterface
@ -30,7 +30,7 @@ abstract class AbstractRestAction implements RequestHandlerInterface, RequestMet
'name' => static::class, 'name' => static::class,
'middleware' => \array_merge($prevMiddleware, [static::class], $postMiddleware), 'middleware' => \array_merge($prevMiddleware, [static::class], $postMiddleware),
'path' => static::ROUTE_PATH, 'path' => static::ROUTE_PATH,
'allowed_methods' => static::ALLOWED_METHODS, 'allowed_methods' => static::ROUTE_ALLOWED_METHODS,
]; ];
} }
} }

View file

@ -15,6 +15,9 @@ use Zend\I18n\Translator\TranslatorInterface;
class AuthenticateAction extends AbstractRestAction class AuthenticateAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/authenticate';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST];
/** /**
* @var TranslatorInterface * @var TranslatorInterface
*/ */

View file

@ -16,6 +16,9 @@ use Zend\I18n\Translator\TranslatorInterface;
class EditShortCodeAction extends AbstractRestAction class EditShortCodeAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/short-codes/{shortCode}';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT];
/** /**
* @var ShortUrlServiceInterface * @var ShortUrlServiceInterface
*/ */

View file

@ -14,6 +14,9 @@ use Zend\I18n\Translator\TranslatorInterface;
class EditShortcodeTagsAction extends AbstractRestAction class EditShortcodeTagsAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/short-codes/{shortCode}/tags';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT];
/** /**
* @var ShortUrlServiceInterface * @var ShortUrlServiceInterface
*/ */

View file

@ -15,6 +15,9 @@ use Zend\I18n\Translator\TranslatorInterface;
class GetVisitsAction extends AbstractRestAction class GetVisitsAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/short-codes/{shortCode}/visits';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
/** /**
* @var VisitsTrackerInterface * @var VisitsTrackerInterface
*/ */

View file

@ -16,6 +16,9 @@ class ListShortcodesAction extends AbstractRestAction
{ {
use PaginatorUtilsTrait; use PaginatorUtilsTrait;
protected const ROUTE_PATH = '/short-codes';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
/** /**
* @var ShortUrlServiceInterface * @var ShortUrlServiceInterface
*/ */

View file

@ -15,6 +15,9 @@ use Zend\I18n\Translator\TranslatorInterface;
class ResolveUrlAction extends AbstractRestAction class ResolveUrlAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/short-codes/{shortCode}';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
/** /**
* @var UrlShortenerInterface * @var UrlShortenerInterface
*/ */

View file

@ -12,6 +12,9 @@ use Zend\Diactoros\Response\JsonResponse;
class CreateTagsAction extends AbstractRestAction class CreateTagsAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/tags';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST];
/** /**
* @var TagServiceInterface * @var TagServiceInterface
*/ */

View file

@ -12,6 +12,9 @@ use Zend\Diactoros\Response\EmptyResponse;
class DeleteTagsAction extends AbstractRestAction class DeleteTagsAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/tags';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE];
/** /**
* @var TagServiceInterface * @var TagServiceInterface
*/ */

View file

@ -12,6 +12,9 @@ use Zend\Diactoros\Response\JsonResponse;
class ListTagsAction extends AbstractRestAction class ListTagsAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/tags';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
/** /**
* @var TagServiceInterface * @var TagServiceInterface
*/ */

View file

@ -16,6 +16,9 @@ use Zend\I18n\Translator\TranslatorInterface;
class UpdateTagAction extends AbstractRestAction class UpdateTagAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/tags';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT];
/** /**
* @var TagServiceInterface * @var TagServiceInterface
*/ */