7 Star 1 Fork 1

罗中天 / douyin

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
user.go 1.46 KB
Copy Edit Raw Blame History
LavenderHaze authored 2023-02-14 04:10 . update拼写错误updata
package db
import (
"context"
"gitee.com/derrickball/douyin/app/user/model"
"gorm.io/gorm"
)
func QueryUser(ctx context.Context, userName string) ([]*model.User, error) {
users := make([]*model.User, 0)
if err := DB.WithContext(ctx).Where("username = ?", userName).Find(&users).Error; err != nil {
return nil, err
}
return users, nil
}
func CreateUser(ctx context.Context, user *model.User) error {
return DB.WithContext(ctx).Create(user).Error
}
func QueryUserById(ctx context.Context, users_id []int64) ([]*model.User, error) {
users := make([]*model.User, 0)
result := DB.WithContext(ctx).Where(users_id).Find(&users)
err := result.Error
if err != nil {
return nil, err
}
return users, nil
}
func UpdateFollowCount(ctx context.Context, to_user_id int64, follower_id int64, flag bool) error {
if flag {
if err := DB.Model(&model.User{}).Where("id = ?", to_user_id).Update("follower_Count", gorm.Expr("follower_count+?", 1)).Error; err != nil {
return err
}
if err := DB.Model(&model.User{}).Where("id = ?", follower_id).Update("follow_count", gorm.Expr("follow_count+?", 1)).Error; err != nil {
return err
}
} else {
if err := DB.Model(&model.User{}).Where("id = ?", to_user_id).Update("follower_Count", gorm.Expr("follower_count-?", 1)).Error; err != nil {
return err
}
if err := DB.Model(&model.User{}).Where("id = ?", follower_id).Update("follow_count", gorm.Expr("follow_count-?", 1)).Error; err != nil {
return err
}
}
return nil
}
1
https://gitee.com/derrickball/douyin.git
git@gitee.com:derrickball/douyin.git
derrickball
douyin
douyin
48d44dfe16fa

Search