This commit is contained in:
2023-10-04 13:32:30 +03:00
parent 215d238505
commit 1ca5f4e521
82 changed files with 519 additions and 1889 deletions
+8 -17
View File
@@ -5,18 +5,16 @@ namespace Lucent\Record;
use Carbon\Carbon;
use Lucent\Schema\Schema;
class System
readonly class System
{
function __construct(
public readonly string $schema,
public readonly int $version,
public readonly string $status,
public readonly string $createdBy,
public readonly string $updatedBy,
public readonly string $createdAt,
public readonly string $updatedAt,
public int $version,
public string $createdBy,
public string $updatedBy,
public string $createdAt,
public string $updatedAt,
)
{
@@ -26,9 +24,7 @@ class System
public static function fromArray(array $data): System
{
return new System(
schema: data_get($data, "schema"),
version: data_get($data, "version"),
status: data_get($data, "status"),
createdBy: data_get($data, "createdBy"),
updatedBy: data_get($data, "updatedBy"),
createdAt: data_get($data, "createdAt"),
@@ -37,13 +33,11 @@ class System
}
public static function newRecord(Schema $schema, string $userId, ?string $status = null): System
public static function newRecord(string $userId): System
{
$now = Carbon::now()->toJson();
return new System(
schema: $schema->name,
version: 1,
status: (new RecordStatus($status))->value(),
createdBy: $userId,
updatedBy: $userId,
createdAt: $now,
@@ -52,14 +46,11 @@ class System
}
public function update(string $userId, ?string $status = null): System
public function update(string $userId): System
{
$now = Carbon::now()->toJson();
$newStatus = $status ?? $this->status;
return new System(
schema: $this->schema,
version: $this->version + 1,
status: (new RecordStatus($newStatus))->value(),
createdBy: $this->createdBy,
updatedBy: $userId,
createdAt: $this->createdAt,