7 Star 1 Fork 1

罗中天/douyin

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
relation.go 1.80 KB
Copy Edit Raw Blame History
黎博凯 authored 2023-02-13 22:33 +08:00 . merge:relation模块 简单测试通过
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
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/derrickball/douyin.git
git@gitee.com:derrickball/douyin.git
derrickball
douyin
douyin
48d44dfe16fa

Search