diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-03 16:18:20 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-03 16:18:20 +0530 |
commit | 776522d8741752832981b17ec81deb11a298ef57 (patch) | |
tree | f7c0654f2b3dbc475c2a32daa5c623eec0ffce4a /customer/service.go | |
parent | 95dfc551f7eaaf6e8ebdefce1b733951354ac40d (diff) |
different customers for different users
Diffstat (limited to 'customer/service.go')
-rw-r--r-- | customer/service.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/customer/service.go b/customer/service.go index c5d7cb8..f1108c6 100644 --- a/customer/service.go +++ b/customer/service.go @@ -36,8 +36,8 @@ func getCustomer(customer *Customer, id uint) error { return nil } -func getCustomers(customers *[]Customer) error { - res := db.Find(&customers) +func getCustomers(customers *[]Customer, userId uint) error { + res := db.Where("user_id = ?", userId).Find(&customers) // TODO: handle potential errors if res.Error != nil { @@ -58,13 +58,14 @@ func (c *Customer) upsert() error { } func (c *Customer) del() error { - res := db.Delete(c) + res := db.Where("id = ? and user_id = ?", c.ID, c.UserID).Delete(c) // TODO: handle potential errors if res.Error != nil { return res.Error } + // returns 404 if either row doesn't exist or if the user doesn't own it if res.RowsAffected == 0 { return e.ErrNotFound } |