Skip to content

Commit

Permalink
Refactor ModelObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
pellaras committed Sep 26, 2018
1 parent 2269286 commit 4c5b11b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/ModelObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ public function __construct(DynamoDbClientInterface $dynamoDb)
$this->attributeFilter = $dynamoDb->getAttributeFilter();
}

protected function _save($model)
private function saveToDynamoDb($model)
{
$attrs = $model->attributesToArray();
// $this->attributeFilter->filter($attrs);

try {
$this->dynamoDbClient->putItem([
'TableName' => $model->getDynamoDbTableName(),
'Item' => $this->marshaler->marshalItem($attrs),
]);
} catch (Exception $e) {
Log::info($e);
Log::error($e);
}
}

protected function _delete($model)
private function deleteFromDynamoDb($model)
{
$key = [$model->getKeyName() => $model->getKey()];

Expand All @@ -56,27 +56,27 @@ protected function _delete($model)
'Key' => $this->marshaler->marshalItem($key),
]);
} catch (Exception $e) {
Log::info($e);
Log::error($e);
}
}

public function created($model)
{
$this->_save($model);
$this->saveToDynamoDb($model);
}

public function updated($model)
{
$this->_save($model);
$this->saveToDynamoDb($model);
}

public function deleted($model)
{
$this->_delete($model);
$this->deleteFromDynamoDb($model);
}

public function restored($model)
{
$this->_save($model);
$this->saveToDynamoDb($model);
}
}

0 comments on commit 4c5b11b

Please sign in to comment.