feat: add app and database modules
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ============================================================
|
||||
*
|
||||
* @project biiproject
|
||||
*
|
||||
* @author Andika Debi Putra
|
||||
*
|
||||
* @email andikadebiputra@gmail.com
|
||||
*
|
||||
* @website https://biiproject.com
|
||||
*
|
||||
* @copyright Copyright (c) 2026 Andika Debi Putra
|
||||
* @license Proprietary - All Rights Reserved
|
||||
*
|
||||
* @version 1.0.0
|
||||
*
|
||||
* @created 2026-05-01
|
||||
* ============================================================
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\AI;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\AI\AiAssistantService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* @OA\Tag(
|
||||
* name="AI Intelligence",
|
||||
* description="API Endpoints for AI-powered system features"
|
||||
* )
|
||||
*/
|
||||
class AiAssistantController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AiAssistantService $assistantService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/api/v1/ai/assistant/ask",
|
||||
* summary="Ask the AI Assistant",
|
||||
* description="Sends a natural language query to the AI assistant for system guidance.",
|
||||
* operationId="askAiAssistant",
|
||||
* tags={"AI Intelligence"},
|
||||
* security={{"sanctum":{}}},
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* required=true,
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
* required={"question"},
|
||||
*
|
||||
* @OA\Property(property="question", type="string", example="How do I change the maintenance mode secret?")
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="AI Response",
|
||||
*
|
||||
* @OA\JsonContent(
|
||||
*
|
||||
* @OA\Property(property="status", type="string", example="success"),
|
||||
* @OA\Property(property="answer", type="string", example="To change the secret, go to Global Settings > Maintenance.")
|
||||
* )
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(response=401, description="Unauthenticated"),
|
||||
* @OA\Response(response=422, description="Validation Error")
|
||||
* )
|
||||
*/
|
||||
public function ask(Request $request)
|
||||
{
|
||||
$this->authorize('use ai assistant');
|
||||
$request->validate([
|
||||
'question' => 'required|string|max:500',
|
||||
]);
|
||||
|
||||
$answer = $this->assistantService->answer($request->question);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'answer' => $answer,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ============================================================
|
||||
*
|
||||
* @project biiproject
|
||||
*
|
||||
* @author Andika Debi Putra
|
||||
*
|
||||
* @email andikadebiputra@gmail.com
|
||||
*
|
||||
* @website https://biiproject.com
|
||||
*
|
||||
* @copyright Copyright (c) 2026 Andika Debi Putra
|
||||
* @license Proprietary - All Rights Reserved
|
||||
*
|
||||
* @version 1.0.0
|
||||
*
|
||||
* @created 2026-05-01
|
||||
* ============================================================
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\AI;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\AI\LogAnalysisService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class LogAnalysisController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected LogAnalysisService $analysisService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the latest AI log analysis.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('view ai log analysis');
|
||||
|
||||
$analysis = Cache::get('ai_log_analysis_result', 'Analysis not generated yet. Click analyze to start.');
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'analysis' => $analysis,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a new AI log analysis.
|
||||
*/
|
||||
public function analyze(Request $request)
|
||||
{
|
||||
$this->authorize('view ai log analysis');
|
||||
|
||||
// Clear cache to force new analysis
|
||||
Cache::forget('ai_log_analysis_result');
|
||||
|
||||
$analysis = $this->analysisService->analyzeRecentLogs();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'analysis' => $analysis,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the AI log analysis cache.
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->authorize('view ai log analysis');
|
||||
|
||||
Cache::forget('ai_log_analysis_result');
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Analysis cleared successfully',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user