8000 DeleteItem · blackbeltcoder/Todoo@6ee2856 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ee2856

Browse files
author
genio
committed
DeleteItem
1 parent 152ef2e commit 6ee2856

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

src/main/java/com/sar/sandpit/ItemController.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public String addItem(Model model){
8383
// return a
8484
// }
8585

86+
private void test() {
87+
// Long i =1L;
88+
}
8689

8790

8891

@@ -96,12 +99,12 @@ public String items(ModelMap modalMap){
9699
//return "todo/items";
97100
}
98101

99-
@PostMapping(value = "/deleteItem/{id}")
102+
@GetMapping(value = "/deleteItem/{id}")
100103
public String deleteItem( @PathVariable Long id, ModelMap model ){
101-
itemService.delete(1L);
104+
itemService.delete(id);
102105

103106
//return null;
104107
//return "redirect:todo/items";
105-
return "todo/items";
108+
return "redirect:/todo/items";
106109
}
107110
}

src/main/java/com/sar/sandpit/ItemService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public List<Item> getItems() {
4444

4545
@Override
4646
public boolean delete(Long id) {
47-
return false;
47+
itemStore.delete(id);
48+
return itemStore.exists(id);
4849
}
4950

5051
@Override

src/main/resources/templates/todo/addItem.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
<p>Message: <input type="text" th:field="*{details}" /></p>
1414
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
1515
</form>
16+
17+
<p><a th:href="@{/todo/items/}">items</a></p>
1618
</html>

src/main/resources/templates/todo/addItemResult.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
<body>
99
<p th:text="'id ='+ ${item.id} + ' task = '+ ${item.details}"/>
1010
<p th:text="'id ='+ ${itemDto.id} + ' task = '+ ${itemDto.details}"/>
11+
<p><a th:href="@{/todo/addItem/}">Add Another</a></p>
12+
<p><a th:href="@{/todo/items/}">items</a></p>
1113
</body>
1214
</html>

src/main/resources/templates/todo/items.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,32 @@
1212
<p th:text="'test 2 = '+ ${test}">not empty</p>
1313
<p th:text="'items count = '+${items.size()} "></p>
1414

15+
<p><a th:href="@{/todo/deleteItem/{items}/}">
16+
the items </a></p>
1517
<table>
1618
<thead>
1719
<tr>
1820
<th>ids</th>
1921
<th>detail snippet </th>
22+
<th>actions</th>
2023
</tr>
2124
</thead>
2225
<tbody>
2326
<tr th:each="item: ${items}" >
2427
<td th:text="${item.id} "> </td>
2528
<td th:text="${item.details}"></td>
29+
<td th:href="@{/todo/deleteItem/{item}}">
30+
delete2
31+
<a th:href="@{'/todo/deleteItem/'+${item.id}+'/'}">
32+
delete</a>
33+
</td>
2634
</tr>
2735
</tbody>
2836
</table>
37+
<p><a th:href="@{/todo/addItem/}">add item</a>
38+
</p>
39+
40+
2941

3042

3143
</body>

src/test/java/com/sar/sandpit/ItemControllerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public void deleteItemByItem_GivenItemToDelete_Success() throws Exception {
218218
public void deleteItemById_GivenItemToDelete_Success() throws Exception {
219219
Long id =1L;
220220
when(itemServiceable.delete(id)).thenReturn(true);
221-
mockMvc.perform(post(TODO_DELETE_ITEM_URL +id))
222-
.andExpect(status().isOk())
221+
mockMvc.perform(get(TODO_DELETE_ITEM_URL +id))
222+
.andExpect(status().is3xxRedirection())
223223
.andDo(print())
224224
.andReturn()
225225
;
@@ -232,10 +232,10 @@ public void deleteItemById_GivenItemToDelete_Success() throws Exception {
232232
@Test
233233
public void deleteItemById_GivenItemToDelete_ReturnsSuccessPage() throws Exception {
234234
Long id =1L;
235-
mockMvc.perform(post(TODO_DELETE_ITEM_URL +id))
236-
.andExpect(status().isOk())
237-
.andExpect(view().name(is("todo/items")))
238-
.andExpect(forwardedUrl("todo/items"))
235+
mockMvc.perform(get(TODO_DELETE_ITEM_URL +id))
236+
.andExpect(status().is3xxRedirection())
237+
// .andExpect(view().name(is("todo/items")))
238+
// .andExpect(forwardedUrl("/todo/items"))
239239
.andDo(print())
240240
.andReturn()
241241
;

src/test/java/com/sar/sandpit/ItemServiceTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ public void deleteTaskItem_returnTrue() throws Exception {
102102
verify(itemStorable).exists(id);
103103
}
104104

105+
@Test
106+
public void deleteTaskItemById_returnsTrue() throws Exception {
107+
final Long id = 1L;
108+
when(itemStorable.exists(id)).thenReturn(true);
109+
boolean res = itemService.delete(id);
110+
assertThat("should be true ",res,is(equalTo(true)));
111+
verify(itemStorable, times(1)).exists(idCapture.capture());
112+
113+
114+
}
115+
116+
105117
//////////////////////////////
106118
//todo update single item
107119
/////////////////////////////

0 commit comments

Comments
 (0)
0