update the new school year model

This commit is contained in:
root
2026-06-07 20:01:58 -04:00
parent 6866aedf42
commit 68a5c9edca
19 changed files with 472 additions and 32 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\BadgeScan;
use App\Http\Controllers\Api\Core\BaseApiController;
use App\Services\BadgeScan\BadgeScanService;
use App\Services\SchoolYears\SchoolYearContextService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
@@ -13,6 +14,7 @@ class BadgeScanController extends BaseApiController
{
public function __construct(
private BadgeScanService $badgeScan,
private SchoolYearContextService $schoolYears,
) {
parent::__construct();
}
@@ -24,13 +26,21 @@ class BadgeScanController extends BaseApiController
{
$validator = Validator::make($request->all(), [
'badge_scan' => ['required', 'string', 'max:255'],
'school_year' => ['nullable', 'string', 'max:50'],
'semester' => ['nullable', 'string', 'max:50'],
]);
if ($validator->fails()) {
return $this->respondValidationError($validator->errors()->toArray());
}
$result = $this->badgeScan->processScan($validator->validated()['badge_scan']);
$payload = $validator->validated();
$context = $this->schoolYears->options($payload['school_year'] ?? null, $payload['semester'] ?? null);
$result = $this->badgeScan->processScan(
$payload['badge_scan'],
$context['school_year'] ?? null,
$context['semester'] ?? null
);
if (! $result['recognized']) {
return $this->error($result['message'], Response::HTTP_NOT_FOUND);
@@ -46,10 +56,19 @@ class BadgeScanController extends BaseApiController
/**
* Authenticated scan log listing (legacy RFIDController::log).
*/
public function logs(): JsonResponse
public function logs(Request $request): JsonResponse
{
$context = $this->schoolYears->options(
$request->query('school_year'),
$request->query('semester')
);
return $this->success([
'logs' => $this->badgeScan->scanLogRows(),
'logs' => $this->badgeScan->scanLogRows(
$context['school_year'] ?? null,
$context['semester'] ?? null
),
'meta' => $context,
]);
}
}