Fetch the repository succeeded.
package db
import (
"context"
"strconv"
"gitee.com/derrickball/douyin/app/user/model"
)
func QueryRelation(ctx context.Context, to_user_id int64, follower_id int64) ([]*model.Relation, error) {
relations := make([]*model.Relation, 0)
if err := DB.WithContext(ctx).Where(map[string]interface{}{"to_user_id": to_user_id, "follower_id": follower_id}).Find(&relations).Error; err != nil {
return nil, err
}
return relations, nil
}
func CreateRelation(ctx context.Context, relation *model.Relation) error {
if err := DB.WithContext(ctx).Create(relation).Error; err != nil {
return err
}
return nil
}
func DeleteRelation(ctx context.Context, to_user_id int64, follower_id int64) error {
return DB.WithContext(ctx).Where("to_user_id = ? AND follower_id = ?", to_user_id, follower_id).Delete(&model.Relation{}).Error
}
// query the 粉丝
func QueryRelationFollower(ctx context.Context, to_user_id int64) ([]*model.Relation, error) {
relations := make([]*model.Relation, 0)
if err := DB.WithContext(ctx).Where("to_user_id = ?", strconv.FormatInt(to_user_id, 10)).Find(&relations).Error; err != nil {
return nil, err
}
return relations, nil
}
// query the 关注
func QueryRelationFollow(ctx context.Context, follower_id int64) ([]*model.Relation, error) {
relations := make([]*model.Relation, 0)
if err := DB.WithContext(ctx).Where("follower_id = ?", strconv.FormatInt(follower_id, 10)).Find(&relations).Error; err != nil {
return nil, err
}
return relations, nil
}
func QueryIsFollow(ctx context.Context, user int64, user_id int64) (bool, error) {
relations := make([]*model.Relation, 0)
if err := DB.WithContext(ctx).Where("to_user_id = ? AND follower_id = ?", user, user_id).Find(&relations).Error; err != nil {
return false, err
}
if len(relations) == 1 {
return true, nil
} else {
return false, nil
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。