Files
InvoiceShelf/app/Platform/Ai/Http/Company/ConversationController.php
T
Darko Gjorgjijoski 5ef7804e60 refactor: adopt modular domain architecture (#747)
* refactor: stabilize model identities for domain migration

* refactor: extract module platform context

* refactor: assign models to domain contexts

* refactor: extract ai platform context

* refactor: extract storage platform context

* refactor: extract mail platform context

* refactor: extract pdf platform context

* refactor: extract operations platform context

* refactor: move installation into operations platform

* refactor: extract money domain context

* refactor: extract taxation domain context

* refactor: extract catalog domain context

* refactor: extract metadata domain context

* refactor: extract reporting domain context

* refactor: extract purchases domain context

* refactor: extract receivables domain context

* refactor: extract accounts domain context

* refactor: complete reporting statement boundary

* refactor: extract contacts domain context

* refactor: extract sales domain context

* refactor: remove legacy application layers

* fix: migrate legacy bouncer role identities
2026-08-05 17:40:03 +02:00

104 lines
2.9 KiB
PHP

<?php
namespace App\Platform\Ai\Http\Company;
use App\Platform\Ai\Models\AiConversation;
use App\Platform\Http\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
class ConversationController extends Controller
{
/**
* List the current user's conversations for the current company.
*/
public function index(Request $request): JsonResponse
{
$this->authorize('use ai');
$conversations = AiConversation::query()
->where('company_id', $request->header('company'))
->where('user_id', $request->user()->id)
->latest('updated_at')
->limit(50)
->get(['id', 'title', 'model', 'updated_at', 'created_at']);
return response()->json(['conversations' => $conversations]);
}
/**
* Show a single conversation with its full message history.
*/
public function show(Request $request, int $id): JsonResponse
{
$this->authorize('use ai');
$conversation = AiConversation::query()
->where('id', $id)
->where('company_id', $request->header('company'))
->firstOrFail();
$this->authorize('view', $conversation);
$messages = $conversation->messages()
->whereIn('role', ['user', 'assistant'])
->get(['id', 'role', 'content', 'created_at']);
return response()->json([
'conversation' => [
'id' => $conversation->id,
'title' => $conversation->title,
'model' => $conversation->model,
'created_at' => $conversation->created_at,
'updated_at' => $conversation->updated_at,
],
'messages' => $messages,
]);
}
/**
* Rename a conversation.
*
* @throws ValidationException
*/
public function update(Request $request, int $id): JsonResponse
{
$this->authorize('use ai');
$conversation = AiConversation::query()
->where('id', $id)
->where('company_id', $request->header('company'))
->firstOrFail();
$this->authorize('update', $conversation);
$validated = $this->validate($request, [
'title' => 'required|string|max:255',
]);
$conversation->update(['title' => $validated['title']]);
return response()->json(['success' => true]);
}
/**
* Delete a conversation (cascades to messages via DB foreign key).
*/
public function destroy(Request $request, int $id): JsonResponse
{
$this->authorize('use ai');
$conversation = AiConversation::query()
->where('id', $id)
->where('company_id', $request->header('company'))
->firstOrFail();
$this->authorize('delete', $conversation);
$conversation->delete();
return response()->json(['success' => true]);
}
}