aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/database/database.go59
-rw-r--r--server/main.go8
2 files changed, 45 insertions, 22 deletions
diff --git a/server/database/database.go b/server/database/database.go
index 8b7c7f6..b3c1e78 100644
--- a/server/database/database.go
+++ b/server/database/database.go
@@ -21,58 +21,75 @@ type Item struct {
Desc string `json:"Description"`
Price float64
HSN int
+ GST float64
+ Cat string `json:"Category"`
+ Brand string
}
var myDatabase *sql.DB
-var registered_items *sql.Stmt
var register_item *sql.Stmt
func init() {
myDatabase, _ = sql.Open("sqlite3", "./openbills.db")
- registered_items, _ = myDatabase.Prepare(
+ init_registered_items, _ := myDatabase.Prepare(
`CREATE TABLE IF NOT EXISTS registered_items
(id INTEGER PRIMARY KEY AUTOINCREMENT,
- model TEXT NOT NULL,
- desc TEXT,
- price REAL,
- hsn BLOB)`,
+ model TEXT NOT NULL,
+ desc TEXT,
+ price REAL,
+ hsn BLOB,
+ gst REAL,
+ category TEXT,
+ brand TEXT)`,
)
- registered_items.Exec()
+ init_registered_items.Exec()
register_item, _ = myDatabase.Prepare(
`INSERT INTO registered_items
- (model, desc, price, hsn)
- VALUES (?, ?, ?, ?)`,
+ (model, desc, price, hsn, gst, category, brand)
+ VALUES (?, ?, ?, ?, ?, ?, ?)`,
)
}
func GetAllItems() []Item {
var allItems []Item
rows, _ := myDatabase.Query(
- `SELECT model, desc, price, hsn FROM registered_items`,
+ `SELECT model, desc, price, hsn, gst, category, brand FROM registered_items`,
)
var (
- model, desc string
- price float64
+ model, desc, cat, brand string
+ price, GST float64
HSN int
)
for rows.Next() {
- rows.Scan(&model, &desc, &price, &HSN)
- allItems = append(allItems, Item{model, desc, price, HSN})
+ rows.Scan(&model, &desc, &price, &HSN, &GST, &cat, &brand)
+ allItems = append(allItems, Item{model, desc, price, HSN, GST, cat, brand})
}
return allItems
}
-func RegisterItem(model string, desc string, price float64, HSN int) {
- /*
- var item Item = Item{
- model, desc, price, HSN,
+func RegisterItem(item Item) bool {
+ itemNames, _ := myDatabase.Query("SELECT model FROM registered_items")
+
+ // check if item already exists
+ // probably this should be handled by front end
+ // so we can check this without need of using api
+ for itemNames.Next() {
+ var rModel string
+ itemNames.Scan(&rModel)
+ if rModel == item.Model {
+ return false
+ }
}
- register_item.Exec(item.Model, item.Desc, item.Price, item.HSN)
- */
- register_item.Exec(model, desc, price, HSN)
+ register_item.Exec(
+ item.Model, item.Desc,
+ item.Price, item.HSN,
+ item.GST, item.Cat,
+ item.Brand,
+ )
+ return true
}
diff --git a/server/main.go b/server/main.go
index 1aa34c3..c75a5de 100644
--- a/server/main.go
+++ b/server/main.go
@@ -51,6 +51,9 @@ func registerItem(ctx *gin.Context) {
desc := ctx.Query("desc")
price, _ := strconv.ParseFloat(ctx.Query("price"), 64)
hsn, _ := strconv.Atoi(ctx.Query("hsn"))
+ gst, _ := strconv.ParseFloat(ctx.Query("gst"), 64)
+ cat := "cat coming soon"
+ brand := "brand coming soon"
// why does it show warnings
item := db.Item {
@@ -58,7 +61,10 @@ func registerItem(ctx *gin.Context) {
desc,
price,
hsn,
+ gst,
+ cat,
+ brand,
}
- db.RegisterItem(item.Model, item.Desc, item.Price, item.HSN)
+ db.RegisterItem(item)
}