Feature: Updating Listreners, Separating Logic from listeners, Queuing Policies

This commit is contained in:
2026-09-16 23:24:02 +03:00
parent a411e6bbc1
commit a55697ce82
25 changed files with 445 additions and 163 deletions
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Modules\Core\Review\Events;
use Modules\Core\Auth\Models\Staff;
use Modules\Core\Review\Models\ProductReview;
/**
* Dispatched whenever staff post or edit a reply to a review (see
* Modules\Core\Review\Services\ReviewService::reply()) — previously this
* happened with no event at all, so nothing could react to it (no audit
* trail, no "notify the reviewer their review got a reply" hook).
*
* $wasReply distinguishes a brand-new reply from an edit to an existing
* one — a listener building an audit trail or notification may care which
* happened (e.g. only notify the reviewer the first time, not on every
* subsequent edit).
*/
class ReviewReplied
{
public function __construct(
public readonly ProductReview $review,
public readonly Staff $repliedBy,
public readonly bool $wasReply,
) {}
}
@@ -13,11 +13,11 @@ use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Carbon;
use Illuminate\Support\HtmlString;
use Lunar\Admin\Filament\Resources\ProductResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Modules\Core\Review\Models\ProductReview;
use Modules\Core\Review\Services\ReviewService;
class ManageProductReviews extends BaseManageRelatedRecords
{
@@ -139,10 +139,7 @@ class ManageProductReviews extends BaseManageRelatedRecords
])
->fillForm(fn (ProductReview $record) => ['reply' => $record->reply])
->action(function (ProductReview $record, array $data) {
$record->update([
'reply' => $data['reply'],
'replied_at' => Carbon::now(),
]);
app(ReviewService::class)->reply($record, $data['reply'], auth('staff')->user());
}),
DeleteAction::make(),
])
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Modules\Core\Review\Services;
use Illuminate\Support\Facades\Event;
use Modules\Core\Auth\Models\Staff;
use Modules\Core\Review\Events\ReviewReplied;
use Modules\Core\Review\Models\ProductReview;
/**
* The one place a reply is written onto a ProductReview — previously
* Modules\Core\Review\Filament\Pages\ManageProductReviews wrote directly
* to the record inside its own Action closure, with no Service and no
* event dispatched for a real state change (a customer's review getting a
* staff reply). Matches the write-then-dispatch shape every other
* module's Service already uses (e.g. Modules\Core\Payment\Services\
* PaymentMethodService, Modules\Core\Customer\Services\
* CustomerAccountService).
*/
class ReviewService
{
public function reply(ProductReview $review, string $reply, Staff $repliedBy): ProductReview
{
$wasReply = $review->replied_at === null;
$review->update([
'reply' => $reply,
'replied_at' => now(),
]);
Event::dispatch(new ReviewReplied($review, $repliedBy, $wasReply));
return $review;
}
}