package com.example.demo.controller;
import com.example.demo.entities.Student;
import com.example.demo.services.StudentService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping("/api/students")
public class StudentController {
private final StudentService studentService;
public StudentController(StudentService studentService)
{
this.studentService = studentService;
}
public Mono<Student>
saveStudent(@RequestBody Student student)
{
return studentService.saveStudent(student);
}
@GetMapping public Flux<Student> getAllStudents()
{
return studentService.getAllStudents();
}
@GetMapping("/{id}")
public Mono<Student>
getStudentById(@PathVariable String id)
{
return studentService.getStudentById(id);
}
@PostMapping
public Mono<Student>
createStudent(@RequestBody Student student)
{
return studentService.saveStudent(student);
}
@DeleteMapping("/{id}")
public Mono<Void> deleteStudent(@PathVariable String id)
{
return studentService.deleteStudent(id);
}
}