diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-12-26 20:32:10 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-12-26 20:32:10 +0530 |
commit | 31e9605652faf350291634f5a2d642573f320e66 (patch) | |
tree | 3041b2bcf3dbadf3849296a6d7cc50d6e5c7e288 /invoice | |
parent | 6581728a1291850b9fa6c5f3aaf072512d50f165 (diff) |
deleted useless files to render the invoice. it will be handled by react.
Diffstat (limited to 'invoice')
-rw-r--r-- | invoice/router.go | 70 |
1 files changed, 1 insertions, 69 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()}) |