From 31e9605652faf350291634f5a2d642573f320e66 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 26 Dec 2022 20:32:10 +0530 Subject: deleted useless files to render the invoice. it will be handled by react. --- invoice/router.go | 70 +---------------------------------- main.go | 2 - web/templates/partials/item.html | 3 -- web/templates/partials/item_list.html | 7 ---- web/templates/views/invoice.html | 15 -------- 5 files changed, 1 insertion(+), 96 deletions(-) delete mode 100644 web/templates/partials/item.html delete mode 100644 web/templates/partials/item_list.html delete mode 100644 web/templates/views/invoice.html diff --git a/invoice/router.go b/invoice/router.go index 37c3cd5..ffa8ed3 100644 --- a/invoice/router.go +++ b/invoice/router.go @@ -23,10 +23,8 @@ import ( "log" "errors" "net/http" - "strconv" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" - //"go.mongodb.org/mongo-driver/bson" ) func Routes(route *gin.Engine) { @@ -45,74 +43,8 @@ func Routes(route *gin.Engine) { ctx.JSON(http.StatusOK, invoices) }) - // TODO: /preview routes should send error codes as HTML - // send invoice as HTML, filtering by InvoiceNumber - i.GET("/preview/by-num/:invoiceNumber", func(ctx *gin.Context) { - num := ctx.Param("invoiceNumber") - numInt, _ := strconv.Atoi(num) - - invoice, err := getInvoiceByNumber(numInt) - if err != nil { - if errors.Is(err, mongo.ErrNoDocuments) { - ctx.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) - } else { - ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - } - log.Printf("ERROR: Failed to read invoice #%d from DB: %v\n", numInt, err.Error()) - return - } - - ctx.HTML(http.StatusOK, "invoice.html", gin.H{ - "Invoice": invoice, - }) - }) - - // send invoice as HTML, filtering by ID - i.GET("/preview/by-id/:invoiceId", func(ctx *gin.Context) { - id, err := primitive.ObjectIDFromHex(ctx.Param("invoiceId")) - if err != nil { - ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) - log.Printf("ERROR: Failed to get invoice with ID, Error parsing ID: %v\n", err.Error()) - return - } - - invoice, err := getInvoiceById(id) - if err != nil { - if errors.Is(err, mongo.ErrNoDocuments) { - ctx.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) - } else { - ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - } - log.Printf("ERROR: Failed to read invoice %v from DB: %v\n", id, err.Error()) - return - } - - ctx.HTML(http.StatusOK, "invoice.html", gin.H{ - "Invoice": invoice, - }) - }) - - // send invoice as JSON, filtering by InvoiceNumber - i.GET("/by-num/:invoiceNumber", func(ctx *gin.Context) { - num := ctx.Param("invoiceNumber") - numInt, _ := strconv.Atoi(num) - - invoice, err := getInvoiceByNumber(numInt) - if err != nil { - if errors.Is(err, mongo.ErrNoDocuments) { - ctx.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) - } else { - ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - } - log.Printf("ERROR: Failed to read invoice #%d from DB: %v\n", numInt, err.Error()) - return - } - - ctx.JSON(http.StatusOK, invoice) - }) - // send invoice as JSON, filtering by ID - i.GET("/by-id/:invoiceId", func(ctx *gin.Context) { + i.GET("/:invoiceId", func(ctx *gin.Context) { id, err := primitive.ObjectIDFromHex(ctx.Param("invoiceId")) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) diff --git a/main.go b/main.go index becba70..76fb534 100644 --- a/main.go +++ b/main.go @@ -34,8 +34,6 @@ func main() { defer database.DisconnectDB() r := gin.New() - r.LoadHTMLGlob("web/templates/**/*") - item.Routes(r) brand.Routes(r) client.Routes(r) diff --git a/web/templates/partials/item.html b/web/templates/partials/item.html deleted file mode 100644 index 04eabba..0000000 --- a/web/templates/partials/item.html +++ /dev/null @@ -1,3 +0,0 @@ -{{ define "partials/item.html" }} -
{{ .Name }}
-{{ end }} diff --git a/web/templates/partials/item_list.html b/web/templates/partials/item_list.html deleted file mode 100644 index 6fdd1f9..0000000 --- a/web/templates/partials/item_list.html +++ /dev/null @@ -1,7 +0,0 @@ -{{ define "partials/item_list.html" }} -
- {{ range . }} - {{ template "partials/item.html" .}} - {{ end }} -
-{{ end }} diff --git a/web/templates/views/invoice.html b/web/templates/views/invoice.html deleted file mode 100644 index c8a3c70..0000000 --- a/web/templates/views/invoice.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - OpenBills Testing - - - - - - - {{ template "partials/item_list.html" .Invoice.Items }} - - -- cgit v1.2.3