UserRestController.java
2.07 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
package fr.plil.sio.web.mvc;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
public class UserRestController {
@Resource
private UserService userService;
@RequestMapping(value = "/api/users/", method = RequestMethod.GET)
public List<User> listUsers() {
return userService.findAll();
}
@RequestMapping(value="/api/connectedUser/",method=RequestMethod.GET)
public User connectedUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User usr = (User)authentication.getPrincipal();
return usr;
}
@RequestMapping(value = "/api/users/{username}/", method = RequestMethod.GET)
public User listUsers(@PathVariable String username) {
return userService.findByUsername(username);
}
@RequestMapping(value = "/api/debts/", method = RequestMethod.GET)
public List<Dette> listDettes() {
return userService.findDettes();
}
@RequestMapping(value = "/api/creances/", method = RequestMethod.GET)
public List<Dette> listCreances(){
return userService.findCreances();
}
@RequestMapping(value = "/api/addDette/", method = RequestMethod.POST)
public Dette addDette(@RequestParam(value="username",required=false) String username,@RequestParam(value="sommeDette",required=false) String sommeDette) {
return userService.addDette(username,sommeDette);
}
@RequestMapping(value="/api/deleteDette/{id}",method=RequestMethod.DELETE)
public String deleteDette(@PathVariable("id") String id){
return userService.deleteDette(id);
}
}