minor change
This commit is contained in:
@@ -19,8 +19,8 @@ type UIProductsRepo interface {
|
||||
Find(id_lang, userID uint, p find.Paging, filt *filters.FiltersList) (find.Found[model.ProductInList], error)
|
||||
AddToFavorites(userID uint, productID uint) error
|
||||
RemoveFromFavorites(userID uint, productID uint) error
|
||||
ExistsInFavorites(userID uint, productID uint) (int64, error)
|
||||
ProductInDatabase(productID uint) (int64, error)
|
||||
ExistsInFavorites(userID uint, productID uint) (bool, error)
|
||||
ProductInDatabase(productID uint) (bool, error)
|
||||
}
|
||||
|
||||
type ProductsRepo struct{}
|
||||
@@ -144,20 +144,20 @@ func (repo *ProductsRepo) RemoveFromFavorites(userID uint, productID uint) error
|
||||
Delete(&model.B2bFavorite{}).Error
|
||||
}
|
||||
|
||||
func (repo *ProductsRepo) ExistsInFavorites(userID uint, productID uint) (int64, error) {
|
||||
func (repo *ProductsRepo) ExistsInFavorites(userID uint, productID uint) (bool, error) {
|
||||
var count int64
|
||||
err := db.Get().
|
||||
Table("b2b_favorites").
|
||||
Where("user_id = ? AND product_id = ?", userID, productID).
|
||||
Count(&count).Error
|
||||
return count, err
|
||||
return count >= 1, err
|
||||
}
|
||||
|
||||
func (repo *ProductsRepo) ProductInDatabase(productID uint) (int64, error) {
|
||||
func (repo *ProductsRepo) ProductInDatabase(productID uint) (bool, error) {
|
||||
var count int64
|
||||
err := db.Get().
|
||||
Table(dbmodel.TableNamePsProduct).
|
||||
Where(dbmodel.PsProductCols.IDProduct.Col()+" = ?", productID).
|
||||
Count(&count).Error
|
||||
return count, err
|
||||
return count >= 1, err
|
||||
}
|
||||
|
||||
@@ -35,19 +35,19 @@ func (s *ProductService) Find(id_lang, userID uint, p find.Paging, filters *filt
|
||||
}
|
||||
|
||||
func (s *ProductService) AddToFavorites(userID uint, productID uint) error {
|
||||
count, err := s.productsRepo.ProductInDatabase(productID)
|
||||
exists, err := s.productsRepo.ProductInDatabase(productID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count <= 0 {
|
||||
if !exists {
|
||||
return responseErrors.ErrProductNotFound
|
||||
}
|
||||
|
||||
count, err = s.productsRepo.ExistsInFavorites(userID, productID)
|
||||
exists, err = s.productsRepo.ExistsInFavorites(userID, productID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count >= 1 {
|
||||
if exists {
|
||||
return responseErrors.ErrAlreadyInFavorites
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ func (s *ProductService) AddToFavorites(userID uint, productID uint) error {
|
||||
}
|
||||
|
||||
func (s *ProductService) RemoveFromFavorites(userID uint, productID uint) error {
|
||||
count, err := s.productsRepo.ProductInDatabase(productID)
|
||||
exists, err := s.productsRepo.ProductInDatabase(productID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count <= 0 {
|
||||
if !exists {
|
||||
return responseErrors.ErrProductNotFound
|
||||
}
|
||||
|
||||
count, err = s.productsRepo.ExistsInFavorites(userID, productID)
|
||||
exists, err = s.productsRepo.ExistsInFavorites(userID, productID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count <= 0 {
|
||||
if !exists {
|
||||
return responseErrors.ErrNotInFavorites
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user