aboutsummaryrefslogtreecommitdiff
path: root/server/database/people.go
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-05-01 09:43:59 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-05-01 09:43:59 +0530
commit45a3b94f133ebcd9abff2baf266d0b3f691d2790 (patch)
tree0716d12d6d25ead8b1905cd5b7ed70463c2fc458 /server/database/people.go
parent0fa16426f56120c4eb18bc18c202703c460daed8 (diff)
defined api group to handle DB functions regarding people/customers
Diffstat (limited to 'server/database/people.go')
-rw-r--r--server/database/people.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/server/database/people.go b/server/database/people.go
new file mode 100644
index 0000000..0ff3acb
--- /dev/null
+++ b/server/database/people.go
@@ -0,0 +1,67 @@
+/*
+ * OpenBills - Self hosted browser app to generate and keep track of simple invoices
+ * Version - 0
+ * Licensed under the MIT license - https://opensource.org/licenses/MIT
+ *
+ * Copyright (c) 2021 Vidhu Kant Sharma
+*/
+
+// handles all People related database functions
+
+package database
+
+import (
+ _ "github.com/mattn/go-sqlite3"
+ "fmt"
+)
+
+type Person struct {
+ Name string
+ Phone string
+ Email string
+}
+
+func GetAllPeople() []Person {
+ var allPeople []Person
+ rows, _ := myDatabase.Query(
+ `SELECT Name, Phone, Email FROM People`,
+ )
+
+ var (
+ name, phone, email string
+ )
+
+ for rows.Next() {
+ rows.Scan(&name, &phone, &email)
+ allPeople = append(allPeople, Person{name, phone, email})
+ }
+
+ return allPeople
+}
+
+func RegisterPerson(person Person) bool {
+ personNames, _ := myDatabase.Query("SELECT Name FROM People")
+
+ // check if already exists
+ // probs shouldnt make it
+ // make front end handle it
+ for personNames.Next() {
+ var rPerson string
+ if rPerson == person.Name {
+ fmt.Println(person.Name, "already exists")
+ return false
+ }
+ }
+
+ register_person, _ := myDatabase.Prepare(
+ `INSERT INTO People
+ (Name, Phone, Email)
+ VALUES (?, ?, ?)`,
+ )
+
+ register_person.Exec(
+ person.Name, person.Phone, person.Email,
+ )
+
+ return true
+}