First commit

This commit is contained in:
Saufi
2026-05-18 08:56:23 +08:00
commit fd3d3a4d2b
147 changed files with 22099 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Http\Controllers\Chatbot;
use App\Http\Controllers\Controller;
use App\Models\ChatFeedback;
use App\Models\ChatLog;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FeedbackController extends Controller
{
/**
* Simpan feedback untuk satu jawapan chatbot.
*/
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'chat_log_id' => ['required', 'integer', 'exists:chat_logs,id'],
'rating' => ['required', 'in:helpful,not_helpful,partially_helpful'],
'comment' => ['nullable', 'string', 'max:1000'],
'correct_answer' => ['nullable', 'string', 'max:5000'],
]);
$chatLog = ChatLog::findOrFail($validated['chat_log_id']);
// Elak duplikasi feedback
if ($chatLog->feedback) {
return response()->json([
'success' => false,
'message' => 'Anda sudah memberikan feedback untuk soalan ini.',
], 409);
}
$feedback = ChatFeedback::create([
'chat_log_id' => $chatLog->id,
'user_id' => auth()->id(),
'rating' => $validated['rating'],
'comment' => $validated['comment'] ?? null,
'correct_answer' => $validated['correct_answer'] ?? null,
]);
// Flag untuk semakan admin jika jawapan tidak membantu
if ($validated['rating'] === ChatFeedback::RATING_NOT_HELPFUL) {
$chatLog->update(['is_flagged' => true]);
}
return response()->json([
'success' => true,
'message' => 'Terima kasih atas maklum balas anda.',
]);
}
}