service->getByKanban($kanbanId); return $this->successResponse(payload: KanbanReplyResource::collection($replies)); } public function store(KanbanReplyRequest $request, int $kanbanId): JsonResponse { $reply = $this->service->create($kanbanId, auth()->id(), $request->validated()['reply']); $this->notifyReplyCreated($kanbanId); return $this->successResponse(payload: new KanbanReplyResource($reply), message: __('messages.created'), code: 201); } /** * Notifica o outro lado da atividade quando há um novo comentário. * Autor da matriz → unidade da atividade; autor da unidade → matriz. */ private function notifyReplyCreated(int $kanbanId): void { $card = Kanban::find($kanbanId); if (!$card) { return; } $author = auth()->user(); $authorIsMatriz = $author->user_type === 'ADMIN'; $unitId = $card->unit_id ?? $card->target_unit_id; $recipients = $authorIsMatriz ? $this->notifications->unitUserIds($unitId) : $this->notifications->matrizUserIds(); // Não notifica o próprio autor do comentário. $recipients = array_values(array_diff($recipients, [$author->id])); $this->notifications->dispatch([ 'origin_table' => 'kanban_replies', 'origin_id' => $card->id, 'unit_id' => $unitId, 'type' => NotificationType::KANBAN_REPLY->value, 'title' => 'Novo comentário na atividade', 'message' => $card->title, 'url' => '/kanban', 'action_text' => 'Ver atividade', 'created_by_user_id' => $author->id, 'recipient_user_ids' => $recipients, ]); } public function update(KanbanReplyRequest $request, int $kanbanId, int $id): JsonResponse { $reply = $this->service->update($kanbanId, $id, $request->validated()['reply']); return $this->successResponse(payload: new KanbanReplyResource($reply), message: __('messages.updated')); } public function destroy(int $kanbanId, int $id): JsonResponse { $this->service->delete($kanbanId, $id); return $this->successResponse(message: __('messages.deleted'), code: 204); } }