031e499819
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
258 lines
8.4 KiB
PHP
258 lines
8.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\SchoolYears;
|
|
|
|
use App\Http\Controllers\Api\Core\BaseApiController;
|
|
use App\Http\Requests\SchoolYears\CloseSchoolYearRequest;
|
|
use App\Http\Requests\SchoolYears\PreviewCloseSchoolYearRequest;
|
|
use App\Http\Requests\SchoolYears\SaveSchoolYearRequest;
|
|
use App\Services\SchoolYears\SchoolYearClosureService;
|
|
use App\Services\SchoolYears\SchoolYearContextService;
|
|
use App\Services\SchoolYears\SelectedSchoolYearContextService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class SchoolYearController extends BaseApiController
|
|
{
|
|
public function __construct(
|
|
private SchoolYearClosureService $service,
|
|
private SchoolYearContextService $context,
|
|
private SelectedSchoolYearContextService $selectedSchoolYear
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$context = $this->context->options(
|
|
$request->query('school_year'),
|
|
$request->query('semester')
|
|
);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->list(),
|
|
'meta' => $context,
|
|
'school_years' => $context['school_years'],
|
|
'current_school_year' => $context['current_school_year'],
|
|
'current_semester' => $context['current_semester'],
|
|
]);
|
|
}
|
|
|
|
public function current(Request $request): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->context->options(
|
|
$request->query('school_year'),
|
|
$request->query('semester')
|
|
),
|
|
]);
|
|
}
|
|
|
|
public function options(Request $request): JsonResponse
|
|
{
|
|
return $this->current($request);
|
|
}
|
|
|
|
public function store(SaveSchoolYearRequest $request): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->createYear($request->validated(), $this->getCurrentUserId()),
|
|
], Response::HTTP_CREATED);
|
|
}
|
|
|
|
public function update(SaveSchoolYearRequest $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->updateYear($schoolYear, $request->validated(), $this->getCurrentUserId()),
|
|
]);
|
|
}
|
|
|
|
public function updateSelected(SaveSchoolYearRequest $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->updateYear($selected->id, $request->validated(), $this->getCurrentUserId()),
|
|
]);
|
|
}
|
|
|
|
public function summary(int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json(['ok' => true, 'data' => $this->service->summary($schoolYear)]);
|
|
}
|
|
|
|
public function summarySelected(Request $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json(['ok' => true, 'data' => $this->service->summaryByYearName($selected->name)]);
|
|
}
|
|
|
|
public function validateClose(PreviewCloseSchoolYearRequest $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'validation' => $this->service->validateClose($schoolYear, $request->validated()),
|
|
]);
|
|
}
|
|
|
|
public function validateCloseSelected(PreviewCloseSchoolYearRequest $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'validation' => $this->service->validateCloseByYearName($selected->name, $request->validated()),
|
|
]);
|
|
}
|
|
|
|
public function previewClose(PreviewCloseSchoolYearRequest $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->previewClose($schoolYear, $request->validated()),
|
|
]);
|
|
}
|
|
|
|
public function previewCloseSelected(PreviewCloseSchoolYearRequest $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->previewCloseByYearName($selected->name, $request->validated()),
|
|
]);
|
|
}
|
|
|
|
public function close(CloseSchoolYearRequest $request, int $schoolYear): JsonResponse
|
|
{
|
|
try {
|
|
$result = $this->service->close($schoolYear, $request->validated(), $this->getCurrentUserId());
|
|
} catch (ValidationException $e) {
|
|
throw $e;
|
|
} catch (\Throwable $e) {
|
|
return response()->json([
|
|
'ok' => false,
|
|
'message' => $e->getMessage(),
|
|
], Response::HTTP_CONFLICT);
|
|
}
|
|
|
|
return response()->json(['ok' => true, 'data' => $result]);
|
|
}
|
|
|
|
public function closeSelected(CloseSchoolYearRequest $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
try {
|
|
$result = $this->service->closeByYearName($selected->name, $request->validated(), $this->getCurrentUserId());
|
|
} catch (ValidationException $e) {
|
|
throw $e;
|
|
} catch (\Throwable $e) {
|
|
return response()->json([
|
|
'ok' => false,
|
|
'message' => $e->getMessage(),
|
|
], Response::HTTP_CONFLICT);
|
|
}
|
|
|
|
return response()->json(['ok' => true, 'data' => $result]);
|
|
}
|
|
|
|
public function reopen(Request $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->reopen($schoolYear, $this->getCurrentUserId()),
|
|
]);
|
|
}
|
|
|
|
public function reopenSelected(Request $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->reopenByYearName($selected->name, $this->getCurrentUserId()),
|
|
]);
|
|
}
|
|
|
|
public function parentBalances(Request $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->parentBalances($schoolYear, $request->query('to_school_year')),
|
|
]);
|
|
}
|
|
|
|
public function parentBalancesSelected(Request $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->parentBalancesByYearName($selected->name, $request->query('to_school_year')),
|
|
]);
|
|
}
|
|
|
|
public function promotionPreview(Request $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->promotionPreview($schoolYear, $request->query('to_school_year')),
|
|
]);
|
|
}
|
|
|
|
public function promotionPreviewSelected(Request $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->promotionPreviewByYearName($selected->name, $request->query('to_school_year')),
|
|
]);
|
|
}
|
|
|
|
public function closingReport(int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->closingReport($schoolYear),
|
|
]);
|
|
}
|
|
|
|
public function closingReportSelected(Request $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->closingReportByYearName($selected->name),
|
|
]);
|
|
}
|
|
|
|
public function archive(Request $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->archive($schoolYear, $this->getCurrentUserId()),
|
|
]);
|
|
}
|
|
|
|
public function archiveSelected(Request $request): JsonResponse
|
|
{
|
|
$selected = $this->selectedSchoolYear->fromRequest($request);
|
|
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->archiveByYearName($selected->name, $this->getCurrentUserId()),
|
|
]);
|
|
}
|
|
}
|