diff options
Diffstat (limited to 'invoice/controller.go')
-rw-r--r-- | invoice/controller.go | 25 |
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, + }) +} |