StudentResponsibleController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Services\StudentResponsibleService;
  4. use App\Http\Requests\StudentResponsibleRequest;
  5. use App\Http\Resources\StudentResponsibleResource;
  6. use Illuminate\Http\JsonResponse;
  7. class StudentResponsibleController extends Controller
  8. {
  9. public function __construct(
  10. protected StudentResponsibleService $service,
  11. ) {}
  12. public function getByStudent(int $studentId): JsonResponse
  13. {
  14. $item = $this->service->getByStudentId($studentId);
  15. return $this->successResponse(payload: $item ? new StudentResponsibleResource($item) : null);
  16. }
  17. public function store(StudentResponsibleRequest $request): JsonResponse
  18. {
  19. $item = $this->service->create($request->validated());
  20. return $this->successResponse(payload: new StudentResponsibleResource($item), message: __('messages.created'), code: 201);
  21. }
  22. public function update(StudentResponsibleRequest $request, int $id): JsonResponse
  23. {
  24. $item = $this->service->update($id, $request->validated());
  25. return $this->successResponse(payload: new StudentResponsibleResource($item), message: __('messages.updated'));
  26. }
  27. public function destroy(int $id): JsonResponse
  28. {
  29. $this->service->delete($id);
  30. return $this->successResponse(message: __('messages.deleted'), code: 204);
  31. }
  32. }