update controllers logic

This commit is contained in:
root
2026-04-23 00:04:35 -04:00
parent 1977a513df
commit ca4ba272fc
353 changed files with 13402 additions and 1301 deletions
@@ -33,10 +33,15 @@ class TeacherAttendanceApiController extends Controller
public function form(Request $request): JsonResponse|TeacherAttendanceFormResource
{
$guard = $this->authenticatedUserIdOrUnauthorized();
if ($guard instanceof JsonResponse) {
return $guard;
}
try {
return new TeacherAttendanceFormResource(
$this->queryService->teacherAttendanceFormData(
auth()->id(),
$guard,
(int)$request->query('class_section_id', 0)
)
);
@@ -47,12 +52,30 @@ class TeacherAttendanceApiController extends Controller
public function submit(TeacherSubmitAttendanceRequest $request): JsonResponse
{
$user = auth()->user();
if ($user === null) {
return response()->json(['message' => 'Unauthorized.'], 401);
}
try {
return response()->json(
$this->attendanceService->submitTeacherAttendance(auth()->user(), $request->validated())
$this->attendanceService->submitTeacherAttendance($user, $request->validated())
);
} catch (Throwable $e) {
return response()->json(['message' => $e->getMessage()], 422);
}
}
/**
* @return int|JsonResponse
*/
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return response()->json(['message' => 'Unauthorized.'], 401);
}
return $userId;
}
}