增加收藏页的添加和删除接口

This commit is contained in:
laodaming
2023-10-08 12:04:00 +08:00
parent bfeacad5f0
commit b93691a0bf
9 changed files with 305 additions and 5 deletions

View File

@@ -1,2 +1,37 @@
package gmodel
// TODO: 使用model的属性做你想做的
import "context"
// 查询
func (c *FsProductCollectionModel) FindOne(ctx context.Context, userId, guestId, productId int64) (resp *FsProductCollection, err error) {
err = c.db.WithContext(ctx).Model(&FsProductCollection{}).
Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId).
Take(&resp).Error
return resp, err
}
// 创建
func (c *FsProductCollectionModel) Create(ctx context.Context, data *FsProductCollection) error {
return c.db.WithContext(ctx).Model(&FsProductCollection{}).Create(&data).Error
}
// 更新
func (c *FsProductCollectionModel) Update(ctx context.Context, userId, guestId, productId int64, data *FsProductCollection) error {
return c.db.WithContext(ctx).Model(&FsProductCollection{}).
Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId).
Updates(&data).Error
}
// 删除
func (c *FsProductCollectionModel) Delete(ctx context.Context, userId, guestId, productId int64) error {
return c.db.WithContext(ctx).Model(&FsProductCollection{}).
Where("user_id = ? and guest_id = ? and product_id = ?", userId, guestId, productId).
Delete(&FsProductCollection{}).Error
}
// 删除
func (c *FsProductCollectionModel) Delete2(ctx context.Context, userId, guestId, id int64) error {
return c.db.WithContext(ctx).Model(&FsProductCollection{}).
Where("user_id = ? and guest_id = ? and id = ?", userId, guestId, id).
Delete(&FsProductCollection{}).Error
}