diff options
-rw-r--r-- | invoice/router.go | 70 | ||||
-rw-r--r-- | main.go | 2 | ||||
-rw-r--r-- | web/templates/partials/item.html | 3 | ||||
-rw-r--r-- | web/templates/partials/item_list.html | 7 | ||||
-rw-r--r-- | web/templates/views/invoice.html | 15 |
5 files changed, 1 insertions, 96 deletions
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()}) @@ -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" }} -<div>{{ .Name }}</div> -{{ 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" }} -<div class="items"> - {{ range . }} - {{ template "partials/item.html" .}} - {{ end }} -</div> -{{ 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 @@ -<!doctype html> -<html class="no-js" lang=""> - <head> - <meta charset="utf-8"> - <meta http-equiv="x-ua-compatible" content="ie=edge"> - <title>OpenBills Testing</title> - <meta name="description" content=""> - <meta name="viewport" content="width=device-width, initial-scale=1"> - - <link rel="apple-touch-icon" href="/apple-touch-icon.png"> - </head> - <body> - {{ template "partials/item_list.html" .Invoice.Items }} - </body> -</html> |