test-errcode
wangchuxiao 2 years ago
parent e888910f3c
commit a0f3307fe3

@ -31,15 +31,15 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.Universal
userRouterGroup := r.Group("/user")
{
u := NewUser(zk)
userRouterGroupChild1 := mw.NewRouterGroup(userRouterGroup, "",)
userRouterGroupChild2 := mw.NewRouterGroup(userRouterGroup, "", mw.WithGinParseToken(rdb))
userRouterGroupChild1.POST("/user_register", u.UserRegister)
userRouterGroupChild2.POST("/update_user_info", u.UpdateUserInfo) //1
userRouterGroupChild2.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
userRouterGroupChild2.POST("/get_users_info", u.GetUsersPublicInfo) //1
userRouterGroupChild2.POST("/get_all_users_uid", u.GetAllUsersID) // todo
userRouterGroupChild2.POST("/account_check", u.AccountCheck) // todo
userRouterGroupChild2.POST("/get_users", u.GetUsers)
userRouterGroupChild := mw.NewRouterGroup(userRouterGroup, "",)
userRouterGroupChildToken := mw.NewRouterGroup(userRouterGroup, "", mw.WithGinParseToken(rdb))
userRouterGroupChild.POST("/user_register", u.UserRegister)
userRouterGroupChildToken.POST("/update_user_info", u.UpdateUserInfo) //1
userRouterGroupChildToken.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
userRouterGroupChildToken.POST("/get_users_info", u.GetUsersPublicInfo) //1
userRouterGroupChildToken.POST("/get_all_users_uid", u.GetAllUsersID) // todo
userRouterGroupChildToken.POST("/account_check", u.AccountCheck) // todo
userRouterGroupChildToken.POST("/get_users", u.GetUsers)
}
////friend routing group
friendRouterGroup := r.Group("/friend")
@ -94,12 +94,12 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.Universal
{
a := NewAuth(zk)
u := NewUser(zk)
authRouterGroupChild1 := mw.NewRouterGroup(authRouterGroup, "",)
authRouterGroupChild2 := mw.NewRouterGroup(authRouterGroup, "", mw.WithGinParseToken(rdb))
authRouterGroupChild1.POST("/user_register", u.UserRegister) //1
authRouterGroupChild1.POST("/user_token", a.UserToken) //1
authRouterGroupChild2.POST("/parse_token", a.ParseToken) //1
authRouterGroupChild2.POST("/force_logout", a.ForceLogout) //1
authRouterGroupChild := mw.NewRouterGroup(authRouterGroup, "",)
authRouterGroupChildToken := mw.NewRouterGroup(authRouterGroup, "", mw.WithGinParseToken(rdb))
authRouterGroupChild.POST("/user_register", u.UserRegister) //1
authRouterGroupChild.POST("/user_token", a.UserToken) //1
authRouterGroupChildToken.POST("/parse_token", a.ParseToken) //1
authRouterGroupChildToken.POST("/force_logout", a.ForceLogout) //1
}
////Third service
thirdGroup := r.Group("/third")

@ -48,28 +48,27 @@ func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID
m := make(map[string]interface{}, 1)
m["remark"] = ""
return utils.Wrap(f.db(ctx).Where("owner_user_id = ?", ownerUserID).Updates(m).Error, "")
}
// 获取单个好友信息,如没找到 返回错误
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.FriendModel, err error) {
friend = &relation.FriendModel{}
return friend, utils.Wrap(f.DB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
return friend, utils.Wrap(f.db(ctx).Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
}
// 查找好友关系,如果是双向关系,则都返回
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.FriendModel, err error) {
return friends, utils.Wrap(f.DB.Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
return friends, utils.Wrap(f.db(ctx).Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
}
// 获取 owner指定的好友列表 如果有friendUserIDs不存在也不返回错误
func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error) {
return friends, utils.Wrap(f.DB.Where("owner_user_id = ? AND friend_user_id in (?)", ownerUserID, friendUserIDs).Find(&friends).Error, "")
return friends, utils.Wrap(f.db(ctx).Where("owner_user_id = ? AND friend_user_id in (?)", ownerUserID, friendUserIDs).Find(&friends).Error, "")
}
// 获取哪些人添加了friendUserID 如果有ownerUserIDs不存在也不返回错误
func (f *FriendGorm) FindReversalFriends(ctx context.Context, friendUserID string, ownerUserIDs []string) (friends []*relation.FriendModel, err error) {
return friends, utils.Wrap(f.DB.Where("friend_user_id = ? AND owner_user_id in (?)", friendUserID, ownerUserIDs).Find(&friends).Error, "")
return friends, utils.Wrap(f.db(ctx).Where("friend_user_id = ? AND owner_user_id in (?)", friendUserID, ownerUserIDs).Find(&friends).Error, "")
}
// 获取ownerUserID好友列表 支持翻页
@ -78,7 +77,7 @@ func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, p
if err != nil {
return nil, 0, utils.Wrap(err, "")
}
err = utils.Wrap(f.DB.Where("owner_user_id = ? ", ownerUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
err = utils.Wrap(f.db(ctx).Where("owner_user_id = ? ", ownerUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
return
}
@ -88,10 +87,10 @@ func (f *FriendGorm) FindInWhoseFriends(ctx context.Context, friendUserID string
if err != nil {
return nil, 0, utils.Wrap(err, "")
}
err = utils.Wrap(f.DB.Where("friend_user_id = ? ", friendUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
err = utils.Wrap(f.db(ctx).Where("friend_user_id = ? ", friendUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
return
}
func (f *FriendGorm) FindFriendUserIDs(ctx context.Context, ownerUserID string) (friendUserIDs []string, err error) {
return friendUserIDs, utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("owner_user_id = ? ", ownerUserID).Pluck("friend_user_id", &friendUserIDs).Error, "")
return friendUserIDs, utils.Wrap(f.db(ctx).Model(&relation.FriendModel{}).Where("owner_user_id = ? ", ownerUserID).Pluck("friend_user_id", &friendUserIDs).Error, "")
}

Loading…
Cancel
Save