Skip to content

Commit

Permalink
Added api_format parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cassani committed Jul 12, 2017
1 parent 924e5a4 commit 39a1219
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
10 changes: 5 additions & 5 deletions Controller/EventStoreManagerBundleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use JMS\Serializer\SerializerBuilder;
use SimpleEventStoreManager\Application\EventQuery;
use SimpleEventStoreManager\Bundle\Service\Manager;
use SimpleEventStoreManager\Infrastructure\DataTransformers\JsonEventDataTransformer;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -25,20 +24,21 @@ class EventStoreManagerBundleController extends Controller
*/
public function indexAction(Request $request, $page = null)
{
$currentPage = ($page) ?: 1;

/** @var Manager $manager */
$manager = $this->container->get('simple_event_store_manager');
$eventStore = $manager->getMananger()->eventStore();

$config = $this->container->getParameter('simple_event_store_manager');
$dataTransformer = 'SimpleEventStoreManager\\Infrastructure\\DataTransformers\\'.ucfirst($config['api_format']).'EventDataTransformer';
$eventsQuery = new EventQuery(
$eventStore,
new JsonEventDataTransformer(
new $dataTransformer(
SerializerBuilder::create()->build(),
$request,
true
)
);

return $eventsQuery->paginate($currentPage);
return $eventsQuery->paginate(($page) ?: 1);
}
}
37 changes: 24 additions & 13 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,35 @@ public function getConfigTreeBuilder()
$rootNode = $treeBuilder->root('simple_event_store_manager');
$rootNode
->children()
->enumNode('driver')
->values([
'in-memory',
'mongo',
'pdo',
'redis',
])
->defaultValue('mongo')
->isRequired()
->end()
->enumNode('driver')
->values([
'in-memory',
'mongo',
'pdo',
'redis',
])
->defaultValue('mongo')
->isRequired()
->end()
->end()
->children()
->arrayNode('parameters')
->isRequired()
->prototype('variable')
->enumNode('api_format')
->values([
'json',
'xml',
'yaml',
])
->defaultValue('json')
->end()
->end()
->children()
->arrayNode('parameters')
->isRequired()
->prototype('variable')
->end()
->end()
;

return $treeBuilder;
}
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Here is an example:
# Simple EventStore Manager
simple_event_store_manager:
driver: 'mongo'
api_format: 'yaml'
parameters:
host: 'localhost'
username: ~
Expand All @@ -26,6 +27,8 @@ simple_event_store_manager:
port: '27017'
```

`api_format` is an optional parameter; you can choose between `json`, `xml` or `yaml`.

Please refer to [Simple EventStore Manager page](https://github.com/mauretto78/simple-event-store-manager) for more details.

#### Step 3: Setup your AppKernel.php by adding the Simple EventStore Manager Bundle
Expand Down Expand Up @@ -70,7 +73,7 @@ Please refer to [official documentation of Simple EventStore Manager](https://gi

## API support ##

An API endpoint is automatically exposed to `/_events/{page}` path; it will automatically paginated with **25 records per page**.
An API endpoint is automatically exposed to `/_events/{page}` path; it will automatically with **25 records per page**.

When a page is complete, it will set automatically an infinite cache on it.

Expand Down

0 comments on commit 39a1219

Please sign in to comment.