-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaderController.java
More file actions
41 lines (34 loc) · 1.67 KB
/
LeaderController.java
File metadata and controls
41 lines (34 loc) · 1.67 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
package com.example.spring.app.leader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/v1/leader")
public class LeaderController {
@Autowired
private LeaderService leaderService;
// Example: http://localhost:8080/api/v1/leader/get-by-id/123
@GetMapping("/get-by-id/{id}")
public LeaderModel getLeaderById(@PathVariable Integer id) {
return leaderService.getLeaderById(id);
}
// Example: http://localhost:8080/api/v1/leader/get-by-siren?siren=exemple
@GetMapping("/get-by-siren/{siren}")
public List<LeaderModel> getLeaderBySiren(@PathVariable String siren) {
return leaderService.getLeadersBySirens(siren);
}
// Example: http://localhost:8080/api/v1/leader/get-by-first-and-last-name?firstName=exemple&lastName=exemple&page=0
@GetMapping("/get-by-first-and-last-name")
public Page<LeaderModel> getLeadersByName(@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size, Sort.by("id").ascending());
return leaderService.getLeadersByFirstAndLastName(firstName, lastName, pageable);
}
}