mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Added Create and Delete tag actions
This commit is contained in:
@@ -20,6 +20,8 @@ return [
|
||||
Action\ListShortcodesAction::class => AnnotatedFactory::class,
|
||||
Action\EditShortcodeTagsAction::class => AnnotatedFactory::class,
|
||||
Action\Tag\ListTagsAction::class => AnnotatedFactory::class,
|
||||
Action\Tag\DeleteTagsAction::class => AnnotatedFactory::class,
|
||||
Action\Tag\CreateTagsAction::class => AnnotatedFactory::class,
|
||||
|
||||
Middleware\BodyParserMiddleware::class => AnnotatedFactory::class,
|
||||
Middleware\CrossDomainMiddleware::class => InvokableFactory::class,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use Shlinkio\Shlink\Rest\Action;
|
||||
use Fig\Http\Message\RequestMethodInterface as RequestMethod;
|
||||
|
||||
return [
|
||||
|
||||
@@ -8,7 +9,7 @@ return [
|
||||
'name' => Action\AuthenticateAction::class,
|
||||
'path' => '/rest/v{version:1}/authenticate',
|
||||
'middleware' => Action\AuthenticateAction::class,
|
||||
'allowed_methods' => ['POST'],
|
||||
'allowed_methods' => [RequestMethod::METHOD_POST],
|
||||
],
|
||||
|
||||
// Short codes
|
||||
@@ -16,25 +17,25 @@ return [
|
||||
'name' => Action\CreateShortcodeAction::class,
|
||||
'path' => '/rest/v{version:1}/short-codes',
|
||||
'middleware' => Action\CreateShortcodeAction::class,
|
||||
'allowed_methods' => ['POST'],
|
||||
'allowed_methods' => [RequestMethod::METHOD_POST],
|
||||
],
|
||||
[
|
||||
'name' => Action\ResolveUrlAction::class,
|
||||
'path' => '/rest/v{version:1}/short-codes/{shortCode}',
|
||||
'middleware' => Action\ResolveUrlAction::class,
|
||||
'allowed_methods' => ['GET'],
|
||||
'allowed_methods' => [RequestMethod::METHOD_GET],
|
||||
],
|
||||
[
|
||||
'name' => Action\ListShortcodesAction::class,
|
||||
'path' => '/rest/v{version:1}/short-codes',
|
||||
'middleware' => Action\ListShortcodesAction::class,
|
||||
'allowed_methods' => ['GET'],
|
||||
'allowed_methods' => [RequestMethod::METHOD_GET],
|
||||
],
|
||||
[
|
||||
'name' => Action\EditShortcodeTagsAction::class,
|
||||
'path' => '/rest/v{version:1}/short-codes/{shortCode}/tags',
|
||||
'middleware' => Action\EditShortcodeTagsAction::class,
|
||||
'allowed_methods' => ['PUT'],
|
||||
'allowed_methods' => [RequestMethod::METHOD_PUT],
|
||||
],
|
||||
|
||||
// Visits
|
||||
@@ -42,15 +43,27 @@ return [
|
||||
'name' => Action\GetVisitsAction::class,
|
||||
'path' => '/rest/v{version:1}/short-codes/{shortCode}/visits',
|
||||
'middleware' => Action\GetVisitsAction::class,
|
||||
'allowed_methods' => ['GET'],
|
||||
'allowed_methods' => [RequestMethod::METHOD_GET],
|
||||
],
|
||||
|
||||
// Tags
|
||||
[
|
||||
'name' => Action\ListTagsAction::class,
|
||||
'name' => Action\Tag\ListTagsAction::class,
|
||||
'path' => '/rest/v{version:1}/tags',
|
||||
'middleware' => Action\ListTagsAction::class,
|
||||
'allowed_methods' => ['GET'],
|
||||
'middleware' => Action\Tag\ListTagsAction::class,
|
||||
'allowed_methods' => [RequestMethod::METHOD_GET],
|
||||
],
|
||||
[
|
||||
'name' => Action\Tag\DeleteTagsAction::class,
|
||||
'path' => '/rest/v{version:1}/tags',
|
||||
'middleware' => Action\Tag\DeleteTagsAction::class,
|
||||
'allowed_methods' => [RequestMethod::METHOD_DELETE],
|
||||
],
|
||||
[
|
||||
'name' => Action\Tag\CreateTagsAction::class,
|
||||
'path' => '/rest/v{version:1}/tags',
|
||||
'middleware' => Action\Tag\CreateTagsAction::class,
|
||||
'allowed_methods' => [RequestMethod::METHOD_POST],
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
57
module/Rest/src/Action/Tag/CreateTagsAction.php
Normal file
57
module/Rest/src/Action/Tag/CreateTagsAction.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Action\Tag;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation as DI;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Core\Service\Tag\TagService;
|
||||
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class CreateTagsAction extends AbstractRestAction
|
||||
{
|
||||
/**
|
||||
* @var TagServiceInterface
|
||||
*/
|
||||
private $tagService;
|
||||
|
||||
/**
|
||||
* CreateTagsAction constructor.
|
||||
* @param TagServiceInterface $tagService
|
||||
* @param LoggerInterface|null $logger
|
||||
*
|
||||
* @DI\Inject({TagService::class, LoggerInterface::class})
|
||||
*/
|
||||
public function __construct(TagServiceInterface $tagService, LoggerInterface $logger = null)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
$this->tagService = $tagService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an incoming server request and return a response, optionally delegating
|
||||
* to the next middleware component to create the response.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$tags = isset($body['tags']) ? $body['tags'] : [];
|
||||
|
||||
return new JsonResponse([
|
||||
'tags' => [
|
||||
'data' => $this->tagService->createTags($tags)->toArray(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
53
module/Rest/src/Action/Tag/DeleteTagsAction.php
Normal file
53
module/Rest/src/Action/Tag/DeleteTagsAction.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Action\Tag;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation as DI;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Core\Service\Tag\TagService;
|
||||
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class DeleteTagsAction extends AbstractRestAction
|
||||
{
|
||||
/**
|
||||
* @var TagServiceInterface
|
||||
*/
|
||||
private $tagService;
|
||||
|
||||
/**
|
||||
* DeleteTagsAction constructor.
|
||||
* @param TagServiceInterface $tagService
|
||||
* @param LoggerInterface|null $logger
|
||||
*
|
||||
* @DI\Inject({TagService::class, LoggerInterface::class})
|
||||
*/
|
||||
public function __construct(TagServiceInterface $tagService, LoggerInterface $logger = null)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
$this->tagService = $tagService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an incoming server request and return a response, optionally delegating
|
||||
* to the next middleware component to create the response.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$query = $request->getQueryParams();
|
||||
$tags = isset($query['tags']) ? $query['tags'] : [];
|
||||
|
||||
$this->tagService->deleteTags($tags);
|
||||
return new EmptyResponse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user