update emergency contact student controller

This commit is contained in:
root
2026-03-25 17:59:40 -04:00
parent 33be0c9a0d
commit c582bfc242
11 changed files with 179 additions and 16 deletions
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api\Administrator;
use App\Http\Controllers\Controller;
use App\Http\Requests\EmergencyContacts\EmergencyContactParentRequest;
use App\Http\Requests\EmergencyContacts\EmergencyContactUpdateRequest;
use App\Http\Resources\EmergencyContacts\EmergencyContactGroupResource;
use App\Http\Resources\EmergencyContacts\EmergencyContactResource;
@@ -28,9 +29,10 @@ class EmergencyContactController extends Controller
]);
}
public function update(EmergencyContactUpdateRequest $request, int $contactId): JsonResponse
public function show(EmergencyContactParentRequest $request, int $contactId): JsonResponse
{
$contact = $this->crudService->update($contactId, $request->validated());
$parentId = (int) $request->validated()['parent_id'];
$contact = $this->crudService->findForParent($contactId, $parentId);
return response()->json([
'ok' => true,
@@ -38,9 +40,21 @@ class EmergencyContactController extends Controller
]);
}
public function destroy(int $contactId): JsonResponse
public function update(EmergencyContactUpdateRequest $request, int $contactId): JsonResponse
{
$this->crudService->delete($contactId);
$payload = $request->validated();
$contact = $this->crudService->update($contactId, (int) $payload['parent_id'], $payload);
return response()->json([
'ok' => true,
'contact' => new EmergencyContactResource($contact),
]);
}
public function destroy(EmergencyContactParentRequest $request, int $contactId): JsonResponse
{
$parentId = (int) $request->validated()['parent_id'];
$this->crudService->delete($contactId, $parentId);
return response()->json(['ok' => true]);
}
@@ -58,4 +58,17 @@ class ConfigurationAdminController extends BaseApiController
return response()->json(['ok' => true]);
}
public function getByKey(string $configKey): JsonResponse
{
$config = $this->service->getByKey($configKey);
if (!$config) {
return response()->json(['ok' => false, 'message' => 'Configuration not found.'], 404);
}
return response()->json([
'ok' => true,
'config' => new ConfigurationResource($config->toArray()),
]);
}
}
@@ -123,7 +123,6 @@ class StudentController extends BaseApiController
'parent_id',
'registration_date',
'tuition_paid',
'rfid_tag',
'semester',
'year_of_registration',
'school_year',
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Requests\EmergencyContacts;
use App\Http\Requests\ApiFormRequest;
class EmergencyContactParentRequest extends ApiFormRequest
{
public function rules(): array
{
return [
'parent_id' => ['required', 'integer', 'min:1'],
];
}
}
@@ -9,6 +9,7 @@ class EmergencyContactUpdateRequest extends ApiFormRequest
public function rules(): array
{
return [
'parent_id' => ['required', 'integer', 'min:1'],
'name' => ['required', 'string', 'max:150'],
'cellphone' => ['required', 'string', 'max:30'],
'email' => ['nullable', 'email', 'max:150'],