aboutsummaryrefslogtreecommitdiff
path: root/invoice/controller.go
diff options
context:
space:
mode:
Diffstat (limited to 'invoice/controller.go')
-rw-r--r--invoice/controller.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/invoice/controller.go b/invoice/controller.go
index 6bd5ad5..d3dd51c 100644
--- a/invoice/controller.go
+++ b/invoice/controller.go
@@ -192,6 +192,46 @@ func handleDelInvoice (ctx *gin.Context) {
})
}
+// get items belonging to a certain invoice
+func handleGetInvoiceItems (ctx *gin.Context) {
+ id, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
+ if err != nil {
+ ctx.Error(e.ErrInvalidID)
+ ctx.Abort()
+ return
+ }
+
+ uId, ok := ctx.Get("UserID")
+ if !ok {
+ ctx.Error(e.ErrUnauthorized)
+ ctx.Abort()
+ return
+ }
+
+ userId := uId.(uint)
+
+
+ err = checkInvoiceOwnership(uint(id), userId)
+ if err != nil {
+ ctx.Error(err)
+ ctx.Abort()
+ return
+ }
+
+ var items []InvoiceItem
+ err = getInvoiceItems(&items, uint(id))
+ if err != nil {
+ ctx.Error(err)
+ ctx.Abort()
+ return
+ }
+
+ ctx.JSON(http.StatusOK, gin.H{
+ "message": "success",
+ "data": items,
+ })
+}
+
func addItem (ctx *gin.Context) {
id, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
if err != nil {