From 9d941b5d99621bc98df0be3002aa7121f98e7a56 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Thu, 8 Jul 2021 11:35:30 +0530 Subject: Added basic functionality to send the invoice data to server --- package.json | 1 + server/database/invoices.go | 4 ++-- server/router/invoice.go | 35 +++++++++++++++++++++++++++++++++++ server/router/items.go | 1 - server/router/people.go | 1 - server/router/router.go | 8 ++++++-- src/components/Pages/BillingPage.tsx | 21 ++++++++++++++++++++- src/interfaces.ts | 6 ++++++ src/styles/global.scss | 1 - 9 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 server/router/invoice.go diff --git a/package.json b/package.json index e18bd80..4748409 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ }, "scripts": { "start": "react-scripts start", + "dev": "alacritty -e react-scripts start & cd server;go run main.go", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/server/database/invoices.go b/server/database/invoices.go index f6e1a4c..d6bc015 100644 --- a/server/database/invoices.go +++ b/server/database/invoices.go @@ -15,8 +15,8 @@ import ( type Invoice struct { ID int - Data string - CreatedON string + Items []Item + Transport string } /* diff --git a/server/router/invoice.go b/server/router/invoice.go new file mode 100644 index 0000000..6544119 --- /dev/null +++ b/server/router/invoice.go @@ -0,0 +1,35 @@ +/* + * 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 +*/ + +package router + +import ( + "github.com/gin-gonic/gin" + //"net/http" + "fmt" + + //"strconv" + db "github.com/MikunoNaka/openbills/database" +) + +// func getAllInvoices(ctx *gin.Context) { +// ctx.Header("Content-Type", "application/json") +// ctx.JSON(http.StatusOK, db.GetAllItems()) +// } + +// func registerInvoices(ctx *gin.Context) { +// var newItem db.Item +// ctx.Bind(&newItem) +// db.RegisterItem(newItem) +// } + +func previewInvoice(ctx *gin.Context) { + var newInvoice db.Invoice + ctx.Bind(&newInvoice) + fmt.Println(newInvoice) +} diff --git a/server/router/items.go b/server/router/items.go index 82f86ec..ba5f172 100644 --- a/server/router/items.go +++ b/server/router/items.go @@ -16,7 +16,6 @@ import ( db "github.com/MikunoNaka/openbills/database" ) -// items API functions func getAllItems(ctx *gin.Context) { ctx.Header("Content-Type", "application/json") ctx.JSON(http.StatusOK, db.GetAllItems()) diff --git a/server/router/people.go b/server/router/people.go index 25d5353..a439993 100644 --- a/server/router/people.go +++ b/server/router/people.go @@ -15,7 +15,6 @@ import ( db "github.com/MikunoNaka/openbills/database" ) -// people API functions func getAllPeople(ctx *gin.Context) { ctx.Header("Content-Type", "application/json") ctx.JSON(http.StatusOK, db.GetAllPeople()) diff --git a/server/router/router.go b/server/router/router.go index 9da6d1e..5b79fa4 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -21,10 +21,11 @@ func InitRouter() { myRouter.Use(static.Serve("/", static.LocalFile("./app", true))) - // define routes + // define groups api := myRouter.Group("/api") - people := api.Group("/people") items := api.Group("/items") + people := api.Group("/people") + invoice := api.Group("/invoice") // items API routes items.GET("/get-all", getAllItems) @@ -34,5 +35,8 @@ func InitRouter() { people.GET("/get-all", getAllPeople) people.POST("/register", registerPerson) + // invoice API routes + invoice.POST("/preview", previewInvoice) + myRouter.Run(":8080") } diff --git a/src/components/Pages/BillingPage.tsx b/src/components/Pages/BillingPage.tsx index 3949beb..301f39e 100644 --- a/src/components/Pages/BillingPage.tsx +++ b/src/components/Pages/BillingPage.tsx @@ -9,7 +9,7 @@ import React, { useState, useEffect } from "react"; import axios from "axios"; -import { Item, Person, Transport } from "../../interfaces"; +import { Item, Person, Transport, Invoice } from "../../interfaces"; import AddNewItemForm from "./../Form/Items/AddNewItemForm"; import RegisterItemForm from "./../Form/Items/RegisterItemForm"; @@ -57,6 +57,24 @@ const BillingPage: React.FC = () => { // update the items from AddNewItemForm const getItems = (item: Item) => setItems([...items, item]); + const postInvoice = () => { + const newInvoice: Invoice = { + Items: items, + Transport: transporter + } + window.print(); + + // just for testing it will not save to DB + axios.post("/api/invoice/preview", newInvoice) + .then((res) => { + alert("OH MY FUCKEN GOD") + console.log(res) + }) + .catch((res) => { + console.log(res) + }) + } + return ( <> {registerItemFormVisibility && @@ -106,6 +124,7 @@ const BillingPage: React.FC = () => { /> + ); } diff --git a/src/interfaces.ts b/src/interfaces.ts index 5e918b7..3500c2b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -41,3 +41,9 @@ export interface Person { Phone?: string Email?: string } + +export interface Invoice { + //Client: Person + Items: Item[] + Transport: Transport +} diff --git a/src/styles/global.scss b/src/styles/global.scss index a82e4ad..ef3d11d 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -93,7 +93,6 @@ body { max-width: 960px; } - @media only screen and (max-device-width: 480px) { .floatingMenu { width: 95%; -- cgit v1.2.3