aboutsummaryrefslogtreecommitdiff
path: root/invoice/controller.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-10-09 21:07:20 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-10-09 21:07:20 +0530
commit1924bfca2439829253df3598481034e5c586e3e2 (patch)
tree6b82a091ae97e1980fe0ff3f3fb3eaa726a6d6ad /invoice/controller.go
parentb643f7852f93f73843aa5f52f9b4545321713e10 (diff)
added route to add items to invoicev0.0.12
Diffstat (limited to 'invoice/controller.go')
-rw-r--r--invoice/controller.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/invoice/controller.go b/invoice/controller.go
index efcaa40..354ae21 100644
--- a/invoice/controller.go
+++ b/invoice/controller.go
@@ -151,3 +151,28 @@ func handleDelInvoice (ctx *gin.Context) {
"message": "success",
})
}
+
+func addItem (ctx *gin.Context) {
+ id, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
+ if err != nil {
+ ctx.Error(e.ErrInvalidID)
+ return
+ }
+
+ var item InvoiceItem
+ ctx.Bind(&item)
+
+ item.InvoiceID = uint(id)
+
+ err = item.upsert()
+ if err != nil {
+ ctx.Error(err)
+ ctx.Abort()
+ return
+ }
+
+ ctx.JSON(http.StatusOK, gin.H{
+ "message": "success",
+ "data": item,
+ })
+}