File tree 2 files changed +15
-4
lines changed
2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package routes
2
2
3
3
import (
4
4
"encoding/json"
5
- "fmt"
6
5
"io/ioutil"
7
6
"log"
8
7
"net/http"
@@ -71,8 +70,21 @@ func delete(w http.ResponseWriter, r *http.Request) {
71
70
if err != nil {
72
71
log .Println ("error:" , err )
73
72
}
74
- fmt .Println ("delete: " + element .Query )
75
-
73
+ var indexDelete int
74
+ for i , item := range itemsBunch .Items {
75
+ if item .Name == element .Query {
76
+ indexDelete = i
77
+ }
78
+ }
79
+ var emptyItem Item
80
+ copy (itemsBunch .Items [indexDelete :], itemsBunch .Items [indexDelete + 1 :])
81
+ itemsBunch .Items [len (itemsBunch .Items )- 1 ] = emptyItem
82
+ itemsBunch .Items = itemsBunch .Items [:len (itemsBunch .Items )- 1 ]
83
+ itemsBunch .Total = 0
84
+ for index := range itemsBunch .Items {
85
+ totalProduct := productTotalPrice (itemsBunch .Items [index ].Price , itemsBunch .Items [index ].Quantity )
86
+ itemsBunch .Total = newTotal (itemsBunch .Total , totalProduct )
87
+ }
76
88
if err := json .NewEncoder (w ).Encode (itemsBunch ); err != nil {
77
89
panic (err )
78
90
}
Original file line number Diff line number Diff line change @@ -74,7 +74,6 @@ <h4 class="modal-title custom_align" id="Heading">Add Item</h4>
74
74
</ div >
75
75
76
76
77
-
78
77
<!------ Modal edit ---------->
79
78
< div class ="modal fade " id ="edit " tabindex ="-1 " role ="dialog " aria-labelledby ="edit " aria-hidden ="true ">
80
79
< div class ="modal-dialog ">
You can’t perform that action at this time.
0 commit comments