Skip to content

Commit 707a3de

Browse files
authored
Merge pull request #23 from AuroraWebSoftware/v2-dev2
V2 dev2
2 parents 0adb39d + e1e7cff commit 707a3de

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

src/Contracts/IssueOwnerModelContract.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace AuroraWebSoftware\AIssue\Contracts;
44

5+
use AuroraWebSoftware\AIssue\Models\AIssue;
56
use AuroraWebSoftware\Connective\Collections\ConnectiveCollection;
67
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
78
use Illuminate\Database\Query\Builder;
@@ -11,13 +12,17 @@
1112
*/
1213
interface IssueOwnerModelContract extends ConnectiveContract
1314
{
15+
public function ownIssue(AIssue $issue): void;
16+
17+
public function disownIssue(AIssue $issue): void;
18+
1419
/**
1520
* ConnectiveCollection<AIssue>
1621
*/
17-
public function getOwningIssues(): ConnectiveCollection;
22+
public function getOwningIssues(): ?ConnectiveCollection;
1823

1924
/**
2025
* ConnectiveCollection<AIssue>
2126
*/
22-
public function scopeAllOwningIssues(Builder $query): ConnectiveCollection;
27+
public function scopeAllOwningIssues(Builder $query): ?ConnectiveCollection;
2328
}

src/Models/AIssue.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use AuroraWebSoftware\ACalendar\Models\Event;
99
use AuroraWebSoftware\ACalendar\Traits\HasEvents;
1010
use AuroraWebSoftware\AIssue\Contracts\IssueActorModelContract;
11+
use AuroraWebSoftware\AIssue\Contracts\IssueOwnerModelContract;
1112
use AuroraWebSoftware\ArFlow\Contacts\StateableModelContract;
1213
use AuroraWebSoftware\ArFlow\Traits\HasState;
1314
use AuroraWebSoftware\Connective\Collections\ConnectiveCollection;
@@ -180,4 +181,23 @@ public function removeAllObservers(): void
180181
$observer->delete();
181182
}
182183
}
184+
185+
public function getOwnerModel(): IssueOwnerModelContract|Model|null
186+
{
187+
return $this->connectives('issue_owner_model')?->first();
188+
}
189+
190+
/**
191+
* @throws ConnectionTypeNotSupportedException
192+
* @throws ConnectionTypeException
193+
*/
194+
public function setOwnerModel(IssueActorModelContract&Model $issueOwnerModel): void
195+
{
196+
if ($this->connections('issue_owner_model')) {
197+
$this->connections('issue_owner_model')
198+
->each(fn (Model $connection) => $connection->delete());
199+
}
200+
201+
$this->connectTo($issueOwnerModel, 'issue_owner_model');
202+
}
183203
}

src/Traits/AIssueOwner.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,34 @@
33
namespace AuroraWebSoftware\AIssue\Traits;
44

55
use AuroraWebSoftware\AIssue\Contracts\IssueOwnerModelContract;
6+
use AuroraWebSoftware\AIssue\Models\AIssue;
67
use AuroraWebSoftware\Connective\Collections\ConnectiveCollection;
8+
use AuroraWebSoftware\Connective\Exceptions\ConnectionTypeException;
9+
use AuroraWebSoftware\Connective\Exceptions\ConnectionTypeNotSupportedException;
10+
use Illuminate\Database\Query\Builder;
711

812
trait AIssueOwner
913
{
14+
/**
15+
* @throws ConnectionTypeNotSupportedException
16+
* @throws ConnectionTypeException
17+
*/
18+
public function ownIssue(AIssue $issue): void
19+
{
20+
$issue->connectTo($this, 'issue_owner_model');
21+
}
22+
23+
public function disownIssue(AIssue $issue): void
24+
{
25+
// todo
26+
foreach ($this->getOwningIssues() ?? [] as $issueItem) {
27+
if ($issue->getId() === $issueItem->getId()) {
28+
$issue->connections('issue_owner_model')->delete();
29+
break;
30+
}
31+
}
32+
}
33+
1034
/**
1135
* ConnectiveCollection<AIssue>
1236
*/
@@ -18,4 +42,10 @@ public function getOwningIssues(): ConnectiveCollection
1842

1943
return $this->inverseConnectives('issue_owner_model');
2044
}
45+
46+
public function scopeAllOwningIssues(Builder $query): ?ConnectiveCollection
47+
{
48+
// todo will be implemented
49+
return ConnectiveCollection::make();
50+
}
2151
}

tests/Models/ExampleIssueOwner.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace AuroraWebSoftware\AIssue\Tests\Models;
4+
5+
use AuroraWebSoftware\AIssue\Contracts\IssueOwnerModelContract;
6+
use AuroraWebSoftware\AIssue\Traits\AIssueOwner;
7+
use AuroraWebSoftware\Connective\Traits\Connective;
8+
use Illuminate\Database\Eloquent\Model;
9+
10+
/**
11+
* @property string $name
12+
*
13+
* @method static ExampleIssueOwner create(array $attributes = [])
14+
*/
15+
class ExampleIssueOwner extends Model implements IssueOwnerModelContract
16+
{
17+
use AIssueOwner;
18+
use Connective;
19+
20+
protected $guarded = [];
21+
22+
public static function supportedConnectionTypes(): array
23+
{
24+
return [];
25+
}
26+
}

tests/Unit/AIssueTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use AuroraWebSoftware\AIssue\Models\AIssue;
4+
use AuroraWebSoftware\AIssue\Tests\Models\ExampleIssueOwner;
45
use AuroraWebSoftware\AIssue\Tests\Models\User;
56
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
67
use Illuminate\Database\Schema\Blueprint;
@@ -19,6 +20,12 @@
1920
$table->timestamps();
2021
});
2122

23+
Schema::create('example_issue_owners', function (Blueprint $table) {
24+
$table->id();
25+
$table->string('name');
26+
$table->timestamps();
27+
});
28+
2229
$classArflow = require __DIR__.'/../../vendor/aurorawebsoftware/arflow/database/migrations/create_arflow_history_table.php';
2330
(new $classArflow)->up();
2431

@@ -192,4 +199,10 @@
192199

193200
expect($issue->currentState())->toEqual('state2');
194201

202+
$exampleIssueOwner1 = ExampleIssueOwner::create(['name' => 'example issue owner 1']);
203+
$exampleIssueOwner1->ownIssue($issue);
204+
expect($exampleIssueOwner1->getOwningIssues())->toHaveCount(1);
205+
206+
// todo delete kısmı yazılmadı henüz
207+
195208
});

0 commit comments

Comments
 (0)