43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Api\Controllers;
|
|
|
|
use Api\Core\Controller;
|
|
use Api\Core\Response;
|
|
use Api\Core\Auth;
|
|
use Api\Models\School;
|
|
|
|
class SchoolController extends Controller {
|
|
public function index() {
|
|
$user = Auth::getUser();
|
|
if (!$user || $user['role'] !== 'Super Admin') {
|
|
return Response::error('Unauthorized', 403);
|
|
}
|
|
|
|
$schools = School::all();
|
|
Response::json($schools);
|
|
}
|
|
|
|
public function stats() {
|
|
$user = Auth::getUser();
|
|
if (!$user || $user['role'] !== 'Super Admin') {
|
|
return Response::error('Unauthorized', 403);
|
|
}
|
|
|
|
$stats = School::getStats();
|
|
Response::json($stats);
|
|
}
|
|
|
|
public function store() {
|
|
$user = Auth::getUser();
|
|
if (!$user || $user['role'] !== 'Super Admin') {
|
|
return Response::error('Unauthorized', 403);
|
|
}
|
|
|
|
$data = $this->getRequestData();
|
|
$id = School::create($data);
|
|
|
|
Response::json(['id' => $id, 'message' => 'School onboarded successfully']);
|
|
}
|
|
}
|