-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentController.java
47 lines (39 loc) · 1.48 KB
/
StudentController.java
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
package com.burakkutbay.springdataredisproject.controller;
import com.burakkutbay.springdataredisproject.model.Student;
import com.burakkutbay.springdataredisproject.service.StudentService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@AllArgsConstructor
public class StudentController {
@Autowired
private StudentService studentService;
@GetMapping("/student")
public List<Student> getAllStudent() {
return studentService.getAllStudent();
}
@Cacheable(value = "student", key = "#id")
@GetMapping("/student/{id}")
public Student getStudent(@PathVariable("id") Integer id) {
return studentService.findById(id);
}
@CacheEvict(value = "student", key="#id")
@DeleteMapping("/student/{id}")
public void deleteStudent(@PathVariable("id") Integer id) {
studentService.deleteStudent(id);
}
@PostMapping("/student")
public void saveStudent(@RequestBody Student student) {
studentService.saveStudent(student);
}
@CachePut(value = "student", key = "#student.id")
@PutMapping("/student/update")
public void updateStudent(@RequestBody Student student) {
studentService.updateStudent(student);
}
}