mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-09 00:24:09 +00:00
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
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user