Skip to content

Commit be47256

Browse files
committed
Update catalog example.
1 parent 993f723 commit be47256

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

httprpc-test/src/main/java/org/httprpc/test/CatalogService.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public List<Item> getItems() {
8282
public int addItem(String description, double price) {
8383
items.add(new Item(description, price));
8484

85-
return items.size() - 1;
85+
return items.size();
8686
}
8787

8888
@RequestMethod("GET")
@@ -106,22 +106,12 @@ public void updateItem(String description, double price) {
106106
int itemID = Integer.parseInt(getKey("itemID"));
107107

108108
if (itemID > 0 && itemID <= items.size()) {
109-
Item item = items.get(itemID);
109+
Item item = items.get(itemID - 1);
110110

111111
item.setDescription(description);
112112
item.setPrice(price);
113113
} else {
114114
throw new IllegalArgumentException("Item not found.");
115115
}
116116
}
117-
118-
@RequestMethod("DELETE")
119-
@ResourcePath("items/?:itemID")
120-
public void deleteItem() {
121-
int itemID = Integer.parseInt(getKey("itemID"));
122-
123-
if (itemID > 0 && itemID <= items.size()) {
124-
items.remove(itemID);
125-
}
126-
}
127117
}

httprpc-test/src/main/resources/org/httprpc/test/CatalogService.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ addItem = Adds a new item to the catalog.
44
addItem.description = The item's description.
55
addItem.price = The price of the item.
66
getItem = Returns a single item.
7-
updateItem = Updates an item in the catalog.
7+
updateItem = Updates an item.
88
updateItem.description = The item's description.
99
updateItem.price = The price of the item.
10-
deleteItem = Deletes an item from the catalog.

httprpc-test/src/main/webapp/index.jsp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,41 @@
2424
<a href="${pageContext.request.contextPath}/catalog?api">Catalog (API)</a><br/>
2525
<br/>
2626
<a href="${pageContext.request.contextPath}/catalog/items">Items</a><br/>
27+
28+
<br/>
29+
30+
<form action="${pageContext.request.contextPath}/catalog/items" method="post" enctype="application/x-www-form-urlencoded">
31+
<table>
32+
<tr>
33+
<td>Description</td><td><input type="text" name="description"/></td>
34+
</tr>
35+
<tr>
36+
<td>Price</td><td><input type="text" name="price"/></td>
37+
</tr>
38+
<tr>
39+
<td colspan="2"><input type="submit" value="Add Item"/></td>
40+
</tr>
41+
</table>
42+
</form>
43+
2744
<a href="${pageContext.request.contextPath}/catalog/items/1">Item 1</a><br/>
2845

46+
<br/>
47+
48+
<form action="${pageContext.request.contextPath}/catalog/items/1" method="post" enctype="application/x-www-form-urlencoded">
49+
<table>
50+
<tr>
51+
<td>Description</td><td><input type="text" name="description"/></td>
52+
</tr>
53+
<tr>
54+
<td>Price</td><td><input type="text" name="price"/></td>
55+
</tr>
56+
<tr>
57+
<td colspan="2"><input type="submit" value="Update Item 1"/></td>
58+
</tr>
59+
</table>
60+
</form>
61+
2962
<hr/>
3063

3164
<a href="${pageContext.request.contextPath}/upload?api">Upload (API)</a><br/>

0 commit comments

Comments
 (0)