aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/customer/controller.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-11 20:55:48 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-11 20:55:48 +0530
commitbc154857fb5569d7c1fa9785cc891cb927a6a156 (patch)
tree590c9f6a00a1b97b2ee45cfa5a767558089affe0 /customer/controller.go
parent8a47978ca17d2f251d67d12b0e34fa26bb1e4ace (diff)
removed per-user itemsv0.17.0
Diffstat (limited to 'customer/controller.go')
-rw-r--r--customer/controller.go71
1 files changed, 2 insertions, 69 deletions
diff --git a/customer/controller.go b/customer/controller.go
index f2704bd..83423da 100644
--- a/customer/controller.go
+++ b/customer/controller.go
@@ -31,17 +31,7 @@ func handleGetSingleCustomer (ctx *gin.Context) {
return
}
- uId, ok := ctx.Get("UserID")
- if !ok {
- ctx.Error(e.ErrUnauthorized)
- ctx.Abort()
- return
- }
-
- userId := uId.(uint)
-
var customer Customer
-
err = getCustomer(&customer, uint(id))
if err != nil {
ctx.Error(err)
@@ -49,14 +39,7 @@ func handleGetSingleCustomer (ctx *gin.Context) {
return
}
- if customer.UserID != userId {
- ctx.Error(e.ErrForbidden)
- ctx.Abort()
- return
- }
-
ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
"data": customer,
})
}
@@ -64,16 +47,7 @@ func handleGetSingleCustomer (ctx *gin.Context) {
func handleGetCustomers (ctx *gin.Context) {
var customers []Customer
- uId, ok := ctx.Get("UserID")
- if !ok {
- ctx.Error(e.ErrUnauthorized)
- ctx.Abort()
- return
- }
-
- userId := uId.(uint)
-
- err := getCustomers(&customers, userId)
+ err := getCustomers(&customers)
if err != nil {
ctx.Error(err)
ctx.Abort()
@@ -81,7 +55,6 @@ func handleGetCustomers (ctx *gin.Context) {
}
ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
"data": customers,
})
}
@@ -90,26 +63,6 @@ func handleSaveCustomer (ctx *gin.Context) {
var customer Customer
ctx.Bind(&customer)
- uId, ok := ctx.Get("UserID")
- if !ok {
- ctx.Error(e.ErrUnauthorized)
- ctx.Abort()
- return
- }
-
- userId := uId.(uint)
- customer.UserID = userId // necessary even when editing, just in case if UserID was ommitted in the request
-
- if customer.ID != 0 {
- // if customer is being edited, check ownership
- err := checkCustomerOwnership(customer.ID, userId)
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
- }
-
err := customer.upsert()
if err != nil {
ctx.Error(err)
@@ -118,7 +71,6 @@ func handleSaveCustomer (ctx *gin.Context) {
}
ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
"data": customer,
})
}
@@ -133,23 +85,6 @@ func handleDelCustomer (ctx *gin.Context) {
var customer Customer
customer.ID = uint(id)
- uId, ok := ctx.Get("UserID")
- if !ok {
- ctx.Error(e.ErrUnauthorized)
- ctx.Abort()
- return
- }
-
- userId := uId.(uint)
- customer.UserID = userId
-
- err = checkCustomerOwnership(customer.ID, customer.UserID)
- if err != nil {
- ctx.Error(err)
- ctx.Abort()
- return
- }
-
err = customer.del()
if err != nil {
ctx.Error(err)
@@ -157,7 +92,5 @@ func handleDelCustomer (ctx *gin.Context) {
return
}
- ctx.JSON(http.StatusOK, gin.H{
- "message": "success",
- })
+ ctx.JSON(http.StatusOK, nil)
}