-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentController.java
More file actions
96 lines (79 loc) · 3.57 KB
/
Copy pathStudentController.java
File metadata and controls
96 lines (79 loc) · 3.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.dc14.controller;
import com.dc14.entity.Student;
import com.dc14.service.StudentService;
import lombok.AllArgsConstructor;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/student")
@AllArgsConstructor
@Log
public class StudentController {
private final StudentService studentService;
@PostMapping("/create")
public Student createStudent(@RequestBody Student student) {
log.info("Creating the new student");
return studentService.createStudent(student);
}
@GetMapping("/getById/{id}")
public Student getStudentById(@PathVariable String id) {
log.info(String.format("Getting the student by id: %s", id));
return studentService.getStudentById(id);
}
@GetMapping("/all")
public List<Student> getAllStudents() {
log.info("Getting all students");
return studentService.getAllStudents();
}
@PutMapping("/update")
public Student updateStudent(@RequestBody Student student) {
log.info(String.format("Updating the student: %s", student.getId()));
return studentService.updateStudent(student);
}
@DeleteMapping("/delete/{id}")
public String deleteStudent(@PathVariable String id) {
log.info(String.format("Removing the student: %s", id));
return studentService.deleteStudent(id);
}
@GetMapping("/studentsByName/{name}")
public List<Student> getStudentsByName(@PathVariable String name) {
log.info(String.format("Getting the student by name: %s", name));
return studentService.getStudentsByName(name);
}
@GetMapping("/studentsByNameAndMail")
public List<Student> getStudentsByNameAndMail(@RequestParam String name, @RequestParam String email) {
log.info(String.format("Getting the student by name: %s AND email: %s", name, email));
return studentService.studentsByNameAndMail(name, email);
}
@GetMapping("/studentsByNameOrMail")
public List<Student> getStudentsByNameOrMail(@RequestParam String name, @RequestParam String email) {
log.info(String.format("Getting the student by name: %s OR email: %s", name, email));
return studentService.getStudentsByNameOrMail(name, email);
}
@GetMapping("/allWithPagination")
public List<Student> getAllWithPagination(@RequestParam int pageNo, @RequestParam int pageSize) {
log.info(String.format("Getting students on page: %d, pageSize: %d", pageNo, pageSize));
return studentService.getAllWithPagination(pageNo, pageSize);
}
@GetMapping("/allWithSortingByName")
public List<Student> getAllWithSortingByName() {
log.info("Getting all students sorting by name");
return studentService.getAllWithSortingByName();
}
@GetMapping("/allByEmailLike")
public List<Student> getAllByEmailLike(@RequestParam String email) {
log.info(String.format("Getting all students by email LIKE: %s", email));
return studentService.getAllByEmailLike(email);
}
@GetMapping("/allByNameStartsWith")
public List<Student> getAllByNameStartsWith(@RequestParam String name) {
log.info(String.format("Getting all students by name STARTS WITH: %s", name));
return studentService.getAllByNameStartsWith(name);
}
@GetMapping("/allByDepartmentId")
public List<Student> getAllByDepartmentId(@RequestParam String departmentId) {
log.info(String.format("Getting all students by department id: %s", departmentId));
return studentService.getAllByDepartmentId(departmentId);
}
}