104 lines
3.4 KiB
PHP
104 lines
3.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 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)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index(): JsonResponse
|
|
{
|
|
return response()->json(['ok' => true, 'data' => $this->service->list()]);
|
|
}
|
|
|
|
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 summary(int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json(['ok' => true, 'data' => $this->service->summary($schoolYear)]);
|
|
}
|
|
|
|
public function validateClose(PreviewCloseSchoolYearRequest $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'validation' => $this->service->validateClose($schoolYear, $request->validated()),
|
|
]);
|
|
}
|
|
|
|
public function previewClose(PreviewCloseSchoolYearRequest $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->previewClose($schoolYear, $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 reopen(Request $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->reopen($schoolYear, $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 promotionPreview(Request $request, int $schoolYear): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'ok' => true,
|
|
'data' => $this->service->promotionPreview($schoolYear, $request->query('to_school_year')),
|
|
]);
|
|
}
|
|
}
|