Skip to content

Commit

Permalink
Release v1.0.2 (#13)
Browse files Browse the repository at this point in the history
* Update context aware repository definition

* Update context aware repository implementation

* Add additional validation to queue item entity transformer
  • Loading branch information
ristokekovic authored Jan 7, 2025
1 parent 16544cd commit 2f9d24d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
22 changes: 9 additions & 13 deletions src/ORM/Repositories/ContextAwareRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace SeQura\Middleware\ORM\Repositories;

use Illuminate\Database\Eloquent\Model;
use SeQura\Core\Infrastructure\ORM\Entity;
use SeQura\Core\Infrastructure\ORM\Exceptions\QueryFilterInvalidParamException;
use SeQura\Core\Infrastructure\ORM\QueryFilter\Operators;
use SeQura\Core\Infrastructure\ORM\QueryFilter\QueryFilter;
use SeQura\Middleware\ORM\Transformers\ContextAwareTransformer;
use SeQura\Middleware\ORM\Transformers\EloquentTransformer;
use SeQura\Middleware\ORM\Transformers\OrmEntityTransformer;

/**
* Class ContextAwareRepository
Expand All @@ -30,12 +28,11 @@ abstract class ContextAwareRepository extends BaseRepository
public function save(Entity $entity): int
{
$data = $this->getTransformer()->prepareDataForInsertOrUpdate($entity);
/** @var Model $eloquentModel */
$eloquentModel = $this->getTransformer()->newQuery()->create($data);
$entity->setId($eloquentModel->id);
$id = $this->getTransformer()->newQuery()->insertGetId($data);
$entity->setId($id);
$this->update($entity);

return $eloquentModel->id;
return $id;
}

/**
Expand All @@ -62,16 +59,15 @@ public function update(Entity $entity): bool
/**
* Gets EloquentTransformer instance.
*
* @return EloquentTransformer
* @return OrmEntityTransformer
*/
protected function getTransformer(): EloquentTransformer
protected function getTransformer(): OrmEntityTransformer
{
if ($this->transformer === null) {
$ormInstance = new $this->entityClass();
$this->transformer = new ContextAwareTransformer(
$this->getEloquentModelClassName(),
$ormInstance,
$this->getTableName()
$this->transformer = new OrmEntityTransformer(
$this->getTableName(),
$ormInstance
);
}

Expand Down
25 changes: 20 additions & 5 deletions src/ORM/Transformers/QueueItemEntityTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,26 @@ public function toOrmEntity(array $record): Entity
$item->setRetries(!empty($record['retries']) ? (int)$record['retries'] : 0);
$item->setFailureDescription($record['failure_description']);
$item->setCreateTimestamp($record['create_time']);
$item->setStartTimestamp(($record['start_time']));
$item->setEarliestStartTimestamp($record['earliest_start_time']);
$item->setQueueTimestamp($record['queue_time']);
$item->setLastUpdateTimestamp($record['last_update_time']);
$item->setFinishTimestamp($record['finish_time']);
if ($record['start_time'] !== null) {
$item->setStartTimestamp($record['start_time']);
}

if ($record['earliest_start_time'] !== null) {
$item->setEarliestStartTimestamp($record['earliest_start_time']);
}

if ($record['queue_time'] !== null) {
$item->setQueueTimestamp($record['queue_time']);
}

if ($record['last_update_time'] !== null) {
$item->setLastUpdateTimestamp($record['last_update_time']);
}

if ($record['finish_time'] !== null) {
$item->setFinishTimestamp($record['finish_time']);
}

$item->setPriority((int)$record['priority']);

return $item;
Expand Down

0 comments on commit 2f9d24d

Please sign in to comment.