Subcategory now accepts POST requests, so they can be added even after a category has been created.

This commit is contained in:
2021-09-09 21:50:44 -05:00
parent f1272b86e8
commit 5cea8df5f5
2 changed files with 60 additions and 0 deletions
+17
View File
@@ -195,3 +195,20 @@ func getSubcategories(categoryID int64) (subcategories []Subcategory, ok bool) {
return subcategories, true
}
func insertSubcategory(name string, categoryID int64) (recordID int64, ok bool) {
db := getSQLConnection()
defer db.Close()
err := db.QueryRow("INSERT INTO subcategory(subcategory_name, category_id) VALUES($1, $2) RETURNING subcategory_id;", name, categoryID).Scan(&recordID)
if err != nil {
//TODO: log this error
println(err.Error())
return 0, false
//panic(err)
}
return recordID, true
}