Skip to content

feat:[lar-140] Remove point after deleted article ,thread and discussion #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/Actions/Discussion/DeleteDiscussionAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Actions\Discussion;

use App\Gamify\Points\DiscussionCreated;
use App\Models\Discussion;
use Illuminate\Support\Facades\DB;

final class DeleteDiscussionAction
{
public function execute(Discussion $discussion): void
{
DB::beginTransaction();

undoPoint(new DiscussionCreated($discussion));
$discussion->delete();

DB::commit();
}
}
22 changes: 22 additions & 0 deletions app/Actions/Forum/DeleteThreadAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Actions\Forum;

use App\Gamify\Points\ThreadCreated;
use App\Models\Thread;
use Illuminate\Support\Facades\DB;

final class DeleteThreadAction
{
public function execute(Thread $thread): void
{
DB::beginTransaction();

undoPoint(new ThreadCreated($thread));
$thread->delete();

DB::commit();
}
}
8 changes: 7 additions & 1 deletion app/Livewire/Pages/Discussions/SingleDiscussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Livewire\Pages\Discussions;

use App\Actions\Discussion\ConvertDiscussionToThreadAction;
use App\Actions\Discussion\DeleteDiscussionAction;
use App\Models\Discussion;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
Expand Down Expand Up @@ -80,7 +81,12 @@ public function deleteAction(): Action
->authorize('delete', $this->discussion)
->requiresConfirmation()
->successNotificationTitle(__('notifications.discussion.deleted'))
->successRedirectUrl(route('discussions.index'));
->action(function (): void {

app(DeleteDiscussionAction::class)->execute($this->discussion);

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

public function render(): View
Expand Down
4 changes: 3 additions & 1 deletion app/Livewire/Pages/Forum/DetailThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Livewire\Pages\Forum;

use App\Actions\Forum\DeleteThreadAction;
use App\Models\Thread;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
Expand Down Expand Up @@ -53,7 +54,8 @@ public function deleteAction(): Action
->authorize('delete', $this->thread)
->requiresConfirmation()
->action(function (): void {
$this->thread->delete();

app(DeleteThreadAction::class)->execute($this->thread);

$this->redirectRoute('forum.index', navigate: true);
});
Expand Down
88 changes: 44 additions & 44 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
->assertSuccessful();
});

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

Expand All @@ -36,10 +36,13 @@
->assertHasNoFormErrors();

$discussion = Discussion::query()->first();
$user->refresh();

expect($discussion?->user)->toBeInstanceOf(User::class)
->and($discussion?->user->is($user))
->toBeTrue();
->toBeTrue()
->and($user->getPoints())
->toBe(20);
});

it('validate forms input', function (): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@
->assertHasNoFormErrors();

$thread = Thread::query()->first();
$user->refresh();

expect($thread?->user)->toBeInstanceOf(User::class)
->and($thread?->user->is($user))
->toBeTrue();
->toBeTrue()
->and($user->getPoints())
->toBe(55);
});

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