aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-08 09:11:45 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-07-08 09:11:45 +0530
commit165d47723a484ba84acf13d62f7ae8e4f1392347 (patch)
tree1cf092e8aa05e5037e9cd8a6f4bf2dd1696ef729
parent177427b5821a67e141236e6aeb4db12d76b050a0 (diff)
polished how POST requests work on both front and back end
-rw-r--r--server/router/items.go22
-rw-r--r--server/router/people.go11
-rw-r--r--src/components/Form/Items/RegisterItemForm.tsx9
-rw-r--r--src/components/Form/People/RegisterPersonForm.tsx8
-rw-r--r--src/styles/global.scss1
5 files changed, 10 insertions, 41 deletions
diff --git a/server/router/items.go b/server/router/items.go
index 540fdf3..82f86ec 100644
--- a/server/router/items.go
+++ b/server/router/items.go
@@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin"
"net/http"
- "strconv"
+ //"strconv"
db "github.com/MikunoNaka/openbills/database"
)
@@ -23,21 +23,7 @@ func getAllItems(ctx *gin.Context) {
}
func registerItem(ctx *gin.Context) {
- // extract data not string
- price, _ := strconv.ParseFloat(ctx.Query("price"), 64)
- gst, _ := strconv.ParseFloat(ctx.Query("gst"), 64)
- cat := "cat coming soon"
- brand := "brand coming soon"
-
- item := db.Item {
- Model: ctx.Query("model"),
- Description: ctx.Query("desc"),
- UnitPrice: price,
- HSN: ctx.Query("hsn"),
- TotalGST: gst,
- Category: cat,
- Brand: brand,
- }
-
- db.RegisterItem(item)
+ var newItem db.Item
+ ctx.Bind(&newItem)
+ db.RegisterItem(newItem)
}
diff --git a/server/router/people.go b/server/router/people.go
index bdb74a8..25d5353 100644
--- a/server/router/people.go
+++ b/server/router/people.go
@@ -22,12 +22,7 @@ func getAllPeople(ctx *gin.Context) {
}
func registerPerson(ctx *gin.Context) {
- person := db.Person {
- Name: ctx.Query("name"),
- Address: ctx.Query("address"),
- Phone: ctx.Query("phone"),
- Email: ctx.Query("email"),
- }
-
- db.RegisterPerson(person)
+ var newPerson db.Person
+ ctx.Bind(&newPerson)
+ db.RegisterPerson(newPerson)
}
diff --git a/src/components/Form/Items/RegisterItemForm.tsx b/src/components/Form/Items/RegisterItemForm.tsx
index c782df5..886628c 100644
--- a/src/components/Form/Items/RegisterItemForm.tsx
+++ b/src/components/Form/Items/RegisterItemForm.tsx
@@ -47,14 +47,7 @@ const RegisterItemForm: React.FC<props> = (props) => {
// TODO: show confirmation before being invisible
// TODO: Implement override protection
- axios.post(
- `/api/items/register/`
- + `?model=${newItem.Model}`
- + `&desc=${newItem.Description}`
- + `&price=${newItem.UnitPrice}`
- + `&hsn=${newItem.HSN}`
- + `&gst=${newItem.TotalGST}`
- )
+ axios.post("/api/items/register", newItem)
.then((res) => {
console.log(res);
hideSelf();
diff --git a/src/components/Form/People/RegisterPersonForm.tsx b/src/components/Form/People/RegisterPersonForm.tsx
index 66de169..9e3b155 100644
--- a/src/components/Form/People/RegisterPersonForm.tsx
+++ b/src/components/Form/People/RegisterPersonForm.tsx
@@ -39,13 +39,7 @@ const RegisterPersonForm: React.FC<props> = (props) => {
// TODO: show confirmation before being invisible
// TODO: Implement override protection
- axios.post(
- `/api/people/register/`
- + `?name=${newClient.Name}`
- + `&phone=${newClient.Phone}`
- + `&email=${newClient.Email}`
- + `&address=${newClient.Address}`
- )
+ axios.post("/api/people/register", newClient)
.then((res) => {
console.log(res);
props.updatePeopleList();
diff --git a/src/styles/global.scss b/src/styles/global.scss
index 9cecfea..a82e4ad 100644
--- a/src/styles/global.scss
+++ b/src/styles/global.scss
@@ -19,6 +19,7 @@
}
* {
scrollbar-width: 1vw; /* Firefox */
+ transition: 0.3s;
}
body {