favorites #57
@@ -10,6 +10,7 @@ import (
|
|||||||
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
"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/query/find"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
"git.ma-al.com/goc_marek/gormcol"
|
"git.ma-al.com/goc_marek/gormcol"
|
||||||
"github.com/WinterYukky/gorm-extra-clause-plugin/exclause"
|
"github.com/WinterYukky/gorm-extra-clause-plugin/exclause"
|
||||||
)
|
)
|
||||||
@@ -129,6 +130,29 @@ func (repo *ProductsRepo) Find(id_lang, userID uint, p find.Paging, filt *filter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repo *ProductsRepo) AddToFavorites(userID uint, productID uint) error {
|
func (repo *ProductsRepo) AddToFavorites(userID uint, productID uint) error {
|
||||||
|
var count int64
|
||||||
|
err := db.Get().
|
||||||
|
Table(dbmodel.TableNamePsProduct).
|
||||||
|
Where(dbmodel.PsProductCols.IDProduct.Col()+" = ?", productID).
|
||||||
|
Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if count == 0 {
|
||||||
|
return responseErrors.ErrProductNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Get().
|
||||||
|
Table("b2b_favorites").
|
||||||
|
Where("user_id = ? AND product_id = ?", userID, productID).
|
||||||
|
Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return responseErrors.ErrAlreadyInFavorites
|
||||||
|
dudzic_wiktor marked this conversation as resolved
Outdated
|
|||||||
|
}
|
||||||
|
|
||||||
fav := model.B2bFavorite{
|
fav := model.B2bFavorite{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
ProductID: productID,
|
ProductID: productID,
|
||||||
|
|||||||
Reference in New Issue
Block a user
why int64 instead of bool
ok, i can change it to bool