forked from Realhedin/topjava02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminAjaxController.java
More file actions
53 lines (45 loc) · 1.69 KB
/
AdminAjaxController.java
File metadata and controls
53 lines (45 loc) · 1.69 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
package ru.javawebinar.topjava.web.user;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import ru.javawebinar.topjava.model.User;
import ru.javawebinar.topjava.to.UserTo;
import javax.validation.Valid;
import java.util.List;
/**
* User: javawebinar.topjava
*/
@RestController
@RequestMapping("/ajax/admin/users")
public class AdminAjaxController extends AbstractUserController {
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<User> getAll() {
return super.getAll();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public User get(@PathVariable("id") int id) {
return super.get(id);
}
@RequestMapping(value = "/{id}/enable", method = RequestMethod.POST)
public void enable(@PathVariable("id") int id, @RequestParam("enabled") boolean enabled) {
super.enable(id, enabled);
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void delete(@PathVariable("id") int id) {
super.delete(id);
}
@RequestMapping(method = RequestMethod.POST)
public void createOrUpdate(@Valid UserTo userTo, BindingResult result, SessionStatus status) {
if (result.hasErrors()) {
throw LOG.getValidationException(result);
} else {
status.setComplete();
if (userTo.getId() == 0) {
create(userTo);
} else {
update(userTo, userTo.getId());
}
}
}
}