From 520ed8f6387e0744a21a52912418e3acb08d18a5 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 3 Sep 2023 19:18:27 +0530 Subject: different brands and items for different users --- item/validators.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'item/validators.go') 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 -- cgit v1.2.3