From a2f887b1962e3e86b0537b0bf97749526598d5fe Mon Sep 17 00:00:00 2001 From: Jeremy Postlethwaite Date: Sat, 27 Apr 2024 11:00:05 -0700 Subject: [PATCH] GH-19 --- database/factories/NoteFactory.php | 4 +- ...01_02_100001_create_matrix_notes_table.php | 55 ++---- src/Models/Note.php | 176 ++++++++++-------- tests/Feature/Models/Note/ModelTest.php | 35 +++- tests/Unit/Models/Note/ModelTest.php | 11 +- 5 files changed, 159 insertions(+), 122 deletions(-) diff --git a/database/factories/NoteFactory.php b/database/factories/NoteFactory.php index bdbb297..35737d0 100644 --- a/database/factories/NoteFactory.php +++ b/database/factories/NoteFactory.php @@ -1,9 +1,9 @@ uuid('id')->primary(); @@ -30,6 +34,7 @@ public function up(): void $table->uuid('parent_id')->nullable()->index(); $table->string('note_type')->nullable()->index(); $table->uuid('matrix_id')->nullable()->index(); + $table->uuid('tag_id')->nullable()->index(); // Dates @@ -37,21 +42,6 @@ public function up(): void $table->softDeletes(); - $table->dateTime('start_at')->nullable()->index(); - $table->dateTime('planned_start_at')->nullable(); - $table->dateTime('end_at')->nullable()->index(); - $table->dateTime('planned_end_at')->nullable(); - $table->dateTime('canceled_at')->nullable(); - $table->dateTime('closed_at')->nullable()->index(); - $table->dateTime('embargo_at')->nullable(); - $table->dateTime('fixed_at')->nullable(); - $table->dateTime('postponed_at')->nullable(); - $table->dateTime('published_at')->nullable(); - $table->dateTime('released_at')->nullable(); - $table->dateTime('resumed_at')->nullable(); - $table->dateTime('resolved_at')->nullable()->index(); - $table->dateTime('suspended_at')->nullable(); - // Permissions $table->bigInteger('gids')->default(0)->unsigned(); @@ -75,13 +65,13 @@ public function up(): void $table->bigInteger('x')->nullable(); $table->bigInteger('y')->nullable(); $table->bigInteger('z')->nullable(); - $table->decimal('r', 65, 10)->nullable()->default(null); - $table->decimal('theta', 10, 6)->nullable()->default(null); - $table->decimal('rho', 10, 6)->nullable()->default(null); - $table->decimal('phi', 10, 6)->nullable()->default(null); - $table->decimal('elevation', 65, 10)->nullable()->default(null); - $table->decimal('latitude', 8, 6)->nullable()->default(null); - $table->decimal('longitude', 9, 6)->nullable()->default(null); + $table->decimal('r', 65, 10)->nullable(); + $table->decimal('theta', 10, 6)->nullable(); + $table->decimal('rho', 10, 6)->nullable(); + $table->decimal('phi', 10, 6)->nullable(); + $table->decimal('elevation', 65, 10)->nullable(); + $table->decimal('latitude', 8, 6)->nullable(); + $table->decimal('longitude', 9, 6)->nullable(); // Flags @@ -89,34 +79,27 @@ public function up(): void $table->boolean('canceled')->default(0); $table->boolean('closed')->default(0); $table->boolean('completed')->default(0); - $table->boolean('duplicate')->default(0); - $table->boolean('fixed')->default(0); $table->boolean('flagged')->default(0); $table->boolean('internal')->default(0); $table->boolean('locked')->default(0); $table->boolean('pending')->default(0); $table->boolean('planned')->default(0); $table->boolean('problem')->default(0); - $table->boolean('published')->default(0); - $table->boolean('released')->default(0); - $table->boolean('retired')->default(0); - $table->boolean('resolved')->default(0); - $table->boolean('suspended')->default(0); $table->boolean('unknown')->default(0); - // Strings + // Columns $table->string('label')->default(''); $table->string('title')->default(''); $table->string('byline')->default(''); - $table->string('slug')->nullable()->default(null)->index(); + $table->string('slug')->nullable()->index(); $table->string('url')->default(''); $table->string('description')->default(''); $table->string('introduction')->default(''); $table->mediumText('content')->nullable(); $table->mediumText('summary')->nullable(); - // UI + // Ui $table->string('icon')->default(''); $table->string('image')->default(''); @@ -126,13 +109,9 @@ public function up(): void // JSON $table->json('assets')->nullable()->default(new Expression('(JSON_OBJECT())')); - $table->json('backlog')->nullable()->default(new Expression('(JSON_OBJECT())')); - $table->json('board')->nullable()->default(new Expression('(JSON_OBJECT())')); - $table->json('flow')->nullable()->default(new Expression('(JSON_OBJECT())')); $table->json('meta')->nullable()->default(new Expression('(JSON_OBJECT())')); $table->json('notes')->nullable()->default(new Expression('(JSON_ARRAY())'))->comment('Array of note objects'); $table->json('options')->nullable()->default(new Expression('(JSON_OBJECT())')); - $table->json('roadmap')->nullable()->default(new Expression('(JSON_OBJECT())')); $table->json('sources')->nullable()->default(new Expression('(JSON_OBJECT())')); }); } diff --git a/src/Models/Note.php b/src/Models/Note.php index 75a801d..66d5d67 100644 --- a/src/Models/Note.php +++ b/src/Models/Note.php @@ -1,15 +1,79 @@ null, 'parent_id' => null, 'note_type' => null, + 'matrix_id' => null, + 'tag_id' => null, 'created_at' => null, 'updated_at' => null, 'deleted_at' => null, - 'start_at' => null, - 'planned_start_at' => null, - 'end_at' => null, - 'planned_end_at' => null, - 'canceled_at' => null, - 'closed_at' => null, - 'embargo_at' => null, - 'fixed_at' => null, - 'postponed_at' => null, - 'published_at' => null, - 'released_at' => null, - 'resolved_at' => null, - 'resumed_at' => null, - 'suspended_at' => null, 'gids' => 0, 'po' => 0, 'pg' => 0, @@ -54,7 +106,7 @@ class Note extends Model 'status' => 0, 'rank' => 0, 'size' => 0, - 'matrix' => '', + 'matrix' => '{}', 'x' => null, 'y' => null, 'z' => null, @@ -69,19 +121,12 @@ class Note extends Model 'canceled' => false, 'closed' => false, 'completed' => false, - 'duplicate' => false, - 'fixed' => false, 'flagged' => false, 'internal' => false, 'locked' => false, 'pending' => false, 'planned' => false, 'problem' => false, - 'published' => false, - 'released' => false, - 'retired' => false, - 'resolved' => false, - 'suspended' => false, 'unknown' => false, 'label' => '', 'title' => '', @@ -97,13 +142,9 @@ class Note extends Model 'avatar' => '', 'ui' => '{}', 'assets' => '{}', - 'backlog' => '{}', - 'board' => '{}', - 'flow' => '{}', 'meta' => '{}', 'notes' => '[]', 'options' => '{}', - 'roadmap' => '{}', 'sources' => '{}', ]; @@ -116,20 +157,8 @@ class Note extends Model 'owned_by_id', 'parent_id', 'note_type', - 'start_at', - 'planned_start_at', - 'end_at', - 'planned_end_at', - 'canceled_at', - 'closed_at', - 'embargo_at', - 'fixed_at', - 'postponed_at', - 'published_at', - 'released_at', - 'resumed_at', - 'resolved_at', - 'suspended_at', + 'matrix_id', + 'tag_id', 'gids', 'po', 'pg', @@ -156,19 +185,12 @@ class Note extends Model 'canceled', 'closed', 'completed', - 'duplicate', - 'fixed', 'flagged', 'internal', 'locked', 'pending', 'planned', 'problem', - 'published', - 'released', - 'retired', - 'resolved', - 'suspended', 'unknown', 'label', 'title', @@ -184,13 +206,8 @@ class Note extends Model 'avatar', 'ui', 'assets', - 'backlog', - 'board', - 'flow', 'meta', - 'notes', 'options', - 'roadmap', 'sources', ]; @@ -206,20 +223,6 @@ protected function casts(): array 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', - 'start_at' => 'datetime', - 'planned_start_at' => 'datetime', - 'end_at' => 'datetime', - 'planned_end_at' => 'datetime', - 'canceled_at' => 'datetime', - 'closed_at' => 'datetime', - 'embargo_at' => 'datetime', - 'fixed_at' => 'datetime', - 'postponed_at' => 'datetime', - 'published_at' => 'datetime', - 'released_at' => 'datetime', - 'resumed_at' => 'datetime', - 'resolved_at' => 'datetime', - 'suspended_at' => 'datetime', 'gids' => 'integer', 'po' => 'integer', 'pg' => 'integer', @@ -231,7 +234,7 @@ protected function casts(): array 'status' => 'integer', 'rank' => 'integer', 'size' => 'integer', - 'matrix' => 'string', + 'matrix' => 'array', 'x' => 'integer', 'y' => 'integer', 'z' => 'integer', @@ -246,19 +249,12 @@ protected function casts(): array 'canceled' => 'boolean', 'closed' => 'boolean', 'completed' => 'boolean', - 'duplicate' => 'boolean', - 'fixed' => 'boolean', 'flagged' => 'boolean', 'internal' => 'boolean', 'locked' => 'boolean', 'pending' => 'boolean', 'planned' => 'boolean', 'problem' => 'boolean', - 'published' => 'boolean', - 'released' => 'boolean', - 'retired' => 'boolean', - 'resolved' => 'boolean', - 'suspended' => 'boolean', 'unknown' => 'boolean', 'label' => 'string', 'title' => 'string', @@ -274,14 +270,34 @@ protected function casts(): array 'avatar' => 'string', 'ui' => 'array', 'assets' => 'array', - 'backlog' => 'array', - 'board' => 'array', - 'flow' => 'array', 'meta' => 'array', 'notes' => 'array', 'options' => 'array', - 'roadmap' => 'array', 'sources' => 'array', ]; } + + /** + * The matrix of the note. + */ + public function matrix(): HasOne + { + return $this->hasOne( + Matrix::class, + 'id', + 'matrix_id' + ); + } + + /** + * The tag of the note. + */ + public function tag(): HasOne + { + return $this->hasOne( + Tag::class, + 'id', + 'tag_id' + ); + } } diff --git a/tests/Feature/Models/Note/ModelTest.php b/tests/Feature/Models/Note/ModelTest.php index 43cbd92..264cfde 100644 --- a/tests/Feature/Models/Note/ModelTest.php +++ b/tests/Feature/Models/Note/ModelTest.php @@ -15,5 +15,38 @@ class ModelTest extends ModelCase { protected string $modelClass = \Playground\Matrix\Models\Note::class; - protected bool $hasRelationships = false; + protected bool $hasRelationships = true; + + protected array $hasOne = [ + 'creator' => [ + 'key' => 'created_by_id', + 'rule' => 'create', + 'modelClass' => \Playground\Models\User::class, + ], + 'modifier' => [ + 'key' => 'modified_by_id', + 'rule' => 'create', + 'modelClass' => \Playground\Models\User::class, + ], + 'owner' => [ + 'key' => 'owned_by_id', + 'rule' => 'create', + 'modelClass' => \Playground\Models\User::class, + ], + 'parent' => [ + 'key' => 'parent_id', + 'rule' => 'create', + 'modelClass' => \Playground\Matrix\Models\Note::class, + ], + 'matrix' => [ + 'key' => 'matrix_id', + 'rule' => 'create', + 'modelClass' => \Playground\Matrix\Models\Matrix::class, + ], + 'tag' => [ + 'key' => 'tag_id', + 'rule' => 'create', + 'modelClass' => \Playground\Matrix\Models\Tag::class, + ], + ]; } diff --git a/tests/Unit/Models/Note/ModelTest.php b/tests/Unit/Models/Note/ModelTest.php index 087352a..04ddf97 100644 --- a/tests/Unit/Models/Note/ModelTest.php +++ b/tests/Unit/Models/Note/ModelTest.php @@ -15,5 +15,14 @@ class ModelTest extends ModelCase { protected string $modelClass = \Playground\Matrix\Models\Note::class; - protected bool $hasRelationships = false; + protected bool $hasRelationships = true; + + protected array $hasOne = [ + 'creator', + 'modifier', + 'owner', + 'parent', + 'matrix', + 'tag', + ]; }