diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-10-12 23:30:08 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-10-12 23:30:08 +0530 |
commit | 327a32f563394f92313e4a751515d69d90f4e7f5 (patch) | |
tree | 9b49fd41ac852fa459b623f7fbe7c79aaac24418 /invoice | |
parent | 029fe2c7a3532bc3bf435f257cdade240c8f3568 (diff) |
formatted code
Diffstat (limited to 'invoice')
-rw-r--r-- | invoice/controller.go | 40 | ||||
-rw-r--r-- | invoice/hooks.go | 2 | ||||
-rw-r--r-- | invoice/invoice.go | 21 | ||||
-rw-r--r-- | invoice/validators.go | 2 |
4 files changed, 33 insertions, 32 deletions
diff --git a/invoice/controller.go b/invoice/controller.go index b03ec22..bb51628 100644 --- a/invoice/controller.go +++ b/invoice/controller.go @@ -18,13 +18,13 @@ package invoice import ( - e "vidhukant.com/openbills/errors" "github.com/gin-gonic/gin" "net/http" "strconv" + e "vidhukant.com/openbills/errors" ) -func handleGetSingleInvoice (ctx *gin.Context) { +func handleGetSingleInvoice(ctx *gin.Context) { id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { ctx.Error(e.ErrInvalidID) @@ -47,22 +47,22 @@ func handleGetSingleInvoice (ctx *gin.Context) { func handleGetInvoices(getDrafts bool) func(*gin.Context) { return func(ctx *gin.Context) { - var invoices []Invoice + var invoices []Invoice - err := getInvoices(&invoices, getDrafts) - if err != nil { - ctx.Error(err) - ctx.Abort() - return - } + err := getInvoices(&invoices, getDrafts) + if err != nil { + ctx.Error(err) + ctx.Abort() + return + } - ctx.JSON(http.StatusOK, gin.H{ - "data": invoices, - }) + ctx.JSON(http.StatusOK, gin.H{ + "data": invoices, + }) } } -func handleSaveInvoice (ctx *gin.Context) { +func handleSaveInvoice(ctx *gin.Context) { var invoice Invoice ctx.Bind(&invoice) @@ -92,7 +92,7 @@ func handleSaveInvoice (ctx *gin.Context) { }) } -func handleDelInvoice (ctx *gin.Context) { +func handleDelInvoice(ctx *gin.Context) { // TODO: only drafts can be deleted, non-drafts should be "cancelled" id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { @@ -115,7 +115,7 @@ func handleDelInvoice (ctx *gin.Context) { } // get items belonging to a certain invoice -func handleGetInvoiceItems (ctx *gin.Context) { +func handleGetInvoiceItems(ctx *gin.Context) { id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { ctx.Error(e.ErrInvalidID) @@ -136,7 +136,7 @@ func handleGetInvoiceItems (ctx *gin.Context) { }) } -func addItem (ctx *gin.Context) { +func addItem(ctx *gin.Context) { // TODO: only drafts can be edited id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { @@ -160,7 +160,7 @@ func addItem (ctx *gin.Context) { ctx.JSON(http.StatusOK, nil) } -func removeItem (ctx *gin.Context) { +func removeItem(ctx *gin.Context) { // TODO: only drafts can be edited id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { @@ -183,7 +183,7 @@ func removeItem (ctx *gin.Context) { } // get custom fields belonging to a certain invoice -func handleGetInvoiceCustomFields (ctx *gin.Context) { +func handleGetInvoiceCustomFields(ctx *gin.Context) { id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { ctx.Error(e.ErrInvalidID) @@ -204,7 +204,7 @@ func handleGetInvoiceCustomFields (ctx *gin.Context) { }) } -func addCustomField (ctx *gin.Context) { +func addCustomField(ctx *gin.Context) { // TODO: only drafts can be edited id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { @@ -229,7 +229,7 @@ func addCustomField (ctx *gin.Context) { }) } -func removeCustomField (ctx *gin.Context) { +func removeCustomField(ctx *gin.Context) { // TODO: only drafts can be edited id, err := strconv.ParseUint(ctx.Param("id"), 10, 64) if err != nil { diff --git a/invoice/hooks.go b/invoice/hooks.go index b0ec877..68d730b 100644 --- a/invoice/hooks.go +++ b/invoice/hooks.go @@ -34,7 +34,7 @@ func (i *Invoice) BeforeSave(tx *gorm.DB) error { } func (i *Invoice) BeforeDelete(tx *gorm.DB) error { - // if ID is 0, invoice won't be deleted + // if ID is 0, invoice won't be deleted if i.ID == 0 { return errors.ErrNoWhereCondition } diff --git a/invoice/invoice.go b/invoice/invoice.go index 9fa931b..97ba254 100644 --- a/invoice/invoice.go +++ b/invoice/invoice.go @@ -19,13 +19,14 @@ package invoice import ( "gorm.io/gorm" + "time" d "vidhukant.com/openbills/db" - u "vidhukant.com/openbills/util" i "vidhukant.com/openbills/item" - "time" + u "vidhukant.com/openbills/util" ) var db *gorm.DB + func init() { db = d.DB @@ -71,14 +72,14 @@ type Invoice struct { Items []InvoiceItem CustomFields []CustomField - // issuer and customer details are stored here - // because they are NOT intended to ever change - IssuerFirmName string - IssuerFirmAddress string - IssuerFirmGstin string - IssuerFirmPhone string - IssuerFirmEmail string - IssuerFirmWebsite string + // issuer and customer details are stored here + // because they are NOT intended to ever change + IssuerFirmName string + IssuerFirmAddress string + IssuerFirmGstin string + IssuerFirmPhone string + IssuerFirmEmail string + IssuerFirmWebsite string IssuerFirmDetails string CustomerName string CustomerGstin string diff --git a/invoice/validators.go b/invoice/validators.go index 1c39cbe..13cc6e6 100644 --- a/invoice/validators.go +++ b/invoice/validators.go @@ -50,7 +50,7 @@ func isDraft(invoiceId uint) (bool, error) { // TODO: handle potential errors if err != nil { return invoice.IsDraft, err - } + } // invoice doesn't exist if invoice.ID == 0 { |