refactor: use new interface design

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-17 19:12:04 -04:00
parent 2bdd05b4c2
commit 118c527944
3 changed files with 24 additions and 79 deletions
+11 -20
View File
@@ -14,6 +14,7 @@ use KTXF\Chrono\Collection\CollectionBaseInterface;
use KTXF\Chrono\Collection\CollectionPropertiesBaseInterface;
use KTXF\Chrono\Entity\EntityBaseInterface;
use KTXF\Chrono\Entity\EntityPropertiesMutableInterface;
use KTXF\Chrono\Entity\EntityType;
use KTXF\Chrono\Service\ServiceBaseInterface;
use KTXF\Chrono\Service\ServiceCollectionMutableInterface;
use KTXF\Chrono\Service\ServiceEntityMutableInterface;
@@ -406,8 +407,10 @@ class PersonalService implements ServiceBaseInterface, ServiceCollectionMutableI
}
}
public function entityFresh(): EntityResource {
return new EntityResource();
public function entityFresh(EntityType $type = EntityType::Event): EntityResource {
$entity = new EntityResource();
$entity->setProperties($type->instantiate());
return $entity;
}
public function entityCreate(CollectionIdentifierInterface $target, EntityPropertiesMutableInterface $properties, array $options = []): EntityBaseInterface {
@@ -416,15 +419,9 @@ class PersonalService implements ServiceBaseInterface, ServiceCollectionMutableI
if ($this->collectionAccessible($collection) === false) {
throw new InvalidParameterException("Invalid: Collection identifier '$collection' does not exist or does not belong to user '{$this->serviceUserId}'");
}
// convert entity to a native type if needed
if (!($properties instanceof EntityResource)) {
$nativeEntity = $this->entityFresh();
$nativeEntity->jsonDeserialize([
EntityResource::PROPERTY_PROPERTIES => $properties->jsonSerialize(),
]);
} else {
$nativeEntity = clone $properties;
}
// wrap the typed entity object in a native resource
$nativeEntity = $this->entityFresh();
$nativeEntity->setProperties($properties);
// create entity in store (store will handle userId and collection)
$result = $this->store->entityCreate($this->serviceTenantId, $this->serviceUserId, $collection, $nativeEntity);
return $result;
@@ -442,15 +439,9 @@ class PersonalService implements ServiceBaseInterface, ServiceCollectionMutableI
if (!isset($extant[$identifier]) || $extant[$identifier] === false) {
throw new InvalidParameterException("Invalid: Entity identifier '$identifier' does not exist or does not belong to collection '$collection' or user '{$this->serviceUserId}'");
}
// convert entity to a native type if needed
if (!($properties instanceof EntityResource)) {
$nativeEntity = $this->entityFresh();
$nativeEntity->jsonDeserialize([
EntityResource::PROPERTY_PROPERTIES => $properties->jsonSerialize(),
]);
} else {
$nativeEntity = clone $properties;
}
// wrap the typed entity object in a native resource
$nativeEntity = $this->entityFresh();
$nativeEntity->setProperties($properties);
// modify entity in store
$result = $this->store->entityModify($this->serviceTenantId, $this->serviceUserId, $collection, $identifier, $nativeEntity);
return $result;