@@ -8,19 +8,24 @@ import (
88 "gorm.io/gorm"
99)
1010
11- type GroceryItem struct {
11+ type InventoryItem struct {
1212 gorm.Model
1313 Name string `json:"name"`
1414 Count int `json:"count"`
1515}
1616
17- type CheckboxItem struct {
18- gorm.Model
19- Name string `json:"name"`
20- Checked bool `json:"checked"`
17+ func GetInventoryItems () []InventoryItem {
18+ var items []InventoryItem
19+ result := DBConn .Find (& items )
20+
21+ if result .Error != nil {
22+ panic (result .Error )
23+ }
24+
25+ return items
2126}
2227
23- func GetGroceryItemByName (itemName string ) (string , error ) {
28+ func GetInventoryItemByName (itemName string ) (string , error ) {
2429 name := strings .ToLower (itemName )
2530
2631 if len (name ) <= 0 {
@@ -29,20 +34,20 @@ func GetGroceryItemByName(itemName string) (string, error) {
2934
3035 db := DBConn
3136
32- var item GroceryItem
37+ var item InventoryItem
3338 result := db .Find (& item , "Name = ?" , name )
3439 return result .Name (), result .Error
3540}
3641
37- func CreateGroceryItem (itemName string ) (string , error ) {
42+ func CreateInventoryItem (itemName string ) (string , error ) {
3843 name := strings .ToLower (itemName )
3944
4045 if len (name ) <= 0 {
4146 return "" , errors .New ("please type a grocery item" )
4247 }
4348
4449 db := DBConn
45- item := new (GroceryItem )
50+ item := new (InventoryItem )
4651 item .Name = name
4752 item .Count = 1
4853
@@ -51,10 +56,10 @@ func CreateGroceryItem(itemName string) (string, error) {
5156 return "" , result .Error
5257}
5358
54- func UpdateGroceryItem (id string , count int ) (string , error ) {
59+ func UpdateInventoryItem (id string , count int ) (string , error ) {
5560 db := DBConn
5661
57- var item GroceryItem
62+ var item InventoryItem
5863 db .First (& item , "Id" )
5964
6065 item .Count = count
@@ -63,15 +68,15 @@ func UpdateGroceryItem(id string, count int) (string, error) {
6368 return "Item updated." , result .Error
6469}
6570
66- func DeleteGroceryItem (itemName string ) (string , error ) {
71+ func DeleteInventoryItem (itemName string ) (string , error ) {
6772 name := strings .ToLower (itemName )
6873 db := DBConn
6974
7075 if len (name ) <= 0 {
7176 return "" , errors .New ("please type a grocery item" )
7277 }
7378
74- var item GroceryItem
79+ var item InventoryItem
7580 db .First (& item , "Name = ?" , name )
7681
7782 if item .Name == "" {
0 commit comments