From 1924bfca2439829253df3598481034e5c586e3e2 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 9 Oct 2023 21:07:20 +0530 Subject: added route to add items to invoice --- invoice/controller.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'invoice/controller.go') 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, + }) +} -- cgit v1.2.3