From 6baad020ce5037a90d902c8f41f1f37f52419a10 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Mon, 12 Jul 2021 12:14:35 +0530 Subject: Added support for more client details in server --- server/database/database.go | 18 ++++++++++++++---- server/database/people.go | 35 ++++++++++++++++++++--------------- server/router/invoice.go | 3 +-- server/router/router.go | 2 +- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/server/database/database.go b/server/database/database.go index 0499b68..68c3c76 100644 --- a/server/database/database.go +++ b/server/database/database.go @@ -13,6 +13,14 @@ import ( _ "github.com/mattn/go-sqlite3" ) +type Address struct { + AddressLine string + City string + State string + PINCode string + Country string +} + var myDatabase *sql.DB func InitDB() { myDatabase, _ = sql.Open("sqlite3", "./openbills.db") @@ -33,10 +41,12 @@ func InitDB() { init_people, _ := myDatabase.Prepare( `CREATE TABLE IF NOT EXISTS People (id INTEGER PRIMARY KEY AUTOINCREMENT, - Name TEXT, - Address TEXT, - Phone TEXT, - Email TEXT)`, + Name TEXT, + Phone TEXT, + Email TEXT, + BillAddress BLOB, + ShipAddress BLOB, + GSTIN TEXT)`, ) init_people.Exec() diff --git a/server/database/people.go b/server/database/people.go index 4817139..25aa393 100644 --- a/server/database/people.go +++ b/server/database/people.go @@ -7,34 +7,39 @@ */ // handles all People related database functions - -package database +package database import ( _ "github.com/mattn/go-sqlite3" ) + + + type Person struct { - ID int - Name string - Address string - Phone string - Email string + ID int + Name string + Phone string + Email string + BillAddress Address + ShipAddress Address + GSTIN string } func GetAllPeople() []Person { var allPeople []Person - rows, _ := myDatabase.Query( - `SELECT ID, Name, Address, Phone, Email FROM People`, + rows, _ := myDatabase.Query ( + `SELECT ID, Name, Phone, Email, BillAddress, ShipAddress, GSTIN FROM People`, ) var ( id int - name, address, phone, email string + name, phone, email, gstin string + billAddress, shipAddress Address ) for rows.Next() { - rows.Scan(&id, &name, &address, &phone, &email) - allPeople = append(allPeople, Person{id, name, address, phone, email}) + rows.Scan(&id, &name, &phone, &email, &billAddress, &shipAddress, &gstin) + allPeople = append(allPeople, Person{id, name, phone, email, billAddress, shipAddress, gstin}) } return allPeople @@ -43,12 +48,12 @@ func GetAllPeople() []Person { func RegisterPerson(person Person) bool { register_person, _ := myDatabase.Prepare( `INSERT INTO People - (Name, Address, Phone, Email) - VALUES (?, ?, ?, ?)`, + (Name, Phone, Email, BillAddress, ShipAddress, GSTIN) + VALUES (?, ?, ?, ?, ?, ?)`, ) register_person.Exec( - person.Name, person.Address, person.Phone, person.Email, + person.Name, person.Phone, person.Email, person.BillAddress, person.ShipAddress, person.GSTIN, ) return true diff --git a/server/router/invoice.go b/server/router/invoice.go index 6544119..865d244 100644 --- a/server/router/invoice.go +++ b/server/router/invoice.go @@ -13,7 +13,6 @@ import ( //"net/http" "fmt" - //"strconv" db "github.com/MikunoNaka/openbills/database" ) @@ -28,7 +27,7 @@ import ( // db.RegisterItem(newItem) // } -func previewInvoice(ctx *gin.Context) { +func registerInvoice(ctx *gin.Context) { var newInvoice db.Invoice ctx.Bind(&newInvoice) fmt.Println(newInvoice) diff --git a/server/router/router.go b/server/router/router.go index 5b79fa4..c6ddd65 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -36,7 +36,7 @@ func InitRouter() { people.POST("/register", registerPerson) // invoice API routes - invoice.POST("/preview", previewInvoice) + invoice.POST("/preview", registerInvoice) myRouter.Run(":8080") } -- cgit v1.2.3