Skip to content

Commit

Permalink
Merge 52e4beb into a3dde25
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Jun 24, 2017
2 parents a3dde25 + 52e4beb commit 9b28317
Show file tree
Hide file tree
Showing 19 changed files with 523 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config/autoload/dependencies.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
// app
GenericEventFactory::class => InvokableFactory::class,
// actions
Action\Delete::class => Container\Action\DeleteFactory::class,
Action\DeleteStream::class => Container\Action\DeleteStreamFactory::class,
Action\FetchStreamMetadata::class => Container\Action\FetchStreamMetadataFactory::class,
Action\HasStream::class => Container\Action\HasStreamFactory::class,
Action\Load::class => Container\Action\LoadFactory::class,
Expand Down
15 changes: 12 additions & 3 deletions config/autoload/event_store.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@ declare(strict_types=1);
namespace Prooph\EventStore\Http\Api;

use Prooph\EventStore\EventStore;
use Prooph\EventStore\Pdo\Container\MariaDbProjectionManagerFactory;
use Prooph\EventStore\Pdo\Container\MariaDbEventStoreFactory;
use Prooph\EventStore\Pdo\Container\MySqlProjectionManagerFactory;
use Prooph\EventStore\Pdo\Container\MySqlEventStoreFactory;
use Prooph\EventStore\Pdo\Container\PostgresEventStoreFactory;
use Prooph\EventStore\Pdo\Container\PdoConnectionFactory;
use Prooph\EventStore\Pdo\Container\PostgresEventStoreFactory;
use Prooph\EventStore\Pdo\Container\PostgresProjectionManagerFactory;
use Prooph\EventStore\Pdo\PersistenceStrategy\MariaDbAggregateStreamStrategy;
use Prooph\EventStore\Pdo\PersistenceStrategy\MariaDbSingleStreamStrategy;
use Prooph\EventStore\Pdo\PersistenceStrategy\MySqlAggregateStreamStrategy;
use Prooph\EventStore\Pdo\PersistenceStrategy\MySqlSingleStreamStrategy;
use Prooph\EventStore\Pdo\PersistenceStrategy\PostgresAggregateStreamStrategy;
use Prooph\EventStore\Pdo\PersistenceStrategy\PostgresSingleStreamStrategy;
use Prooph\EventStore\Projection\ProjectionManager;

return [
'dependencies' => [
'factories' => [
// choose one !!!
//EventStore::class => MariaDbEventStoreFactory::class,
//EventStore::class => MySqlEventStoreFactory::class,
//EventStore::class => PostgresEventStoreFactory::class,
//Uncomment for both pdo event stores
//'pdo.connection' => PdoConnectionFactory::class,
'pdo_connection' => PdoConnectionFactory::class,
],
],
'prooph' => [
Expand All @@ -37,6 +44,8 @@ return [
'connection' => 'pdo_connection'
'message_factory' => GenericEventFactory::class,
// choose one !!!
//'persistence_strategy' => MariaDbAggregateStreamStrategy::class,
//'persistence_strategy' => MariaDbSingleStreamStrategy::class,
//'persistence_strategy' => MySqlAggregateStreamStrategy::class,
//'persistence_strategy' => MySqlSingleStreamStrategy::class,
//'persistence_strategy' => PostgresAggregateStreamStrategy::class,
Expand Down
20 changes: 19 additions & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

$app->get(
'/delete/{streamname}',
Action\Delete::class,
Action\DeleteStream::class,
'page::delete-stream'
);

Expand All @@ -66,3 +66,21 @@
Action\HasStream::class,
'page::has-stream'
);

$app->get(
'projection/delete/{name}/deleteEmittedEvents:true|false',
Action\DeleteProjection::class,
'page::delete-projection'
);

$app->get(
'projection/reset/{name}',
Action\DeleteProjection::class,
'page::reset-projection'
);

$app->get(
'projection/stop/{name}',
Action\DeleteProjection::class,
'page::stop-projection'
);
51 changes: 51 additions & 0 deletions src/Action/DeleteProjection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* This file is part of the prooph/event-store-http-api.
* (c) 2016-2017 prooph software GmbH <contact@prooph.de>
* (c) 2016-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Http\Api\Action;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Prooph\EventStore\Projection\ProjectionManager;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\EmptyResponse;

final class DeleteProjection implements MiddlewareInterface
{
/**
* @var ProjectionManager
*/
private $projectionManager;

public function __construct(ProjectionManager $projectionManager)
{
$this->projectionManager = $projectionManager;
}

public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$projectionName = urldecode($request->getAttribute('name'));
$deleteEmittedEvents = $request->getAttribute('deleteEmittedEvents');

switch ($deleteEmittedEvents) {
case 'false':
$deleteEmittedEvents = false;
break;
case 'true':
$deleteEmittedEvents = true;
break;
}

$this->projectionManager->deleteProjection($projectionName, $deleteEmittedEvents);

return new EmptyResponse(204);
}
}
2 changes: 1 addition & 1 deletion src/Action/Delete.php → src/Action/DeleteStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\EmptyResponse;

final class Delete implements MiddlewareInterface
final class DeleteStream implements MiddlewareInterface
{
/**
* @var EventStore
Expand Down
41 changes: 41 additions & 0 deletions src/Action/ResetProjection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* This file is part of the prooph/event-store-http-api.
* (c) 2016-2017 prooph software GmbH <contact@prooph.de>
* (c) 2016-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Http\Api\Action;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Prooph\EventStore\Projection\ProjectionManager;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\EmptyResponse;

final class ResetProjection implements MiddlewareInterface
{
/**
* @var ProjectionManager
*/
private $projectionManager;

public function __construct(ProjectionManager $projectionManager)
{
$this->projectionManager = $projectionManager;
}

public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$projectionName = urldecode($request->getAttribute('name'));

$this->projectionManager->resetProjection($projectionName);

return new EmptyResponse(204);
}
}
41 changes: 41 additions & 0 deletions src/Action/StopProjection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* This file is part of the prooph/event-store-http-api.
* (c) 2016-2017 prooph software GmbH <contact@prooph.de>
* (c) 2016-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Http\Api\Action;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Prooph\EventStore\Projection\ProjectionManager;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\EmptyResponse;

final class StopProjection implements MiddlewareInterface
{
/**
* @var ProjectionManager
*/
private $projectionManager;

public function __construct(ProjectionManager $projectionManager)
{
$this->projectionManager = $projectionManager;
}

public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$projectionName = urldecode($request->getAttribute('name'));

$this->projectionManager->stopProjection($projectionName);

return new EmptyResponse(204);
}
}
25 changes: 25 additions & 0 deletions src/Container/Action/DeleteProjectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* This file is part of the prooph/event-store-http-api.
* (c) 2016-2017 prooph software GmbH <contact@prooph.de>
* (c) 2016-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Http\Api\Container\Action;

use Prooph\EventStore\Http\Api\Action\DeleteProjection;
use Prooph\EventStore\Projection\ProjectionManager;
use Psr\Container\ContainerInterface;

final class DeleteProjectionFactory
{
public function __invoke(ContainerInterface $container): DeleteProjection
{
return new DeleteProjection($container->get(ProjectionManager::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
namespace Prooph\EventStore\Http\Api\Container\Action;

use Prooph\EventStore\EventStore;
use Prooph\EventStore\Http\Api\Action\Delete;
use Prooph\EventStore\Http\Api\Action\DeleteStream;
use Psr\Container\ContainerInterface;

final class DeleteFactory
final class DeleteStreamFactory
{
public function __invoke(ContainerInterface $container): Delete
public function __invoke(ContainerInterface $container): DeleteStream
{
return new Delete($container->get(EventStore::class));
return new DeleteStream($container->get(EventStore::class));
}
}
25 changes: 25 additions & 0 deletions src/Container/Action/ResetProjectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* This file is part of the prooph/event-store-http-api.
* (c) 2016-2017 prooph software GmbH <contact@prooph.de>
* (c) 2016-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Http\Api\Container\Action;

use Prooph\EventStore\Http\Api\Action\ResetProjection;
use Prooph\EventStore\Projection\ProjectionManager;
use Psr\Container\ContainerInterface;

final class ResetProjectionFactory
{
public function __invoke(ContainerInterface $container): ResetProjection
{
return new ResetProjection($container->get(ProjectionManager::class));
}
}
25 changes: 25 additions & 0 deletions src/Container/Action/StopProjectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* This file is part of the prooph/event-store-http-api.
* (c) 2016-2017 prooph software GmbH <contact@prooph.de>
* (c) 2016-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\EventStore\Http\Api\Container\Action;

use Prooph\EventStore\Http\Api\Action\StopProjection;
use Prooph\EventStore\Projection\ProjectionManager;
use Psr\Container\ContainerInterface;

final class StopProjectionFactory
{
public function __invoke(ContainerInterface $container): StopProjection
{
return new StopProjection($container->get(ProjectionManager::class));
}
}
67 changes: 67 additions & 0 deletions tests/Action/DeleteProjectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of the prooph/event-store-http-api.
* (c) 2016-2017 prooph software GmbH <contact@prooph.de>
* (c) 2016-2017 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ProophTest\EventStore\Http\Api\Action;

use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prooph\EventStore\Http\Api\Action\DeleteProjection;
use Prooph\EventStore\Projection\ProjectionManager;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\EmptyResponse;

class DeleteProjectionTest extends TestCase
{
/**
* @test
*/
public function it_will_delete_projection_incl_emitted_events(): void
{
$projectionManager = $this->prophesize(ProjectionManager::class);
$projectionManager->deleteProjection('runner', true)->shouldBeCalled();

$request = $this->prophesize(ServerRequestInterface::class);
$request->getAttribute('name')->willReturn('runner')->shouldBeCalled();
$request->getAttribute('deleteEmittedEvents')->willReturn('true')->shouldBeCalled();

$delegate = $this->prophesize(DelegateInterface::class);

$action = new DeleteProjection($projectionManager->reveal());

$response = $action->process($request->reveal(), $delegate->reveal());

$this->assertInstanceOf(EmptyResponse::class, $response);
$this->assertEquals(204, $response->getStatusCode());
}

/**
* @test
*/
public function it_will_delete_projection_without_emitted_events(): void
{
$projectionManager = $this->prophesize(ProjectionManager::class);
$projectionManager->deleteProjection('runner', false)->shouldBeCalled();

$request = $this->prophesize(ServerRequestInterface::class);
$request->getAttribute('name')->willReturn('runner')->shouldBeCalled();
$request->getAttribute('deleteEmittedEvents')->willReturn('false')->shouldBeCalled();

$delegate = $this->prophesize(DelegateInterface::class);

$action = new DeleteProjection($projectionManager->reveal());

$response = $action->process($request->reveal(), $delegate->reveal());

$this->assertInstanceOf(EmptyResponse::class, $response);
$this->assertEquals(204, $response->getStatusCode());
}
}

0 comments on commit 9b28317

Please sign in to comment.