fix apply the plan docs/alrahma_api_fix_plan_school_year_only_v7
API CI/CD / Validate (composer + pint) (push) Successful in 3m10s
API CI/CD / Test (PHPUnit) (push) Failing after 6m49s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 1m0s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m10s
API CI/CD / Test (PHPUnit) (push) Failing after 6m49s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 1m0s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Family;
|
||||
|
||||
use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Services\Families\ParentProfileAdminQueryService;
|
||||
use App\Services\SchoolYears\SelectedSchoolYearContextService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ParentProfileAdminController extends BaseApiController
|
||||
{
|
||||
public function __construct(
|
||||
private ParentProfileAdminQueryService $profiles,
|
||||
private SelectedSchoolYearContextService $schoolYears,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
if ($request->has('school_year_id')) {
|
||||
return $this->error('Use school_year by name; school_year_id is not accepted.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
$context = $this->schoolYears->fromRequest($request);
|
||||
$page = $this->profiles->index(
|
||||
$context->name,
|
||||
trim((string) $request->query('q', '')),
|
||||
(int) $request->query('per_page', 25),
|
||||
);
|
||||
|
||||
return $this->success([
|
||||
'school_year' => $context->name,
|
||||
'read_only' => $context->isReadOnly,
|
||||
'parents' => $page->getCollection()
|
||||
->map(fn ($row) => $this->profiles->parentSummary((array) $row, $context->name))
|
||||
->values()
|
||||
->all(),
|
||||
'pagination' => [
|
||||
'page' => $page->currentPage(),
|
||||
'per_page' => $page->perPage(),
|
||||
'total' => $page->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request): JsonResponse
|
||||
{
|
||||
if ($request->has('school_year_id')) {
|
||||
return $this->error('Use school_year by name; school_year_id is not accepted.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
$context = $this->schoolYears->fromRequest($request);
|
||||
|
||||
return $this->success([
|
||||
'school_year' => $context->name,
|
||||
'read_only' => $context->isReadOnly,
|
||||
'items' => $this->profiles->search(
|
||||
$context->name,
|
||||
trim((string) $request->query('q', '')),
|
||||
(int) $request->query('limit', 10),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, int $parent): JsonResponse
|
||||
{
|
||||
if ($request->has('school_year_id')) {
|
||||
return $this->error('Use school_year by name; school_year_id is not accepted.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
$context = $this->schoolYears->fromRequest($request);
|
||||
$payload = $this->profiles->show($parent, $context->name);
|
||||
|
||||
if (! $payload) {
|
||||
return $this->error('Parent profile not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'school_year' => $context->name,
|
||||
'read_only' => $context->isReadOnly,
|
||||
...$payload,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $parent): JsonResponse
|
||||
{
|
||||
if ($request->has('school_year_id')) {
|
||||
return $this->error('Use school_year by name; school_year_id is not accepted.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
$payload = $request->validate([
|
||||
'firstname' => ['sometimes', 'required', 'string', 'max:100'],
|
||||
'lastname' => ['sometimes', 'required', 'string', 'max:100'],
|
||||
'email' => ['sometimes', 'nullable', 'email', 'max:255'],
|
||||
'cellphone' => ['sometimes', 'nullable', 'string', 'max:30'],
|
||||
'address_street' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||
'city' => ['sometimes', 'nullable', 'string', 'max:100'],
|
||||
'state' => ['sometimes', 'nullable', 'string', 'max:100'],
|
||||
'zip' => ['sometimes', 'nullable', 'string', 'max:30'],
|
||||
'status' => ['sometimes', 'nullable', 'string', 'max:30'],
|
||||
]);
|
||||
|
||||
$updated = $this->profiles->updateParent($parent, $payload);
|
||||
if (! $updated) {
|
||||
return $this->error('Parent profile not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
return $this->success(['parent' => $updated], 'Parent profile updated.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user