Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

Commit

Permalink
Merge branch 'bugfix/archive-post'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Schmidmeister committed Jan 11, 2017
2 parents fa5811c + 6b4030b commit 073dab8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
15 changes: 9 additions & 6 deletions API/src/Commands/Posts/ArchivePostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
*/
namespace Timetabio\API\Commands\Posts
{
use Timetabio\API\DataStore\DataStoreWriter;
use Timetabio\API\Services\PostService;
use Timetabio\Framework\Backends\ElasticBackend;
use Timetabio\Framework\ValueObjects\StringDateTime;

class ArchivePostCommand
{
Expand All @@ -20,21 +21,23 @@ class ArchivePostCommand
private $postService;

/**
* @var DataStoreWriter
* @var ElasticBackend
*/
private $dataStoreWriter;
private $elasticBackend;

public function __construct(PostService $postService, DataStoreWriter $dataStoreWriter)
public function __construct(PostService $postService, ElasticBackend $elasticBackend)
{
$this->postService = $postService;
$this->dataStoreWriter = $dataStoreWriter;
$this->elasticBackend = $elasticBackend;
}

public function execute(string $postId): string
{
$archived = $this->postService->archivePost($postId);

$this->dataStoreWriter->queueTask(new \Timetabio\Library\Tasks\IndexPostTask($postId));
$this->elasticBackend->updateDocument('post', $postId, [
'archived' => (new StringDateTime($archived))->getTimestamp()
]);

return $archived;
}
Expand Down
15 changes: 9 additions & 6 deletions API/src/Commands/Posts/RestorePostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
namespace Timetabio\API\Commands\Posts
{
use Timetabio\API\DataStore\DataStoreWriter;
use Timetabio\API\Services\PostService;
use Timetabio\Framework\Backends\ElasticBackend;

class RestorePostCommand
{
Expand All @@ -20,20 +20,23 @@ class RestorePostCommand
private $postService;

/**
* @var DataStoreWriter
* @var ElasticBackend
*/
private $dataStoreWriter;
private $elasticBackend;

public function __construct(PostService $postService, DataStoreWriter $dataStoreWriter)
public function __construct(PostService $postService, ElasticBackend $elasticBackend)
{
$this->postService = $postService;
$this->dataStoreWriter = $dataStoreWriter;
$this->elasticBackend = $elasticBackend;
}

public function execute(string $postId): void
{
$this->postService->restorePost($postId);
$this->dataStoreWriter->queueTask(new \Timetabio\Library\Tasks\IndexPostTask($postId));

$this->elasticBackend->updateDocument('post', $postId, [
'archived' => null
]);
}
}
}
4 changes: 2 additions & 2 deletions API/src/Factories/CommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ public function createArchivePostCommand(): \Timetabio\API\Commands\Posts\Archiv
{
return new \Timetabio\API\Commands\Posts\ArchivePostCommand(
$this->getMasterFactory()->createPostService(),
$this->getMasterFactory()->createDataStoreWriter()
$this->getMasterFactory()->createElasticBackend()
);
}

public function createRestorePostCommand(): \Timetabio\API\Commands\Posts\RestorePostCommand
{
return new \Timetabio\API\Commands\Posts\RestorePostCommand(
$this->getMasterFactory()->createPostService(),
$this->getMasterFactory()->createDataStoreWriter()
$this->getMasterFactory()->createElasticBackend()
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions Framework/src/Backends/ElasticBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public function indexChildDocument(string $type, string $id, string $parent, arr
]);
}

public function updateDocument(string $type, string $id, array $updates): array
{
return $this->client->update([
'index' => $this->index,
'type' => $type,
'id' => $id,
'body' => [
'doc' => $updates
]
]);
}

public function deleteDocument(string $type, string $id): array
{
return $this->client->delete([
Expand Down

0 comments on commit 073dab8

Please sign in to comment.