Skip to content

Commit f16aa32

Browse files
feat:[lar-140] Remove point after deleted article ,thread and discussion (#252)
1 parent 7f8d521 commit f16aa32

File tree

9 files changed

+149
-49
lines changed

9 files changed

+149
-49
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Actions\Discussion;
6+
7+
use App\Gamify\Points\DiscussionCreated;
8+
use App\Models\Discussion;
9+
use Illuminate\Support\Facades\DB;
10+
11+
final class DeleteDiscussionAction
12+
{
13+
public function execute(Discussion $discussion): void
14+
{
15+
DB::beginTransaction();
16+
17+
undoPoint(new DiscussionCreated($discussion));
18+
$discussion->delete();
19+
20+
DB::commit();
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Actions\Forum;
6+
7+
use App\Gamify\Points\ThreadCreated;
8+
use App\Models\Thread;
9+
use Illuminate\Support\Facades\DB;
10+
11+
final class DeleteThreadAction
12+
{
13+
public function execute(Thread $thread): void
14+
{
15+
DB::beginTransaction();
16+
17+
undoPoint(new ThreadCreated($thread));
18+
$thread->delete();
19+
20+
DB::commit();
21+
}
22+
}

app/Livewire/Pages/Discussions/SingleDiscussion.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Livewire\Pages\Discussions;
66

77
use App\Actions\Discussion\ConvertDiscussionToThreadAction;
8+
use App\Actions\Discussion\DeleteDiscussionAction;
89
use App\Models\Discussion;
910
use Filament\Actions\Action;
1011
use Filament\Actions\Concerns\InteractsWithActions;
@@ -80,7 +81,12 @@ public function deleteAction(): Action
8081
->authorize('delete', $this->discussion)
8182
->requiresConfirmation()
8283
->successNotificationTitle(__('notifications.discussion.deleted'))
83-
->successRedirectUrl(route('discussions.index'));
84+
->action(function (): void {
85+
86+
app(DeleteDiscussionAction::class)->execute($this->discussion);
87+
88+
$this->redirectRoute('discussions.index', navigate: true);
89+
});
8490
}
8591

8692
public function render(): View

app/Livewire/Pages/Forum/DetailThread.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Livewire\Pages\Forum;
66

7+
use App\Actions\Forum\DeleteThreadAction;
78
use App\Models\Thread;
89
use Filament\Actions\Action;
910
use Filament\Actions\Concerns\InteractsWithActions;
@@ -53,7 +54,8 @@ public function deleteAction(): Action
5354
->authorize('delete', $this->thread)
5455
->requiresConfirmation()
5556
->action(function (): void {
56-
$this->thread->delete();
57+
58+
app(DeleteThreadAction::class)->execute($this->thread);
5759

5860
$this->redirectRoute('forum.index', navigate: true);
5961
});

composer.lock

Lines changed: 44 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Feature/Livewire/Components/Slideovers/DiscussionFormTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
->assertSuccessful();
2323
});
2424

25-
it('user can create a new thread', function (): void {
25+
it('user can create a new discussion', function (): void {
2626
$user = $this->login();
2727
$tags = Tag::factory()->count(3)->create();
2828

@@ -36,10 +36,13 @@
3636
->assertHasNoFormErrors();
3737

3838
$discussion = Discussion::query()->first();
39+
$user->refresh();
3940

4041
expect($discussion?->user)->toBeInstanceOf(User::class)
4142
->and($discussion?->user->is($user))
42-
->toBeTrue();
43+
->toBeTrue()
44+
->and($user->getPoints())
45+
->toBe(20);
4346
});
4447

4548
it('validate forms input', function (): void {

tests/Feature/Livewire/Components/Slideovers/ThreadFormTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@
7575
->assertHasNoFormErrors();
7676

7777
$thread = Thread::query()->first();
78+
$user->refresh();
7879

7980
expect($thread?->user)->toBeInstanceOf(User::class)
8081
->and($thread?->user->is($user))
81-
->toBeTrue();
82+
->toBeTrue()
83+
->and($user->getPoints())
84+
->toBe(55);
8285
});
8386

8487
it('user cannot create thread with and unverified email address', function (): void {

0 commit comments

Comments
 (0)