Added the ability to send notifications by email when a new review is added.
This commit is contained in:
@@ -5,32 +5,44 @@ namespace App\Services\Site;
|
||||
use App\Dto\Service\Site\Feedback\Send;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use App\Notifications\ReviewAdded;
|
||||
use App\ServiceResults\ServiceResultError;
|
||||
use App\ServiceResults\ServiceResultSuccess;
|
||||
use App\Services\ProjectFeedback\ProjectFeedbackCommandHandler;
|
||||
use App\Services\Service;
|
||||
use App\Services\WebsiteTranslations;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
final class FeedbackService extends Service
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProjectFeedbackCommandHandler $feedbackCommandHandler,
|
||||
private readonly bool $isNotifications = false,
|
||||
private readonly ?string $mailNotifications = null,
|
||||
) { }
|
||||
|
||||
public function send(Send $send, Project $project, WebsiteTranslations $websiteTranslations, ?User $user = null): ServiceResultError | ServiceResultSuccess
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($send, $project, $user) {
|
||||
$feedback = DB::transaction(function () use ($send, $project, $user) {
|
||||
$data = $this->getDataFeedback($send);
|
||||
$data['user_id'] = $user?->id;
|
||||
$this->feedbackCommandHandler->handleStore($project, $data);
|
||||
return $this->feedbackCommandHandler->handleStore($project, $data);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
return $this->errService($websiteTranslations->translate('Server Error'));
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->isNotifications) {
|
||||
Notification::route('mail', $this->mailNotifications)->notify(new ReviewAdded($feedback));
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
|
||||
return $this->ok($websiteTranslations->translate('site.Message sent successfully'));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user