-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathStudentController.java
More file actions
48 lines (36 loc) · 1.57 KB
/
Copy pathStudentController.java
File metadata and controls
48 lines (36 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.wasim.rest.api.controller;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.wasim.rest.api.entity.Student;
import com.wasim.rest.api.service.StudentService;
@RestController
@RequestMapping("/api/")
public class StudentController {
@Autowired
private StudentService studentService;
@PostMapping("/saveStudent")
public ResponseEntity<Student> createStudent(@RequestBody Student student) {
return new ResponseEntity<Student>(studentService.createStudent(student), HttpStatus.CREATED);
}
@GetMapping("/getAllStudent")
public ResponseEntity<List<Student>> getAllStudent(){
return new ResponseEntity<List<Student>>(studentService.getAllStudent(), HttpStatus.OK);
}
@GetMapping("/getStudent/{id}")
public ResponseEntity<Student> getStudentById(@PathVariable long id){
return new ResponseEntity<Student>(studentService.getStudentById(id), HttpStatus.OK);
}
@PutMapping("/editStudent/{id}")
public ResponseEntity<Student> updateStudent(@PathVariable long id, @RequestBody Student student){
return new ResponseEntity<Student>(studentService.updateStudent(id, student), HttpStatus.OK);
}
@DeleteMapping("/deleteStudent/{id}")
public ResponseEntity<HttpStatus> deleteStudent(@PathVariable("id") long id){
studentService.deleteStudent(id);
return new ResponseEntity<HttpStatus>(HttpStatus.OK);
}
}