-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStudentController.java
More file actions
54 lines (38 loc) · 1.32 KB
/
StudentController.java
File metadata and controls
54 lines (38 loc) · 1.32 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
49
50
51
52
53
54
package com.example.cgn221springstudent.controller;
import com.example.cgn221springstudent.model.Student;
import com.example.cgn221springstudent.service.StudentService;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
@RestController
@RequestMapping("student")
public class StudentController {
private final StudentService service;
public StudentController(StudentService service) {
this.service = service;
}
@GetMapping
public List<Student> getAllStudents() {
return List.of(new Student("Berta", "7112"), new Student("Paul", "4711"));
}
@GetMapping(path = "{id}") //localhost:8080/student/0000
public Student getStudentById(@PathVariable String id) {
return service.getStudentById(id);
}
@PostMapping
public Student addStudent(@RequestBody Student student) {
return service.addStudent(student);
}
@GetMapping("allStudents")
public List<Student> listAllStudents() {
return service.getAllStudents();
}
@DeleteMapping(path = "{id}")
public Student deleteStudent(@PathVariable String id) {
return service.deleteStudent(id);
}
@PutMapping
public Student updateStudent(@RequestBody Student student) {
return service.updateStudent(student);
}
}