diff options
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  |