package com.example.projectback.controllers; import com.example.projectback.model.Student; import com.example.projectback.repository.StudentRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @CrossOrigin(origins = "http://localhost:4200") @RequestMapping("/students") public class StudentController { private final StudentRepository studentRepository; @Autowired public StudentController(StudentRepository studentRepository) {this.studentRepository = studentRepository;} @GetMapping public List getAllStudents() {return studentRepository.findAll();} @PostMapping public ResponseEntity addStudent(@RequestBody Student student) { studentRepository.save(student); return new ResponseEntity<>(student, HttpStatus.CREATED); } }