catching errors again
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||
)
|
||||
|
||||
type ProductService struct {
|
||||
@@ -34,9 +35,41 @@ 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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count <= 0 {
|
||||
return responseErrors.ErrProductNotFound
|
||||
}
|
||||
|
||||
count, err = s.productsRepo.ExistsInFavorites(userID, productID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count >= 1 {
|
||||
return responseErrors.ErrAlreadyInFavorites
|
||||
}
|
||||
|
||||
return s.productsRepo.AddToFavorites(userID, productID)
|
||||
}
|
||||
|
||||
func (s *ProductService) RemoveFromFavorites(userID uint, productID uint) error {
|
||||
count, err := s.productsRepo.ProductInDatabase(productID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count <= 0 {
|
||||
return responseErrors.ErrProductNotFound
|
||||
}
|
||||
|
||||
count, err = s.productsRepo.ExistsInFavorites(userID, productID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count <= 0 {
|
||||
return responseErrors.ErrNotInFavorites
|
||||
}
|
||||
|
||||
return s.productsRepo.RemoveFromFavorites(userID, productID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user