95 lines
4.6 KiB
PHP
95 lines
4.6 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\ProfileController;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Inertia\Inertia;
|
|
|
|
Route::get('/', function () {
|
|
return Inertia::render('Welcome', [
|
|
'canLogin' => Route::has('login'),
|
|
'canRegister' => Route::has('register'),
|
|
'laravelVersion' => Application::VERSION,
|
|
'phpVersion' => PHP_VERSION,
|
|
]);
|
|
});
|
|
|
|
use App\Models\Candidate;
|
|
use App\Models\Attempt;
|
|
|
|
Route::get('/dashboard', function () {
|
|
$stats = [];
|
|
$quizzes = [];
|
|
$topCandidates = [];
|
|
|
|
if (auth()->user()->isAdmin()) {
|
|
$allCandidates = Candidate::with(['attempts'])->get();
|
|
$stats = [
|
|
'total_candidates' => Candidate::count(),
|
|
'finished_tests' => Attempt::whereNotNull('finished_at')->count(),
|
|
'average_score' => round($allCandidates->avg('weighted_score') ?? 0, 1),
|
|
'best_score' => round($allCandidates->max('weighted_score') ?? 0, 1),
|
|
];
|
|
|
|
$topCandidates = Candidate::with(['user', 'attempts'])
|
|
->get()
|
|
->sortByDesc('weighted_score')
|
|
->take(10)
|
|
->map(function($candidate) {
|
|
return [
|
|
'id' => $candidate->id,
|
|
'name' => $candidate->user->name,
|
|
'email' => $candidate->user->email,
|
|
'status' => $candidate->status,
|
|
'weighted_score' => $candidate->weighted_score
|
|
];
|
|
})
|
|
->values()
|
|
->all();
|
|
} else {
|
|
$candidate = auth()->user()->candidate;
|
|
$quizzes = \App\Models\Quiz::all()->map(function($quiz) use ($candidate) {
|
|
$quiz->has_finished_attempt = $candidate
|
|
? $candidate->attempts()->where('quiz_id', $quiz->id)->whereNotNull('finished_at')->exists()
|
|
: false;
|
|
return $quiz;
|
|
});
|
|
}
|
|
|
|
return Inertia::render('Dashboard', [
|
|
'stats' => $stats,
|
|
'quizzes' => $quizzes,
|
|
'top_candidates' => $topCandidates
|
|
]);
|
|
})->middleware(['auth', 'verified'])->name('dashboard');
|
|
|
|
Route::middleware('auth')->group(function () {
|
|
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
|
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
|
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
|
|
|
// Admin Routes
|
|
Route::middleware('admin')->prefix('admin')->name('admin.')->group(function () {
|
|
Route::get('/comparative', [\App\Http\Controllers\CandidateController::class, 'comparative'])->name('comparative');
|
|
Route::resource('candidates', \App\Http\Controllers\CandidateController::class)->only(['index', 'store', 'show', 'destroy', 'update']);
|
|
Route::patch('/candidates/{candidate}/notes', [\App\Http\Controllers\CandidateController::class, 'updateNotes'])->name('candidates.update-notes');
|
|
Route::patch('/candidates/{candidate}/scores', [\App\Http\Controllers\CandidateController::class, 'updateScores'])->name('candidates.update-scores');
|
|
Route::patch('/candidates/{candidate}/position', [\App\Http\Controllers\CandidateController::class, 'updatePosition'])->name('candidates.update-position');
|
|
Route::post('/candidates/{candidate}/reset-password', [\App\Http\Controllers\CandidateController::class, 'resetPassword'])->name('candidates.reset-password');
|
|
Route::get('/documents/{document}', [\App\Http\Controllers\DocumentController::class, 'show'])->name('documents.show');
|
|
|
|
Route::resource('quizzes', \App\Http\Controllers\QuizController::class)->only(['index', 'store', 'show', 'update', 'destroy']);
|
|
Route::resource('job-positions', \App\Http\Controllers\JobPositionController::class)->only(['index', 'store', 'update', 'destroy']);
|
|
Route::resource('quizzes.questions', \App\Http\Controllers\QuestionController::class)->only(['store', 'update', 'destroy']);
|
|
Route::delete('/attempts/{attempt}', [\App\Http\Controllers\AttemptController::class, 'destroy'])->name('attempts.destroy');
|
|
Route::patch('/answers/{answer}/score', [\App\Http\Controllers\AttemptController::class, 'updateAnswerScore'])->name('answers.update-score');
|
|
});
|
|
|
|
// Candidate Routes
|
|
Route::get('/quizzes/{quiz}', [\App\Http\Controllers\AttemptController::class, 'show'])->name('quizzes.take');
|
|
Route::post('/attempts/{attempt}/save', [\App\Http\Controllers\AttemptController::class, 'saveAnswer'])->name('attempts.save');
|
|
Route::post('/attempts/{attempt}/finish', [\App\Http\Controllers\AttemptController::class, 'finish'])->name('attempts.finish');
|
|
});
|
|
|
|
require __DIR__.'/auth.php';
|