-
Notifications
You must be signed in to change notification settings - Fork 45
/
ToppingController_Roo_Controller_Json.aj
95 lines (84 loc) · 4.44 KB
/
ToppingController_Roo_Controller_Json.aj
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
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package com.springsource.pizzashop;
import com.springsource.pizzashop.ToppingController;
import com.springsource.pizzashop.domain.Topping;
import java.util.List;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
privileged aspect ToppingController_Roo_Controller_Json {
@RequestMapping(value = "/{id}", headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> ToppingController.showJson(@PathVariable("id") Long id) {
Topping topping = Topping.findTopping(id);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
if (topping == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(topping.toJson(), headers, HttpStatus.OK);
}
@RequestMapping(headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> ToppingController.listJson() {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
List<Topping> result = Topping.findAllToppings();
return new ResponseEntity<String>(Topping.toJsonArray(result), headers, HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
public ResponseEntity<String> ToppingController.createFromJson(@RequestBody String json) {
Topping topping = Topping.fromJsonToTopping(json);
topping.persist();
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
return new ResponseEntity<String>(headers, HttpStatus.CREATED);
}
@RequestMapping(value = "/jsonArray", method = RequestMethod.POST, headers = "Accept=application/json")
public ResponseEntity<String> ToppingController.createFromJsonArray(@RequestBody String json) {
for (Topping topping: Topping.fromJsonArrayToToppings(json)) {
topping.persist();
}
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
return new ResponseEntity<String>(headers, HttpStatus.CREATED);
}
@RequestMapping(method = RequestMethod.PUT, headers = "Accept=application/json")
public ResponseEntity<String> ToppingController.updateFromJson(@RequestBody String json) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
Topping topping = Topping.fromJsonToTopping(json);
if (topping.merge() == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(headers, HttpStatus.OK);
}
@RequestMapping(value = "/jsonArray", method = RequestMethod.PUT, headers = "Accept=application/json")
public ResponseEntity<String> ToppingController.updateFromJsonArray(@RequestBody String json) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
for (Topping topping: Topping.fromJsonArrayToToppings(json)) {
if (topping.merge() == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
}
return new ResponseEntity<String>(headers, HttpStatus.OK);
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, headers = "Accept=application/json")
public ResponseEntity<String> ToppingController.deleteFromJson(@PathVariable("id") Long id) {
Topping topping = Topping.findTopping(id);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
if (topping == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
topping.remove();
return new ResponseEntity<String>(headers, HttpStatus.OK);
}
}