add more controller

This commit is contained in:
root
2026-03-10 00:48:32 -04:00
parent 5eeaec0257
commit 20ee70d153
151 changed files with 9481 additions and 8407 deletions
@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\Api\Administrator;
use App\Http\Controllers\Controller;
use App\Http\Requests\EmergencyContacts\EmergencyContactUpdateRequest;
use App\Http\Resources\EmergencyContacts\EmergencyContactGroupResource;
use App\Http\Resources\EmergencyContacts\EmergencyContactResource;
use App\Services\EmergencyContacts\EmergencyContactCrudService;
use App\Services\EmergencyContacts\EmergencyContactDirectoryService;
use Illuminate\Http\JsonResponse;
class EmergencyContactController extends Controller
{
public function __construct(
private EmergencyContactDirectoryService $directoryService,
private EmergencyContactCrudService $crudService
) {
}
public function index(): JsonResponse
{
$groups = $this->directoryService->groups();
return response()->json([
'ok' => true,
'groups' => EmergencyContactGroupResource::collection($groups),
]);
}
public function update(EmergencyContactUpdateRequest $request, int $contactId): JsonResponse
{
$contact = $this->crudService->update($contactId, $request->validated());
return response()->json([
'ok' => true,
'contact' => new EmergencyContactResource($contact),
]);
}
public function destroy(int $contactId): JsonResponse
{
$this->crudService->delete($contactId);
return response()->json(['ok' => true]);
}
}
@@ -0,0 +1,58 @@
<?php
namespace App\Http\Controllers\Api\Administrator;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Teachers\TeacherAssignmentDeleteRequest;
use App\Http\Requests\Teachers\TeacherAssignmentListRequest;
use App\Http\Requests\Teachers\TeacherAssignmentStoreRequest;
use App\Http\Resources\Teachers\TeacherAssignmentResource;
use App\Http\Resources\Teachers\TeacherClassResource;
use App\Services\Teachers\TeacherAssignmentService;
use Illuminate\Http\JsonResponse;
class TeacherClassAssignmentController extends BaseApiController
{
public function __construct(private TeacherAssignmentService $assignmentService)
{
parent::__construct();
}
public function index(TeacherAssignmentListRequest $request): JsonResponse
{
$data = $this->assignmentService->listAssignments($request->validated()['school_year'] ?? null);
return response()->json([
'ok' => true,
'school_year' => $data['school_year'],
'teachers' => TeacherAssignmentResource::collection($data['teachers']),
'classes' => TeacherClassResource::collection($data['classes']),
]);
}
public function store(TeacherAssignmentStoreRequest $request): JsonResponse
{
$payload = $request->validated();
$payload['updated_by'] = (int) (auth()->id() ?? 0);
$result = $this->assignmentService->assign($payload);
$status = $result['ok'] ? 200 : 422;
return response()->json([
'ok' => (bool) $result['ok'],
'message' => $result['message'] ?? '',
'position' => $result['position'] ?? null,
], $status);
}
public function destroy(TeacherAssignmentDeleteRequest $request): JsonResponse
{
$result = $this->assignmentService->delete($request->validated());
$status = $result['ok'] ? 200 : 422;
return response()->json([
'ok' => (bool) $result['ok'],
'message' => $result['message'] ?? '',
], $status);
}
}
@@ -0,0 +1,115 @@
<?php
namespace App\Http\Controllers\Api\Exams;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Exams\ExamDraftAdminLegacyRequest;
use App\Http\Requests\Exams\ExamDraftAdminReviewRequest;
use App\Http\Requests\Exams\ExamDraftTeacherStoreRequest;
use App\Http\Resources\Exams\ExamDraftResource;
use App\Services\Exams\ExamDraftAdminService;
use App\Services\Exams\ExamDraftTeacherService;
use Illuminate\Http\JsonResponse;
class ExamDraftController extends BaseApiController
{
public function __construct(
private ExamDraftTeacherService $teacherService,
private ExamDraftAdminService $adminService
) {
parent::__construct();
}
public function teacherIndex(): JsonResponse
{
$teacherId = (int) (auth()->id() ?? 0);
if ($teacherId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$data = $this->teacherService->listForTeacher($teacherId);
return response()->json([
'ok' => true,
'assignments' => $data['assignments'],
'drafts' => ExamDraftResource::collection($data['drafts']),
'legacy_exams' => ExamDraftResource::collection($data['legacyExams']),
'exam_types' => $data['examTypes'],
'status_options' => $data['statusOptions'],
'school_year' => $data['schoolYear'],
'semester' => $data['semester'],
]);
}
public function teacherStore(ExamDraftTeacherStoreRequest $request): JsonResponse
{
$teacherId = (int) (auth()->id() ?? 0);
if ($teacherId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$result = $this->teacherService->store($teacherId, $request->validated(), $request->file('draft_file'));
if (!$result['ok']) {
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Unable to save.'], 422);
}
return response()->json([
'ok' => true,
'draft' => new ExamDraftResource($result['draft']),
], 201);
}
public function adminIndex(): JsonResponse
{
$data = $this->adminService->list();
return response()->json([
'ok' => true,
'drafts' => ExamDraftResource::collection($data['drafts']),
'class_sections' => $data['classSections'],
'legacy_by_class' => $data['legacyByClass'],
'exam_types' => $data['examTypes'],
'status_options' => $data['statusOptions'],
'school_year' => $data['schoolYear'],
'semester' => $data['semester'],
'allowed_extensions' => $data['allowedExtensions'],
'max_upload_bytes' => $data['maxUploadBytes'],
]);
}
public function adminUploadLegacy(ExamDraftAdminLegacyRequest $request): JsonResponse
{
$adminId = (int) (auth()->id() ?? 0);
if ($adminId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$result = $this->adminService->uploadLegacy($adminId, $request->validated(), $request->file('old_exam_file'));
if (!$result['ok']) {
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Unable to save.'], 422);
}
return response()->json([
'ok' => true,
'draft' => new ExamDraftResource($result['draft']),
], 201);
}
public function adminReview(ExamDraftAdminReviewRequest $request): JsonResponse
{
$adminId = (int) (auth()->id() ?? 0);
if ($adminId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$result = $this->adminService->review($adminId, $request->validated(), $request->file('final_file'));
if (!$result['ok']) {
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Unable to save.'], 422);
}
return response()->json([
'ok' => true,
'draft' => new ExamDraftResource($result['draft']),
]);
}
}
@@ -0,0 +1,108 @@
<?php
namespace App\Http\Controllers\Api\Parents;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Parents\ParentAttendanceReportSubmitRequest;
use App\Http\Requests\Parents\ParentAttendanceReportListRequest;
use App\Http\Requests\Parents\ParentAttendanceReportCheckRequest;
use App\Http\Requests\Parents\ParentAttendanceReportUpdateRequest;
use App\Http\Resources\Parents\ParentAttendanceReportResource;
use App\Services\Parents\ParentAttendanceReportService;
use Illuminate\Http\JsonResponse;
class ParentAttendanceReportController extends BaseApiController
{
public function __construct(private ParentAttendanceReportService $reportService)
{
parent::__construct();
}
public function form(): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$data = $this->reportService->formData($parentId);
return response()->json([
'ok' => true,
'students' => $data['students'],
'today' => $data['today'],
'sundays' => $data['sundays'],
'defaultDate' => $data['defaultDate'],
'myReports' => ParentAttendanceReportResource::collection($data['myReports']),
'cutoffThreshold' => $data['cutoffThreshold'],
]);
}
public function submit(ParentAttendanceReportSubmitRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
try {
$result = $this->reportService->submit($parentId, $request->validated());
} catch (\RuntimeException $e) {
return response()->json(['ok' => false, 'message' => $e->getMessage()], 422);
}
return response()->json([
'ok' => true,
'inserted' => $result['inserted'],
'blocked' => $result['blocked'],
'students' => $result['students'],
'dates' => $result['dates'],
], 201);
}
public function list(ParentAttendanceReportListRequest $request): JsonResponse
{
$payload = $request->validated();
$start = $payload['start'] ?? now()->toDateString();
$end = $payload['end'] ?? null;
$schoolYear = $payload['school_year'] ?? null;
$semester = $payload['semester'] ?? null;
$rows = $this->reportService->listReports($start, $end, $schoolYear, $semester);
return response()->json([
'ok' => true,
'reports' => ParentAttendanceReportResource::collection($rows),
]);
}
public function checkExisting(ParentAttendanceReportCheckRequest $request): JsonResponse
{
try {
$rows = $this->reportService->checkExisting($request->validated());
} catch (\RuntimeException $e) {
return response()->json(['ok' => false, 'message' => $e->getMessage()], 422);
}
return response()->json([
'ok' => true,
'students' => $rows,
]);
}
public function update(ParentAttendanceReportUpdateRequest $request, int $reportId): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
try {
$this->reportService->updateReport($parentId, $reportId, $request->validated());
} catch (\RuntimeException $e) {
return response()->json(['ok' => false, 'message' => $e->getMessage()], 422);
}
return response()->json(['ok' => true]);
}
}
@@ -0,0 +1,284 @@
<?php
namespace App\Http\Controllers\Api\Parents;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Parents\ParentAttendanceRequest;
use App\Http\Requests\Parents\ParentEnrollmentActionRequest;
use App\Http\Requests\Parents\ParentEnrollmentRequest;
use App\Http\Requests\Parents\ParentEmergencyContactRequest;
use App\Http\Requests\Parents\ParentEventParticipationRequest;
use App\Http\Requests\Parents\ParentInvoiceRequest;
use App\Http\Requests\Parents\ParentProfileUpdateRequest;
use App\Http\Requests\Parents\ParentRegistrationRequest;
use App\Http\Requests\Parents\ParentStudentUpdateRequest;
use App\Http\Resources\Parents\ParentAttendanceResource;
use App\Http\Resources\Parents\ParentEmergencyContactResource;
use App\Http\Resources\Parents\ParentStudentResource;
use App\Http\Resources\Invoices\InvoiceResource;
use App\Services\Parents\ParentAttendanceService;
use App\Services\Parents\ParentEmergencyContactService;
use App\Services\Parents\ParentEnrollmentService;
use App\Services\Parents\ParentEventParticipationService;
use App\Services\Parents\ParentInvoiceService;
use App\Services\Parents\ParentProfileService;
use App\Services\Parents\ParentRegistrationService;
use Illuminate\Http\JsonResponse;
class ParentController extends BaseApiController
{
public function __construct(
private ParentAttendanceService $attendanceService,
private ParentInvoiceService $invoiceService,
private ParentEnrollmentService $enrollmentService,
private ParentRegistrationService $registrationService,
private ParentEmergencyContactService $emergencyContactService,
private ParentProfileService $profileService,
private ParentEventParticipationService $eventService
) {
parent::__construct();
}
public function attendance(ParentAttendanceRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$data = $this->attendanceService->listAttendance($parentId, $request->validated()['school_year'] ?? null);
return response()->json([
'ok' => true,
'attendance' => ParentAttendanceResource::collection($data['attendance']),
'schoolYears' => $data['schoolYears'],
'selectedYear' => $data['selectedYear'],
]);
}
public function invoices(ParentInvoiceRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$schoolYear = $request->validated()['school_year'] ?? null;
$rows = $this->invoiceService->listInvoices($parentId, $schoolYear);
return response()->json([
'ok' => true,
'invoices' => InvoiceResource::collection($rows),
]);
}
public function enrollments(ParentEnrollmentRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$data = $this->enrollmentService->overview($parentId, $request->validated()['school_year'] ?? null);
return response()->json([
'ok' => true,
'students' => ParentStudentResource::collection($data['students']),
'schoolYears' => $data['schoolYears'],
'selectedYear' => $data['selectedYear'],
'withdrawalDeadline' => $data['withdrawalDeadline'],
'lastDayOfRegistration' => $data['lastDayOfRegistration'],
'schoolStartDate' => $data['schoolStartDate'],
]);
}
public function updateEnrollments(ParentEnrollmentActionRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$payload = $request->validated();
$result = $this->enrollmentService->updateEnrollment(
$parentId,
$payload['enroll'] ?? [],
$payload['withdraw'] ?? []
);
return response()->json([
'ok' => true,
'enrolled' => $result['enrolled'],
'withdrawn' => $result['withdrawn'],
]);
}
public function registration(): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$data = $this->registrationService->overview($parentId);
return response()->json([
'ok' => true,
'parent' => $data['parent'],
'existingKids' => ParentStudentResource::collection($data['existingKids']),
'emergencies' => ParentEmergencyContactResource::collection($data['emergencies']),
'maxChilds' => $data['maxChilds'],
'maxEmergency' => $data['maxEmergency'],
'lastDayOfRegistration' => $data['lastDayOfRegistration'],
'registrationAgeDeadline' => $data['registrationAgeDeadline'],
]);
}
public function storeRegistration(ParentRegistrationRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$payload = $request->validated();
$result = $this->registrationService->register(
$parentId,
$payload['students'] ?? [],
$payload['emergency_contacts'] ?? []
);
return response()->json([
'ok' => true,
'created_student_ids' => $result['created_student_ids'],
], 201);
}
public function updateStudent(ParentStudentUpdateRequest $request, int $studentId): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$this->registrationService->updateStudent($parentId, $studentId, $request->validated());
return response()->json(['ok' => true]);
}
public function deleteStudent(int $studentId): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$this->registrationService->deleteStudent($parentId, $studentId);
return response()->json(['ok' => true]);
}
public function emergencyContacts(): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$rows = $this->emergencyContactService->list($parentId);
return response()->json([
'ok' => true,
'contacts' => ParentEmergencyContactResource::collection($rows),
]);
}
public function storeEmergencyContact(ParentEmergencyContactRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$contact = $this->emergencyContactService->store($parentId, $request->validated());
return response()->json([
'ok' => true,
'contact' => new ParentEmergencyContactResource($contact),
], 201);
}
public function updateEmergencyContact(ParentEmergencyContactRequest $request, int $contactId): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$contact = $this->emergencyContactService->update($parentId, $contactId, $request->validated());
return response()->json([
'ok' => true,
'contact' => new ParentEmergencyContactResource($contact),
]);
}
public function profile(): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$profile = $this->profileService->getProfile($parentId);
return response()->json([
'ok' => true,
'profile' => $profile,
]);
}
public function updateProfile(ParentProfileUpdateRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$profile = $this->profileService->updateProfile($parentId, $request->validated());
return response()->json([
'ok' => true,
'profile' => $profile,
]);
}
public function events(): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$data = $this->eventService->overview($parentId);
return response()->json([
'ok' => true,
'activeEvents' => $data['activeEvents'],
'charges' => $data['charges'],
'yourStudents' => $data['yourStudents'],
]);
}
public function updateParticipation(ParentEventParticipationRequest $request): JsonResponse
{
$parentId = (int) (auth()->id() ?? 0);
if ($parentId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$this->eventService->updateParticipation($parentId, $request->validated()['participation'] ?? []);
return response()->json(['ok' => true]);
}
}
@@ -0,0 +1,73 @@
<?php
namespace App\Http\Controllers\Api\Reports;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Reports\SlipLogListRequest;
use App\Http\Requests\Reports\SlipPreviewRequest;
use App\Http\Requests\Reports\SlipPrintRequest;
use App\Http\Requests\Reports\SlipReprintRequest;
use App\Http\Resources\Reports\LateSlipLogResource;
use App\Services\Reports\SlipPrinterService;
use Illuminate\Http\JsonResponse;
class SlipPrinterController extends BaseApiController
{
public function __construct(private SlipPrinterService $service)
{
parent::__construct();
}
public function print(SlipPrintRequest $request)
{
$userId = (int) (auth()->id() ?? 0);
$result = $this->service->print($request->validated(), $userId);
if (!$result['ok']) {
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Print failed.'], 422);
}
return response($result['pdf'], 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="' . $result['filename'] . '"',
]);
}
public function preview(SlipPreviewRequest $request): JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
$result = $this->service->preview($request->validated(), $userId);
return response()->json([
'ok' => true,
'text' => $result['text'],
'width' => $result['width'],
]);
}
public function logs(SlipLogListRequest $request): JsonResponse
{
$payload = $request->validated();
$rows = $this->service->logs($payload['school_year'] ?? null, $payload['semester'] ?? null);
return response()->json([
'ok' => true,
'logs' => LateSlipLogResource::collection($rows),
]);
}
public function reprint(SlipReprintRequest $request)
{
$userId = (int) (auth()->id() ?? 0);
$result = $this->service->reprint((int) $request->validated()['id'], $userId);
if (!$result['ok']) {
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Slip not found.'], 404);
}
return response($result['pdf'], 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="' . $result['filename'] . '"',
]);
}
}
@@ -0,0 +1,61 @@
<?php
namespace App\Http\Controllers\Api\Settings;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Settings\ConfigurationStoreRequest;
use App\Http\Requests\Settings\ConfigurationUpdateRequest;
use App\Http\Resources\Settings\ConfigurationResource;
use App\Services\Settings\ConfigurationService;
use Illuminate\Http\JsonResponse;
class ConfigurationAdminController extends BaseApiController
{
public function __construct(private ConfigurationService $service)
{
parent::__construct();
}
public function index(): JsonResponse
{
$configs = $this->service->list();
return response()->json([
'ok' => true,
'configs' => ConfigurationResource::collection($configs),
]);
}
public function store(ConfigurationStoreRequest $request): JsonResponse
{
$config = $this->service->store($request->validated());
return response()->json([
'ok' => true,
'config' => new ConfigurationResource($config->toArray()),
], 201);
}
public function update(ConfigurationUpdateRequest $request, int $id): JsonResponse
{
$config = $this->service->update($id, $request->validated());
if (!$config) {
return response()->json(['ok' => false, 'message' => 'Configuration not found.'], 404);
}
return response()->json([
'ok' => true,
'config' => new ConfigurationResource($config->toArray()),
]);
}
public function destroy(int $id): JsonResponse
{
$deleted = $this->service->delete($id);
if (!$deleted) {
return response()->json(['ok' => false, 'message' => 'Configuration not found.'], 404);
}
return response()->json(['ok' => true]);
}
}
@@ -0,0 +1,143 @@
<?php
namespace App\Http\Controllers\Api\Staff;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Teachers\TeacherAbsenceSubmitRequest;
use App\Http\Requests\Teachers\TeacherClassViewRequest;
use App\Http\Requests\Teachers\TeacherSwitchClassRequest;
use App\Http\Resources\Teachers\TeacherAbsenceResource;
use App\Http\Resources\Teachers\TeacherClassResource;
use App\Http\Resources\Teachers\TeacherStudentResource;
use App\Models\User;
use App\Services\Teachers\TeacherAbsenceService;
use App\Services\Teachers\TeacherDashboardService;
use Illuminate\Http\JsonResponse;
class TeacherController extends BaseApiController
{
public function __construct(
private TeacherDashboardService $dashboardService,
private TeacherAbsenceService $absenceService
) {
parent::__construct();
}
public function classes(TeacherClassViewRequest $request): JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
try {
$data = $this->dashboardService->classView(
$userId,
$request->validated()['class_section_id'] ?? null
);
} catch (\RuntimeException $e) {
return response()->json(['ok' => false, 'message' => $e->getMessage()], 403);
}
$teacher = $this->teacherPayload($data['teacher'] ?? null, $userId);
$studentsBySection = [];
foreach (($data['studentsBySection'] ?? []) as $sectionId => $students) {
$studentsBySection[(string) $sectionId] = TeacherStudentResource::collection($students);
}
return response()->json([
'ok' => true,
'teacher' => $teacher,
'classes' => TeacherClassResource::collection($data['classes'] ?? []),
'students' => TeacherStudentResource::collection($data['students'] ?? []),
'students_by_section' => $studentsBySection,
'assigned_names' => $data['assignedNames'] ?? [],
'active_class_section_id' => $data['active_class_section_id'] ?? null,
]);
}
public function switchClass(TeacherSwitchClassRequest $request): JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$requested = (int) $request->validated()['class_section_id'];
try {
$data = $this->dashboardService->classView($userId, $requested);
} catch (\RuntimeException $e) {
return response()->json(['ok' => false, 'message' => $e->getMessage()], 403);
}
if (($data['active_class_section_id'] ?? null) !== $requested) {
return response()->json([
'ok' => false,
'message' => 'You are not assigned to that class.',
], 422);
}
return response()->json([
'ok' => true,
'active_class_section_id' => $requested,
]);
}
public function absenceForm(): JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$data = $this->absenceService->formData($userId);
return response()->json([
'ok' => true,
'teacher_name' => $data['teacher_name'],
'semester' => $data['semester'],
'school_year' => $data['school_year'],
'existing' => TeacherAbsenceResource::collection($data['existing'] ?? []),
'available_dates' => $data['available_dates'] ?? [],
]);
}
public function submitAbsence(TeacherAbsenceSubmitRequest $request): JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
$result = $this->absenceService->submit($userId, $request->validated());
return response()->json([
'ok' => (bool) ($result['ok'] ?? false),
'message' => $result['message'] ?? '',
'saved' => $result['saved'] ?? 0,
'dates' => $result['dates'] ?? [],
], (int) ($result['status'] ?? 200));
}
private function teacherPayload(?array $teacher, int $userId): ?array
{
if (!$teacher) {
$model = User::query()->find($userId);
$teacher = $model?->toArray();
}
if (!$teacher) {
return null;
}
return [
'id' => (int) ($teacher['id'] ?? 0),
'firstname' => (string) ($teacher['firstname'] ?? ''),
'lastname' => (string) ($teacher['lastname'] ?? ''),
'email' => $teacher['email'] ?? null,
'role' => User::getUserRoleName($userId),
];
}
}
@@ -0,0 +1,156 @@
<?php
namespace App\Http\Controllers\Api\Students;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Students\StudentAssignClassRequest;
use App\Http\Requests\Students\StudentAssignmentListRequest;
use App\Http\Requests\Students\StudentAutoDistributeRequest;
use App\Http\Requests\Students\StudentPromotionTotalsRequest;
use App\Http\Requests\Students\StudentRemoveClassRequest;
use App\Http\Requests\Students\StudentSetActiveRequest;
use App\Http\Requests\Students\StudentUpdateRequest;
use App\Http\Resources\Students\StudentAssignmentResource;
use App\Http\Resources\Students\StudentClassSectionResource;
use App\Http\Resources\Students\StudentRemovedResource;
use App\Http\Resources\Students\StudentScoreCardRowResource;
use App\Services\Students\StudentAssignmentService;
use App\Services\Students\StudentAutoDistributionService;
use App\Services\Students\StudentDirectoryService;
use App\Services\Students\StudentProfileService;
use App\Services\Students\StudentScoreCardService;
use App\Services\Students\StudentStatusService;
use Illuminate\Http\JsonResponse;
class StudentController extends BaseApiController
{
public function __construct(
private StudentAssignmentService $assignmentService,
private StudentDirectoryService $directoryService,
private StudentStatusService $statusService,
private StudentAutoDistributionService $autoDistributionService,
private StudentProfileService $profileService,
private StudentScoreCardService $scoreCardService
) {
parent::__construct();
}
public function assignments(StudentAssignmentListRequest $request): JsonResponse
{
$data = $this->directoryService->assignmentData($request->validated()['school_year'] ?? null);
return response()->json([
'ok' => true,
'students' => StudentAssignmentResource::collection($data['students']),
'classes' => StudentClassSectionResource::collection($data['classes']),
'schoolYears' => $data['schoolYears'],
'selectedYear' => $data['selectedYear'],
'currentYear' => $data['currentYear'],
'isCurrentYear' => $data['isCurrentYear'],
]);
}
public function assignClass(StudentAssignClassRequest $request): JsonResponse
{
$payload = $request->validated();
$result = $this->assignmentService->assignClasses(
(int) $payload['student_id'],
$payload['class_section_id'],
(bool) ($payload['is_event_only'] ?? false),
(int) (auth()->id() ?? 0)
);
$status = $result['ok'] ? 200 : 422;
return response()->json($result + ['ok' => (bool) $result['ok']], $status);
}
public function removeClass(StudentRemoveClassRequest $request): JsonResponse
{
$payload = $request->validated();
$result = $this->assignmentService->removeClass(
(int) $payload['student_id'],
(int) $payload['class_section_id'],
(int) (auth()->id() ?? 0)
);
$status = $result['ok'] ? 200 : 422;
return response()->json($result + ['ok' => (bool) $result['ok']], $status);
}
public function removed(StudentAssignmentListRequest $request): JsonResponse
{
$data = $this->directoryService->removedStudents($request->validated()['school_year'] ?? null);
return response()->json([
'ok' => true,
'active_students' => StudentRemovedResource::collection($data['active_students']),
'removed_students' => StudentRemovedResource::collection($data['removed_students']),
'school_year' => $data['school_year'],
]);
}
public function setActive(StudentSetActiveRequest $request): JsonResponse
{
$payload = $request->validated();
$result = $this->statusService->setActive(
(int) $payload['student_id'],
(bool) $payload['is_active'],
(int) (auth()->id() ?? 0)
);
$status = $result['ok'] ? 200 : 422;
return response()->json($result + ['ok' => (bool) $result['ok']], $status);
}
public function autoDistribute(StudentAutoDistributeRequest $request): JsonResponse
{
$payload = $request->validated();
$result = $this->autoDistributionService->autoDistribute(
(int) ($payload['class_id'] ?? 0),
(int) $payload['students_per_section'],
$payload['school_year'] ?? null,
(int) ($payload['class_section_id'] ?? 0),
(int) (auth()->id() ?? 0)
);
$status = $result['ok'] ? 200 : 422;
return response()->json($result + ['ok' => (bool) $result['ok']], $status);
}
public function promotionTotals(StudentPromotionTotalsRequest $request): JsonResponse
{
$data = $this->autoDistributionService->promotionTotals($request->validated()['school_year'] ?? null);
return response()->json([
'ok' => true,
'year' => $data['year'],
'rows' => $data['rows'],
]);
}
public function update(StudentUpdateRequest $request, int $studentId): JsonResponse
{
$result = $this->profileService->updateStudent($studentId, $request->validated());
$status = $result['ok'] ? 200 : 422;
return response()->json($result + ['ok' => (bool) $result['ok']], $status);
}
public function scoreCard(int $studentId): JsonResponse
{
$result = $this->scoreCardService->scoreCard($studentId);
if (!$result['ok']) {
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Not found.'], 404);
}
return response()->json([
'ok' => true,
'student' => $result['student'],
'rows' => StudentScoreCardRowResource::collection($result['rows']),
]);
}
}
@@ -0,0 +1,78 @@
<?php
namespace App\Http\Controllers\Api\Subjects;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\Subjects\SubjectCurriculumStoreRequest;
use App\Http\Requests\Subjects\SubjectCurriculumUpdateRequest;
use App\Http\Resources\Subjects\SubjectClassResource;
use App\Http\Resources\Subjects\SubjectCurriculumResource;
use App\Models\SubjectCurriculum;
use App\Services\Subjects\SubjectCurriculumService;
use Illuminate\Http\JsonResponse;
class SubjectCurriculumController extends BaseApiController
{
public function __construct(private SubjectCurriculumService $service)
{
parent::__construct();
}
public function index(): JsonResponse
{
$data = $this->service->list();
return response()->json([
'ok' => true,
'classes' => SubjectClassResource::collection($data['classes']),
'entries' => SubjectCurriculumResource::collection($data['entries']),
'subject_labels' => $data['subject_labels'],
]);
}
public function show(int $id): JsonResponse
{
$entry = SubjectCurriculum::query()->find($id);
if (!$entry) {
return response()->json(['ok' => false, 'message' => 'Curriculum entry not found.'], 404);
}
return response()->json([
'ok' => true,
'entry' => new SubjectCurriculumResource($entry->toArray()),
]);
}
public function store(SubjectCurriculumStoreRequest $request): JsonResponse
{
$entry = $this->service->store($request->validated());
return response()->json([
'ok' => true,
'entry' => new SubjectCurriculumResource($entry->toArray()),
], 201);
}
public function update(SubjectCurriculumUpdateRequest $request, int $id): JsonResponse
{
$entry = $this->service->update($id, $request->validated());
if (!$entry) {
return response()->json(['ok' => false, 'message' => 'Curriculum entry not found.'], 404);
}
return response()->json([
'ok' => true,
'entry' => new SubjectCurriculumResource($entry->toArray()),
]);
}
public function destroy(int $id): JsonResponse
{
$deleted = $this->service->delete($id);
if (!$deleted) {
return response()->json(['ok' => false, 'message' => 'Curriculum entry not found.'], 404);
}
return response()->json(['ok' => true]);
}
}
@@ -0,0 +1,64 @@
<?php
namespace App\Http\Controllers\Api\System;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Requests\SchoolIds\SchoolIdAssignRequest;
use App\Http\Resources\SchoolIds\SchoolIdResource;
use App\Services\SchoolIds\SchoolIdAssignmentService;
use App\Services\SchoolIds\SchoolIdGenerationService;
use Illuminate\Http\JsonResponse;
class SchoolIdController extends BaseApiController
{
public function __construct(
private SchoolIdAssignmentService $assignmentService,
private SchoolIdGenerationService $generationService
) {
parent::__construct();
}
public function assign(SchoolIdAssignRequest $request): JsonResponse
{
$payload = $request->validated();
$schoolId = $this->assignmentService->assignToUser((int) $payload['user_id']);
if ($schoolId === null) {
return response()->json(['ok' => false, 'message' => 'User not found.'], 404);
}
return response()->json([
'ok' => true,
'result' => new SchoolIdResource([
'type' => 'user',
'school_id' => $schoolId,
]),
]);
}
public function generateStudent(): JsonResponse
{
$schoolId = $this->generationService->generateStudentId();
return response()->json([
'ok' => true,
'result' => new SchoolIdResource([
'type' => 'student',
'school_id' => $schoolId,
]),
]);
}
public function generateUser(): JsonResponse
{
$schoolId = $this->generationService->generateUserId();
return response()->json([
'ok' => true,
'result' => new SchoolIdResource([
'type' => 'user',
'school_id' => $schoolId,
]),
]);
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\EmergencyContacts;
use App\Http\Requests\ApiFormRequest;
class EmergencyContactUpdateRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:150'],
'cellphone' => ['required', 'string', 'max:30'],
'email' => ['nullable', 'email', 'max:150'],
'relation' => ['nullable', 'string', 'max:80'],
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Requests\Exams;
use App\Http\Requests\ApiFormRequest;
class ExamDraftAdminLegacyRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'class_section_id' => ['required', 'integer', 'min:1'],
'school_year' => ['required', 'string'],
'semester' => ['required', 'string'],
'exam_type' => ['nullable', 'string', 'max:50'],
'old_exam_file' => ['required', 'file', 'mimes:doc,docx,pdf', 'max:12288'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Exams;
use App\Http\Requests\ApiFormRequest;
class ExamDraftAdminReviewRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'draft_id' => ['required', 'integer', 'min:1'],
'review_status' => ['nullable', 'in:draft,submitted,reviewed,finalized,rejected,pending,final,approved'],
'admin_comments' => ['nullable', 'string'],
'final_file' => ['nullable', 'file', 'mimes:doc,docx,pdf', 'max:12288'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Exams;
use App\Http\Requests\ApiFormRequest;
class ExamDraftTeacherStoreRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'class_section_id' => ['required', 'integer', 'min:1'],
'exam_type' => ['nullable', 'string', 'max:50'],
'description' => ['nullable', 'string'],
'draft_file' => ['nullable', 'file', 'mimes:doc,docx', 'max:12288'],
];
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentAttendanceReportCheckRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'date' => ['nullable', 'date'],
'dates' => ['nullable', 'array'],
'dates.*' => ['date'],
'type' => ['required', 'in:absent,late,early_dismissal'],
'student_ids' => ['required', 'array'],
'student_ids.*' => ['integer', 'min:1'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentAttendanceReportListRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'start' => ['nullable', 'date'],
'end' => ['nullable', 'date'],
'school_year' => ['nullable', 'string', 'max:20'],
'semester' => ['nullable', 'string', 'max:20'],
];
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentAttendanceReportSubmitRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'student_ids' => ['required', 'array'],
'student_ids.*' => ['integer', 'min:1'],
'date' => ['nullable', 'date'],
'dates' => ['nullable', 'array'],
'dates.*' => ['date'],
'type' => ['required', 'in:absent,late,early_dismissal'],
'arrival_time' => ['nullable', 'string'],
'dismiss_time' => ['nullable', 'string'],
'reason' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentAttendanceReportUpdateRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'reason' => ['nullable', 'string'],
'arrival_time' => ['nullable', 'string'],
'dismiss_time' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentAttendanceRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string', 'max:20'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentEmergencyContactRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:150'],
'cellphone' => ['required', 'string', 'max:30'],
'email' => ['nullable', 'email', 'max:150'],
'relation' => ['nullable', 'string', 'max:80'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentEnrollmentActionRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'enroll' => ['nullable', 'array'],
'enroll.*' => ['integer', 'min:1'],
'withdraw' => ['nullable', 'array'],
'withdraw.*' => ['integer', 'min:1'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentEnrollmentRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string', 'max:20'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentEventParticipationRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'participation' => ['required', 'array'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentInvoiceRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string', 'max:20'],
];
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentProfileUpdateRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'firstname' => ['required', 'string', 'max:255'],
'lastname' => ['required', 'string', 'max:255'],
'cellphone' => ['required', 'string', 'max:25'],
'address_street' => ['required', 'string', 'max:255'],
'city' => ['required', 'string', 'max:255'],
'state' => ['required', 'string', 'max:25'],
'zip' => ['required', 'string', 'max:25'],
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentRegistrationRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'students' => ['nullable', 'array'],
'students.*.firstname' => ['required_with:students', 'string', 'max:255'],
'students.*.lastname' => ['required_with:students', 'string', 'max:255'],
'students.*.dob' => ['required_with:students', 'date'],
'students.*.gender' => ['required_with:students', 'string', 'max:10'],
'students.*.registration_grade' => ['nullable', 'string', 'max:50'],
'students.*.photo_consent' => ['nullable', 'boolean'],
'students.*.is_new' => ['nullable', 'boolean'],
'students.*.allergies' => ['nullable', 'array'],
'students.*.medical_conditions' => ['nullable', 'array'],
'emergency_contacts' => ['nullable', 'array'],
'emergency_contacts.*.name' => ['required_with:emergency_contacts', 'string', 'max:150'],
'emergency_contacts.*.cellphone' => ['required_with:emergency_contacts', 'string', 'max:30'],
'emergency_contacts.*.email' => ['nullable', 'email', 'max:150'],
'emergency_contacts.*.relation' => ['nullable', 'string', 'max:80'],
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Requests\Parents;
use App\Http\Requests\ApiFormRequest;
class ParentStudentUpdateRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'firstname' => ['required', 'string', 'max:255'],
'lastname' => ['required', 'string', 'max:255'],
'dob' => ['required', 'date'],
'gender' => ['required', 'string', 'max:10'],
'photo_consent' => ['nullable', 'boolean'],
'registration_grade' => ['nullable', 'string', 'max:50'],
'allergies' => ['nullable', 'array'],
'medical_conditions' => ['nullable', 'array'],
];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Requests\Reports;
use App\Http\Requests\ApiFormRequest;
class SlipLogListRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string'],
'semester' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Requests\Reports;
use App\Http\Requests\ApiFormRequest;
class SlipPreviewRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string'],
'student_name' => ['nullable', 'string'],
'date' => ['nullable', 'string'],
'time_in' => ['nullable', 'string'],
'grade' => ['nullable', 'string'],
'reason' => ['nullable', 'string'],
'admin_name' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests\Reports;
use App\Http\Requests\ApiFormRequest;
class SlipPrintRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string'],
'student_name' => ['required', 'string'],
'date' => ['nullable', 'string'],
'time_in' => ['nullable', 'string'],
'grade' => ['nullable', 'string'],
'reason' => ['nullable', 'string'],
'admin_name' => ['nullable', 'string'],
'paper' => ['nullable', 'string'],
'font_pt' => ['nullable', 'numeric'],
'line_h' => ['nullable', 'numeric'],
'rows' => ['nullable', 'integer'],
'height_mm' => ['nullable', 'numeric'],
'h' => ['nullable', 'numeric'],
'fudge_mm' => ['nullable', 'numeric'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Reports;
use App\Http\Requests\ApiFormRequest;
class SlipReprintRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'id' => ['required', 'integer', 'min:1'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\SchoolIds;
use App\Http\Requests\ApiFormRequest;
class SchoolIdAssignRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'user_id' => ['required', 'integer', 'min:1', 'exists:users,id'],
];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Requests\Settings;
use App\Http\Requests\ApiFormRequest;
class ConfigurationStoreRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'config_key' => ['required', 'string', 'max:255'],
'config_value' => ['required', 'string'],
];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Requests\Settings;
use App\Http\Requests\ApiFormRequest;
class ConfigurationUpdateRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'config_key' => ['required', 'string', 'max:255'],
'config_value' => ['required', 'string'],
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Requests\Students;
use App\Http\Requests\ApiFormRequest;
class StudentAssignClassRequest extends ApiFormRequest
{
protected function prepareForValidation(): void
{
$value = $this->input('class_section_id');
if (is_string($value)) {
$parts = preg_split('/[,\s]+/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
$this->merge(['class_section_id' => $parts]);
}
}
public function rules(): array
{
return [
'student_id' => ['required', 'integer', 'min:1'],
'class_section_id' => ['required', 'array', 'min:1'],
'class_section_id.*' => ['integer', 'min:1'],
'is_event_only' => ['nullable', 'boolean'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Students;
use App\Http\Requests\ApiFormRequest;
class StudentAssignmentListRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Students;
use App\Http\Requests\ApiFormRequest;
class StudentAutoDistributeRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'class_id' => ['nullable', 'integer', 'min:1'],
'class_section_id' => ['nullable', 'integer', 'min:1'],
'students_per_section' => ['required', 'integer', 'min:1'],
'school_year' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Students;
use App\Http\Requests\ApiFormRequest;
class StudentPromotionTotalsRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Requests\Students;
use App\Http\Requests\ApiFormRequest;
class StudentRemoveClassRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'student_id' => ['required', 'integer', 'min:1'],
'class_section_id' => ['required', 'integer', 'min:1'],
];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Requests\Students;
use App\Http\Requests\ApiFormRequest;
class StudentSetActiveRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'student_id' => ['required', 'integer', 'min:1'],
'is_active' => ['required', 'boolean'],
];
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests\Students;
use App\Http\Requests\ApiFormRequest;
class StudentUpdateRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_id' => ['nullable', 'string', 'max:100'],
'firstname' => ['required', 'string', 'max:255'],
'lastname' => ['required', 'string', 'max:255'],
'dob' => ['required', 'date'],
'age' => ['nullable', 'integer'],
'gender' => ['required', 'in:Male,Female,Other'],
'registration_grade' => ['required', 'string', 'max:50'],
'photo_consent' => ['nullable', 'boolean'],
'parent_id' => ['required', 'integer', 'min:1'],
'registration_date' => ['nullable', 'date'],
'tuition_paid' => ['nullable', 'boolean'],
'year_of_registration' => ['nullable', 'string'],
'school_year' => ['nullable', 'string'],
'rfid_tag' => ['nullable', 'string', 'max:100'],
'semester' => ['nullable', 'string'],
'is_new' => ['required', 'boolean'],
'is_active' => ['nullable', 'boolean'],
'medical_conditions' => ['nullable', 'string'],
'allergies' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Requests\Subjects;
use App\Http\Requests\ApiFormRequest;
class SubjectCurriculumStoreRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'class_id' => ['required', 'integer', 'min:1'],
'subject' => ['required', 'in:islamic,quran'],
'chapter_name' => ['required', 'string', 'max:255'],
'unit_number' => ['nullable', 'integer'],
'unit_title' => ['nullable', 'string', 'max:255'],
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Requests\Subjects;
use App\Http\Requests\ApiFormRequest;
class SubjectCurriculumUpdateRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'class_id' => ['required', 'integer', 'min:1'],
'subject' => ['required', 'in:islamic,quran'],
'chapter_name' => ['required', 'string', 'max:255'],
'unit_number' => ['nullable', 'integer'],
'unit_title' => ['nullable', 'string', 'max:255'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Teachers;
use App\Http\Requests\ApiFormRequest;
class TeacherAbsenceSubmitRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'dates' => ['required', 'array', 'min:1'],
'dates.*' => ['date'],
'reason' => ['required', 'string'],
'reason_type' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Teachers;
use App\Http\Requests\ApiFormRequest;
class TeacherAssignmentDeleteRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'teacher_id' => ['required', 'integer', 'min:1'],
'class_section_id' => ['required', 'integer', 'min:1'],
'position' => ['required', 'in:main,ta'],
'school_year' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Teachers;
use App\Http\Requests\ApiFormRequest;
class TeacherAssignmentListRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'school_year' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Teachers;
use App\Http\Requests\ApiFormRequest;
class TeacherAssignmentStoreRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'teacher_id' => ['required', 'integer', 'min:1'],
'class_section_id' => ['required', 'integer', 'min:1'],
'teacher_role' => ['nullable', 'string'],
'school_year' => ['nullable', 'string'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Teachers;
use App\Http\Requests\ApiFormRequest;
class TeacherClassViewRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'class_section_id' => ['nullable', 'integer', 'min:1'],
];
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\Teachers;
use App\Http\Requests\ApiFormRequest;
class TeacherSwitchClassRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'class_section_id' => ['required', 'integer', 'min:1'],
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources\EmergencyContacts;
use Illuminate\Http\Resources\Json\JsonResource;
class EmergencyContactGroupResource extends JsonResource
{
public function toArray($request): array
{
return [
'parent_id' => (int) ($this['parent_id'] ?? 0),
'parent_name' => (string) ($this['parent_name'] ?? ''),
'parent_phones' => array_values($this['parent_phones'] ?? []),
'students' => EmergencyContactStudentResource::collection($this['students'] ?? []),
'contacts' => EmergencyContactResource::collection($this['contacts'] ?? []),
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources\EmergencyContacts;
use Illuminate\Http\Resources\Json\JsonResource;
class EmergencyContactResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'parent_id' => (int) ($this['parent_id'] ?? 0),
'name' => (string) ($this['emergency_contact_name'] ?? ''),
'cellphone' => (string) ($this['cellphone'] ?? ''),
'email' => $this['email'] ?? null,
'relation' => $this['relation'] ?? null,
'semester' => $this['semester'] ?? null,
'school_year' => $this['school_year'] ?? null,
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Resources\EmergencyContacts;
use Illuminate\Http\Resources\Json\JsonResource;
class EmergencyContactStudentResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'firstname' => (string) ($this['firstname'] ?? ''),
'lastname' => (string) ($this['lastname'] ?? ''),
'school_id' => $this['school_id'] ?? null,
];
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Resources\Exams;
use Illuminate\Http\Resources\Json\JsonResource;
class ExamDraftResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'teacher_id' => (int) ($this['teacher_id'] ?? 0),
'class_section_id' => (int) ($this['class_section_id'] ?? 0),
'class_section_name' => $this['class_section_name'] ?? null,
'semester' => $this['semester'] ?? null,
'school_year' => $this['school_year'] ?? null,
'exam_type' => $this['exam_type'] ?? null,
'draft_title' => $this['draft_title'] ?? null,
'description' => $this['description'] ?? null,
'teacher_file' => $this['teacher_file'] ?? null,
'teacher_filename' => $this['teacher_filename'] ?? null,
'status' => $this['status'] ?? null,
'admin_id' => $this['admin_id'] ?? null,
'admin_comments' => $this['admin_comments'] ?? null,
'reviewed_at' => $this['reviewed_at'] ?? null,
'final_file' => $this['final_file'] ?? null,
'final_filename' => $this['final_filename'] ?? null,
'final_pdf_file' => $this['final_pdf_file'] ?? null,
'version' => $this['version'] ?? null,
'previous_draft_id' => $this['previous_draft_id'] ?? null,
'is_legacy' => $this['is_legacy'] ?? null,
'teacher_first' => $this['teacher_first'] ?? null,
'teacher_last' => $this['teacher_last'] ?? null,
'admin_first' => $this['admin_first'] ?? null,
'admin_last' => $this['admin_last'] ?? null,
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources\Parents;
use Illuminate\Http\Resources\Json\JsonResource;
class ParentAttendanceReportResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'parent_id' => (int) ($this['parent_id'] ?? 0),
'student_id' => (int) ($this['student_id'] ?? 0),
'class_section_id' => $this['class_section_id'] ?? null,
'report_date' => (string) ($this['report_date'] ?? ''),
'type' => (string) ($this['type'] ?? ''),
'arrival_time' => $this['arrival_time'] ?? null,
'dismiss_time' => $this['dismiss_time'] ?? null,
'reason' => $this['reason'] ?? null,
'semester' => $this['semester'] ?? null,
'school_year' => $this['school_year'] ?? null,
'status' => $this['status'] ?? null,
'firstname' => $this['firstname'] ?? null,
'lastname' => $this['lastname'] ?? null,
'class_section_name' => $this['class_section_name'] ?? null,
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources\Parents;
use Illuminate\Http\Resources\Json\JsonResource;
class ParentAttendanceResource extends JsonResource
{
public function toArray($request): array
{
return [
'firstname' => (string) ($this['firstname'] ?? ''),
'lastname' => (string) ($this['lastname'] ?? ''),
'date' => (string) ($this['date'] ?? ''),
'status' => (string) ($this['status'] ?? ''),
'reason' => $this['reason'] ?? null,
];
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources\Parents;
use Illuminate\Http\Resources\Json\JsonResource;
class ParentEmergencyContactResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'name' => (string) ($this['emergency_contact_name'] ?? ''),
'cellphone' => (string) ($this['cellphone'] ?? ''),
'email' => $this['email'] ?? null,
'relation' => $this['relation'] ?? null,
'semester' => $this['semester'] ?? null,
'school_year' => $this['school_year'] ?? null,
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources\Parents;
use Illuminate\Http\Resources\Json\JsonResource;
class ParentStudentResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'firstname' => (string) ($this['firstname'] ?? ''),
'lastname' => (string) ($this['lastname'] ?? ''),
'dob' => $this['dob'] ?? null,
'gender' => $this['gender'] ?? null,
'registration_grade' => $this['registration_grade'] ?? null,
'school_year' => $this['school_year'] ?? null,
'semester' => $this['semester'] ?? null,
'class_section' => $this['class_section'] ?? null,
'enrollment_status' => $this['enrollment_status'] ?? null,
'admission_status' => $this['admission_status'] ?? null,
'disable_enroll' => (bool) ($this['disable_enroll'] ?? false),
'allergies' => $this['allergies'] ?? [],
'medical_conditions' => $this['medical_conditions'] ?? [],
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources\Reports;
use Illuminate\Http\Resources\Json\JsonResource;
class LateSlipLogResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'school_year' => (string) ($this['school_year'] ?? ''),
'semester' => (string) ($this['semester'] ?? ''),
'student_name' => (string) ($this['student_name'] ?? ''),
'date' => $this['date'] ?? null,
'time_in' => $this['time_in'] ?? null,
'grade' => $this['grade'] ?? null,
'reason' => $this['reason'] ?? null,
'admin_name' => $this['admin_name'] ?? null,
'printed_at' => $this['printed_at'] ?? null,
];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Http\Resources\SchoolIds;
use Illuminate\Http\Resources\Json\JsonResource;
class SchoolIdResource extends JsonResource
{
public function toArray($request): array
{
return [
'type' => $this['type'] ?? null,
'school_id' => $this['school_id'] ?? null,
];
}
}
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Resources\Settings;
use Illuminate\Http\Resources\Json\JsonResource;
class ConfigurationResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'config_key' => (string) ($this['config_key'] ?? ''),
'config_value' => (string) ($this['config_value'] ?? ''),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources\Students;
use Illuminate\Http\Resources\Json\JsonResource;
class StudentAssignmentResource extends JsonResource
{
public function toArray($request): array
{
return [
'student_id' => (int) ($this['student_id'] ?? 0),
'name' => (string) ($this['name'] ?? ''),
'age' => $this['age'] ?? null,
'email' => $this['email'] ?? null,
'phone' => $this['phone'] ?? null,
'registration_grade' => $this['registration_grade'] ?? null,
'class_section_name' => $this['class_section_name'] ?? null,
'class_section_names' => $this['class_section_names'] ?? [],
'class_section_ids' => $this['class_section_ids'] ?? [],
'new_student' => $this['new_student'] ?? null,
'registration_date' => $this['registration_date'] ?? null,
'school_year' => $this['school_year'] ?? null,
'semester' => $this['semester'] ?? null,
];
}
}
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Resources\Students;
use Illuminate\Http\Resources\Json\JsonResource;
class StudentClassSectionResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'class_section_id' => (int) ($this['class_section_id'] ?? 0),
'class_section_name' => (string) ($this['class_section_name'] ?? ''),
'school_year' => $this['school_year'] ?? null,
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources\Students;
use Illuminate\Http\Resources\Json\JsonResource;
class StudentRemovedResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'school_id' => $this['school_id'] ?? null,
'firstname' => $this['firstname'] ?? null,
'lastname' => $this['lastname'] ?? null,
'gender' => $this['gender'] ?? null,
'age' => $this['age'] ?? null,
'class_sections' => $this['class_sections'] ?? [],
'class_section_name' => $this['class_section_name'] ?? null,
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources\Students;
use Illuminate\Http\Resources\Json\JsonResource;
class StudentScoreCardRowResource extends JsonResource
{
public function toArray($request): array
{
return [
'school_year' => $this['school_year'] ?? null,
'semester' => $this['semester'] ?? null,
'homework_avg' => $this['homework_avg'] ?? null,
'project_avg' => $this['project_avg'] ?? null,
'participation_score' => $this['participation_score'] ?? null,
'quiz_avg' => $this['quiz_avg'] ?? null,
'test_avg' => $this['test_avg'] ?? null,
'attendance_score' => $this['attendance_score'] ?? null,
'ptap_score' => $this['ptap_score'] ?? null,
'midterm_exam_score' => $this['midterm_exam_score'] ?? null,
'semester_score' => $this['semester_score'] ?? null,
'class_section_name' => $this['class_section_name'] ?? null,
'comments' => $this['comments'] ?? [],
'year_score' => $this['year_score'] ?? null,
];
}
}
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Resources\Subjects;
use Illuminate\Http\Resources\Json\JsonResource;
class SubjectClassResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'class_name' => (string) ($this['class_name'] ?? ''),
'school_year' => $this['school_year'] ?? null,
];
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources\Subjects;
use Illuminate\Http\Resources\Json\JsonResource;
class SubjectCurriculumResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'class_id' => (int) ($this['class_id'] ?? 0),
'class_name' => $this['class_name'] ?? null,
'subject' => (string) ($this['subject'] ?? ''),
'unit_number' => $this['unit_number'] ?? null,
'unit_title' => $this['unit_title'] ?? null,
'chapter_name' => (string) ($this['chapter_name'] ?? ''),
];
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources\Teachers;
use Illuminate\Http\Resources\Json\JsonResource;
class TeacherAbsenceResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => (int) ($this['id'] ?? 0),
'user_id' => (int) ($this['user_id'] ?? 0),
'date' => (string) ($this['date'] ?? ''),
'semester' => $this['semester'] ?? null,
'school_year' => $this['school_year'] ?? null,
'status' => $this['status'] ?? null,
'reason' => $this['reason'] ?? null,
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources\Teachers;
use Illuminate\Http\Resources\Json\JsonResource;
class TeacherAssignmentResource extends JsonResource
{
public function toArray($request): array
{
return [
'teacher_id' => (int) ($this['teacher_id'] ?? 0),
'firstname' => (string) ($this['firstname'] ?? ''),
'lastname' => (string) ($this['lastname'] ?? ''),
'name' => (string) ($this['name'] ?? ''),
'email' => $this['email'] ?? null,
'cellphone' => $this['cellphone'] ?? null,
'role' => $this['role'] ?? null,
'school_year' => $this['school_year'] ?? null,
'main_assignments' => $this['main_assignments'] ?? [],
'ta_assignments' => $this['ta_assignments'] ?? [],
];
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources\Teachers;
use Illuminate\Http\Resources\Json\JsonResource;
class TeacherClassResource extends JsonResource
{
public function toArray($request): array
{
return [
'class_section_id' => (int) ($this['class_section_id'] ?? 0),
'class_section_name' => (string) ($this['class_section_name'] ?? ''),
'class_id' => $this['class_id'] ?? null,
'class_name' => $this['class_name'] ?? null,
'teacher_role' => $this['teacher_role'] ?? null,
'school_year' => $this['school_year'] ?? null,
'semester' => $this['semester'] ?? null,
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources\Teachers;
use Illuminate\Http\Resources\Json\JsonResource;
class TeacherStudentResource extends JsonResource
{
public function toArray($request): array
{
return [
'student_id' => (int) ($this['student_id'] ?? 0),
'firstname' => (string) ($this['firstname'] ?? ''),
'lastname' => (string) ($this['lastname'] ?? ''),
'school_id' => $this['school_id'] ?? null,
'is_new' => $this['is_new'] ?? null,
'photo_consent' => $this['photo_consent'] ?? null,
'age' => $this['age'] ?? null,
'school_year' => $this['school_year'] ?? null,
'class_section_id' => $this['class_section_id'] ?? null,
'medical_conditions' => $this['medical_conditions'] ?? [],
'allergies' => $this['allergies'] ?? [],
'medical_conditions_text' => $this['medical_conditions_text'] ?? '',
'allergies_text' => $this['allergies_text'] ?? '',
];
}
}