diff options
| author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-03 19:18:27 +0530 | 
|---|---|---|
| committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-03 19:18:27 +0530 | 
| commit | 520ed8f6387e0744a21a52912418e3acb08d18a5 (patch) | |
| tree | 7865e20c8e1828d7b1a7d513b08dc282b291aa05 /item/validators.go | |
| parent | 020fc720379255832aad369dfc2dece9a1cf4699 (diff) | |
different brands and items for different users
Diffstat (limited to 'item/validators.go')
| -rw-r--r-- | item/validators.go | 10 | 
1 files changed, 5 insertions, 5 deletions
diff --git a/item/validators.go b/item/validators.go index 09162ab..996a5d7 100644 --- a/item/validators.go +++ b/item/validators.go @@ -36,7 +36,7 @@ func (b *Brand) validate() error {  	var count int64  	err := db.Model(&Brand{}).  		Select("name"). -		Where("name = ?", b.Name). +		Where("name = ? and user_id = ?", b.Name, b.UserID).  		Count(&count).  		Error @@ -51,12 +51,12 @@ func (b *Brand) validate() error {  	return nil  } -func checkIfBrandExists(id uint) error { -	// check if brand id is valid +func checkIfBrandExists(id, userId uint) error { +	// check if brand id is valid and is owned by user  	var count int64  	err := db.Model(&Brand{}).  		Select("id"). -		Where("id = ?", id). +		Where("id = ? and user_id = ?", id, userId).  		Count(&count).  		Error @@ -95,7 +95,7 @@ func (i *SavedItem) validate() error {  	var count int64  	err = db.Model(&SavedItem{}).  		Select("name, brand_id"). -		Where("brand_id = ? and name = ?", i.BrandID, i.Name). +		Where("brand_id = ? and name = ? and user_id = ?", i.BrandID, i.Name, i.UserID).  		Count(&count).  		Error  |