Files
ntspi-app/app/Services/Filament/Domain/Posts/PostNotificationService.php
F4ilji c01016a154 Migrate backend to Porto architecture and fix minor bugs
- Fully transitioned the backend to the Porto architectural pattern
- Improved code organization and maintainability
- Fixed minor bugs and inconsistencies
2025-05-12 08:47:43 +05:00

80 lines
2.7 KiB
PHP

<?php
namespace App\Services\Filament\Domain\Posts;
use App\Containers\Article\Models\Post;
use App\Containers\User\Models\Role;
use App\Containers\User\Models\User;
use App\Filament\Resources\PostResource;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
class PostNotificationService
{
/**
* Отправляет уведомления редакторам о новом посте.
*
* @param Post $post
* @return void
*/
public function send(Post $post): void
{
// Находим всех пользователей с ролью "editor"
$editors = Role::findByName('editor')->users;
// Отправляем уведомление каждому редактору
foreach ($editors as $editor) {
Notification::make()
->title('Новость на проверку')
->body('Новость "' . $post->title . '" нуждается в проверке')
->actions([
Action::make('view')
->label('Проверить')
->button()
->markAsRead()
->url(PostResource::getUrl('edit', ['record' => $post])),
])
->sendToDatabase($editor); // Отправляем уведомление конкретному редактору
}
}
public function sendSuccessNotification(Post $post): void
{
$user = User::find($post->user_id);
Notification::make()
->title('Ваша новость опубликована')
->body('Новость "' . $post->title . '" опубликована')
->actions([
Action::make('view')
->label('Смотреть')
->button()
->markAsRead()
->url(route('client.post.show', $post->slug)),
])
->sendToDatabase($user);
}
/**
* Отправляет уведомление об отклонении.
*
* @param Post $post
* @return void
*/
public function sendDeniedNotification(Post $post): void
{
$user = User::find($post->user_id);
Notification::make()
->title('Ваша новость отклонена :(')
->body('Новость "' . $post->title . '" была отклонена')
->actions([
Action::make('view')
->label('Смотреть')
->button()
->markAsRead()
->url(PostResource::getUrl('edit', ['record' => $post])),
])
->sendToDatabase($user);
}
}