revisions complete
This commit is contained in:
+14
-41
@@ -3,6 +3,9 @@
|
||||
namespace Lucent\Revision;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Lucent\Edge\Edge;
|
||||
use Lucent\Edge\EdgeCollection;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Record\File;
|
||||
use Lucent\Record\Record;
|
||||
use Lucent\Record\RecordData;
|
||||
@@ -13,51 +16,20 @@ readonly class Revision
|
||||
{
|
||||
|
||||
function __construct(
|
||||
public string $id,
|
||||
public string $recordId,
|
||||
public string $schema,
|
||||
public System $_sys,
|
||||
public RecordData $data,
|
||||
public ?File $_file = null,
|
||||
public string $id,
|
||||
public string $recordId,
|
||||
public string $schema,
|
||||
public System $_sys,
|
||||
public RecordData $data,
|
||||
public EdgeCollection $_edges,
|
||||
public ?File $_file = null,
|
||||
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public static function fromDB(stdClass $data): Revision
|
||||
{
|
||||
|
||||
$file = json_decode($data->_file, true);
|
||||
if (!empty($file)) {
|
||||
|
||||
$file = new File(...$file);
|
||||
} else {
|
||||
$file = null;
|
||||
}
|
||||
|
||||
return new Revision(
|
||||
id: $data->id,
|
||||
recordId: $data->recordId,
|
||||
schema: $data->schema,
|
||||
_sys: System::fromArray(json_decode($data->_sys, true)),
|
||||
data: new RecordData(json_decode($data->data, true)),
|
||||
_file: $file,
|
||||
);
|
||||
}
|
||||
|
||||
public function toDB(): array
|
||||
{
|
||||
return [
|
||||
"id" => $this->id,
|
||||
"recordId" => $this->recordId,
|
||||
"schema" => $this->schema,
|
||||
"_sys" => json_encode($this->_sys),
|
||||
"_file" => json_encode($this->_file),
|
||||
"data" => json_encode($this->data),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function fromRecord(Record $record): Revision
|
||||
public static function fromRecord(Record $record, EdgeCollection $edges): Revision
|
||||
{
|
||||
return new Revision(
|
||||
id: (string)Str::uuid(),
|
||||
@@ -65,7 +37,8 @@ readonly class Revision
|
||||
schema: $record->schema,
|
||||
_sys: $record->_sys,
|
||||
data: $record->data,
|
||||
_file: $record->_file,
|
||||
_edges: $edges,
|
||||
_file: $record->_file
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user