Skip to content

Commit 3bb44fc

Browse files
authored
Merge pull request #27 from AuroraWebSoftware/v2-dev2
- remove fix
2 parents 03c3215 + ece901e commit 3bb44fc

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

src/Contracts/IssueActorModelContract.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use AuroraWebSoftware\Connective\Collections\ConnectiveCollection;
66
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
7+
use Illuminate\Database\Eloquent\Collection;
8+
use Illuminate\Database\Eloquent\Model;
79

810
/**
911
* issue actor can be one of the following:
@@ -26,4 +28,9 @@ public function getActingIssues(string $connectionType): ConnectiveCollection;
2628
* ['channel' => 'email', 'email' => '[email protected]']
2729
*/
2830
public function getIssueReminderConfig(): array;
31+
32+
/**
33+
* @return Collection<int, Model&IssueActorModelContract>
34+
*/
35+
public static function searchIssueActor(string $searchTerm): Collection;
2936
}

src/Models/AIssue.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
1616
use AuroraWebSoftware\Connective\Exceptions\ConnectionTypeException;
1717
use AuroraWebSoftware\Connective\Exceptions\ConnectionTypeNotSupportedException;
18+
use AuroraWebSoftware\Connective\Models\Connection;
1819
use AuroraWebSoftware\Connective\Traits\Connective;
1920
use Illuminate\Database\Eloquent\Model;
2021
use Illuminate\Support\Carbon;
@@ -167,18 +168,25 @@ public function addObserver(IssueActorModelContract&Model $issueActorModel): voi
167168

168169
public function removeObserver(IssueActorModelContract $issueActorModel): void
169170
{
170-
foreach ($this->getObservers() ?? [] as $observer) {
171-
if ($observer->getId() === $issueActorModel->getId()) {
172-
$observer->delete();
173-
break;
174-
}
171+
if ($this->connections('issue_observer')) {
172+
$this->connections('issue_observer')
173+
->each(function (Model $connection) use ($issueActorModel) {
174+
175+
/**
176+
* @var Connection $connection
177+
*/
178+
if ($connection->connectedTo()->getId() === $issueActorModel->getId()) {
179+
$connection->delete();
180+
}
181+
});
175182
}
176183
}
177184

178185
public function removeAllObservers(): void
179186
{
180-
foreach ($this->getObservers() ?? [] as $observer) {
181-
$observer->delete();
187+
if ($this->connections('issue_observer')) {
188+
$this->connections('issue_observer')
189+
->each(fn (Model $connection) => $connection->delete());
182190
}
183191
}
184192

tests/Models/User.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use AuroraWebSoftware\AIssue\Traits\AIssueActor;
77
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
88
use AuroraWebSoftware\Connective\Traits\Connective;
9+
use Illuminate\Database\Eloquent\Collection;
910
use Illuminate\Database\Eloquent\Model;
1011

1112
/**
@@ -32,4 +33,14 @@ public function getIssueReminderConfig(): array
3233
{
3334
return ['channel' => 'email', 'email' => '[email protected]'];
3435
}
36+
37+
/**
38+
* @return Collection<IssueActorModelContract>
39+
*
40+
* @phpstan-ignore-next-line
41+
*/
42+
public static function searchIssueActor(string $searchTerm): Collection
43+
{
44+
return User::query()->where('name', 'like', '%'.$searchTerm.'%')->get();
45+
}
3546
}

tests/Unit/AIssueTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,20 @@
203203
$exampleIssueOwner1->ownIssue($issue);
204204
expect($exampleIssueOwner1->getOwningIssues())->toHaveCount(1);
205205

206+
// dd(User::searchIssueActor('user'));
207+
208+
// search actor
209+
expect(User::searchIssueActor('user'))
210+
->toHaveCount(4)
211+
->and(User::searchIssueActor('user 1'))
212+
->toHaveCount(1)
213+
->and(User::searchIssueActor('user 2'))
214+
->toHaveCount(1)
215+
->and(User::searchIssueActor('user 3'))
216+
->toHaveCount(1)
217+
->and(User::searchIssueActor('user 4'))
218+
->toHaveCount(1);
219+
206220
// todo delete kısmı yazılmadı henüz
207221

208222
});

0 commit comments

Comments
 (0)