update project
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Students;
|
||||
|
||||
use App\Domain\SchoolCore\Context\SchoolContextStore;
|
||||
use App\Domain\SchoolCore\Students\Contracts\StudentReadServiceContract;
|
||||
use App\Domain\SchoolCore\Students\Contracts\StudentServiceContract;
|
||||
use App\Http\Requests\Students\CreateStudentRequest;
|
||||
use App\Http\Requests\Students\StudentSearchRequest;
|
||||
use App\Http\Requests\Students\StudentStatusTransitionRequest;
|
||||
use App\Http\Requests\Students\UpdateStudentRequest;
|
||||
use App\Http\Resources\V2\Students\StudentResource;
|
||||
use App\Support\Api\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
final class StudentController extends Controller
|
||||
{
|
||||
public function __construct(private readonly SchoolContextStore $context, private readonly StudentServiceContract $students, private readonly StudentReadServiceContract $reader) {}
|
||||
|
||||
public function index(StudentSearchRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->reader->search($this->context->current(), $request->toDTO());
|
||||
return ApiResponse::success($result);
|
||||
}
|
||||
|
||||
public function store(CreateStudentRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->students->createStudent($this->context->current(), $request->toDTO());
|
||||
return ApiResponse::success((new StudentResource($result))->resolve($request), 'Student created.', [], 201);
|
||||
}
|
||||
|
||||
public function show(int $student): JsonResponse
|
||||
{
|
||||
$result = $this->students->getStudent($this->context->current(), $student);
|
||||
return ApiResponse::success((new StudentResource($result))->resolve(request()));
|
||||
}
|
||||
|
||||
public function update(UpdateStudentRequest $request, int $student): JsonResponse
|
||||
{
|
||||
$result = $this->students->updateStudent($this->context->current(), $student, $request->toDTO());
|
||||
return ApiResponse::success((new StudentResource($result))->resolve($request), 'Student updated.');
|
||||
}
|
||||
|
||||
public function transition(StudentStatusTransitionRequest $request, int $student): JsonResponse
|
||||
{
|
||||
$result = $this->students->transitionStatus($this->context->current(), $student, $request->toDTO());
|
||||
return ApiResponse::success((new StudentResource($result))->resolve($request), 'Student status changed.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user