mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Error code standardization
This commit is contained in:
parent
795a90a194
commit
22c63ecdbd
122
go.mod
122
go.mod
@ -1,6 +1,6 @@
|
||||
module Open_IM
|
||||
|
||||
go 1.18
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
firebase.google.com/go v3.13.0+incompatible
|
||||
@ -17,16 +17,11 @@ require (
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.12.9
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.16.9
|
||||
github.com/bwmarrin/snowflake v0.3.0
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/dtm-labs/rockscache v0.0.11
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/gin-gonic/gin v1.8.2
|
||||
github.com/go-openapi/spec v0.20.6 // indirect
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.11.1
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/goccy/go-json v0.10.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang-jwt/jwt/v4 v4.4.2
|
||||
github.com/golang/protobuf v1.5.2
|
||||
@ -34,7 +29,6 @@ require (
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||
github.com/jinzhu/copier v0.3.5
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/minio/minio-go/v7 v7.0.22
|
||||
github.com/mitchellh/mapstructure v1.4.2
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
@ -51,26 +45,124 @@ require (
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.428
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.428
|
||||
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca
|
||||
github.com/ugorji/go/codec v1.2.8 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.6
|
||||
go.mongodb.org/mongo-driver v1.8.3
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/crypto v0.5.0 // indirect
|
||||
golang.org/x/image v0.3.0
|
||||
golang.org/x/net v0.5.0
|
||||
golang.org/x/tools v0.1.12
|
||||
google.golang.org/api v0.103.0
|
||||
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
|
||||
google.golang.org/grpc v1.52.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
gorm.io/driver/mysql v1.3.5
|
||||
gorm.io/gorm v1.23.8
|
||||
)
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.105.0 // indirect
|
||||
cloud.google.com/go/compute v1.13.0 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.1 // indirect
|
||||
cloud.google.com/go/firestore v1.9.0 // indirect
|
||||
cloud.google.com/go/iam v0.8.0 // indirect
|
||||
cloud.google.com/go/longrunning v0.3.0 // indirect
|
||||
cloud.google.com/go/storage v1.27.0 // indirect
|
||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
github.com/OpenIMSDK/open_log v1.0.0 // indirect
|
||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
|
||||
github.com/alibabacloud-go/openapi-util v0.0.9 // indirect
|
||||
github.com/alibabacloud-go/tea-utils v1.3.9 // indirect
|
||||
github.com/aliyun/credentials-go v1.1.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.8 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.14 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.8 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.15 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.8 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.11.12 // indirect
|
||||
github.com/aws/smithy-go v1.12.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/coreos/go-semver v0.3.0 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/eapache/go-resiliency v1.2.0 // indirect
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
|
||||
github.com/eapache/queue v1.1.0 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.0 // indirect
|
||||
github.com/go-openapi/spec v0.20.6 // indirect
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/goccy/go-json v0.10.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
|
||||
github.com/golang/snappy v0.0.3 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
|
||||
github.com/hashicorp/go-uuid v1.0.2 // indirect
|
||||
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
|
||||
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
|
||||
github.com/jcmturner/gofork v1.0.0 // indirect
|
||||
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
|
||||
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/klauspost/cpuid v1.3.1 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/lestrrat-go/strftime v1.0.6 // indirect
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/minio/md5-simd v1.1.0 // indirect
|
||||
github.com/minio/sha256-simd v0.1.1 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
|
||||
github.com/pierrec/lz4 v2.6.0+incompatible // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.37.0 // indirect
|
||||
github.com/prometheus/procfs v0.8.0 // indirect
|
||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
|
||||
github.com/rs/xid v1.2.1 // indirect
|
||||
github.com/tjfoc/gmsm v1.3.2 // indirect
|
||||
github.com/ugorji/go/codec v1.2.8 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.0.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.6 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.6 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/crypto v0.5.0 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
golang.org/x/time v0.1.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/Shopify/sarama => github.com/Shopify/sarama v1.29.0
|
||||
|
@ -2,8 +2,8 @@ package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation1 "Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
@ -15,25 +15,25 @@ type FriendInterface interface {
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, friends []*table.FriendModel, revFriends []*table.FriendModel) (err error)
|
||||
BecomeFriend(ctx context.Context, friends []*relation.FriendModel, revFriends []*relation.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// Delete 删除好友
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
// UpdateRemark 更新好友备注
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error)
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error)
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error)
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error)
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriends 获取某人指定好友的信息 如果有一个不存在也返回错误
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error)
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendController struct {
|
||||
@ -55,17 +55,17 @@ func (f *FriendController) AddFriendRequest(ctx context.Context, fromUserID, toU
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, ownerUserID string, friends []*table.FriendModel) (err error) {
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error) {
|
||||
return f.database.BecomeFriend(ctx, ownerUserID, friends)
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
func (f *FriendController) RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendController) RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return f.database.RefuseFriendRequest(ctx, friendRequest)
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return f.database.AgreeFriendRequest(ctx, friendRequest)
|
||||
}
|
||||
|
||||
@ -80,27 +80,27 @@ func (f *FriendController) UpdateRemark(ctx context.Context, ownerUserID, friend
|
||||
}
|
||||
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
func (f *FriendController) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendController) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.database.FindOwnerFriends(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendController) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendController) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.database.FindInWhoseFriends(ctx, friendUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendController) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendController) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.database.FindFriendRequestFromMe(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.database.FindFriendRequestToMe(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
func (f *FriendController) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendController) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error) {
|
||||
return f.database.FindFriends(ctx, ownerUserID, friendUserIDs)
|
||||
|
||||
}
|
||||
@ -111,34 +111,34 @@ type FriendDatabaseInterface interface {
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, ownerUserID string, friends []*table.FriendModel) (err error)
|
||||
BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// Delete 删除好友
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
// UpdateRemark 更新好友备注
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error)
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error)
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error)
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error)
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error)
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendDatabase struct {
|
||||
friend *relation.FriendGorm
|
||||
friendRequest *relation.FriendRequestGorm
|
||||
friend *relation1.FriendGorm
|
||||
friendRequest *relation1.FriendRequestGorm
|
||||
}
|
||||
|
||||
func NewFriendDatabase(db *gorm.DB) *FriendDatabase {
|
||||
return &FriendDatabase{friend: relation.NewFriendGorm(db), friendRequest: relation.NewFriendRequestGorm(db)}
|
||||
return &FriendDatabase{friend: relation1.NewFriendGorm(db), friendRequest: relation1.NewFriendRequestGorm(db)}
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
@ -157,11 +157,31 @@ func (f *FriendDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (
|
||||
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
func (f *FriendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error) {
|
||||
|
||||
return f.friendRequest.DB.Transaction(func(tx *gorm.DB) error {
|
||||
fq, err := f.friendRequest.Find(ctx, fromUserID, toUserID, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fq != nil { //
|
||||
m := make(map[string]interface{}, 1)
|
||||
m["handle_result"] = 0
|
||||
m["handle_msg"] = ""
|
||||
m["req_msg"] = reqMsg
|
||||
m["ex"] = ex
|
||||
if err := f.friendRequest.UpdateByMap(ctx, fromUserID, toUserID, m, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := f.friendRequest.Create(ctx, []*relation.FriendRequestModel{&relation.FriendRequestModel{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex}}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, friends []*table.FriendModel) (err error) {
|
||||
func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error) {
|
||||
return f.friend.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
friendUserIDs := make([]string, 0, len(friends))
|
||||
@ -173,7 +193,7 @@ func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, f
|
||||
return err
|
||||
}
|
||||
fs1 = append(fs1, friends...)
|
||||
fs11 := utils.DistinctAny(fs1, func(e *table.FriendModel) string {
|
||||
fs11 := utils.DistinctAny(fs1, func(e *relation.FriendModel) string {
|
||||
return utils.UniqueJoin(e.OwnerUserID, e.FriendUserID)
|
||||
})
|
||||
err = f.friend.Create(ctx, fs11, tx)
|
||||
@ -185,9 +205,9 @@ func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, f
|
||||
return err
|
||||
}
|
||||
for _, v := range friends {
|
||||
fs2 = append(fs2, &table.FriendModel{OwnerUserID: v.FriendUserID, FriendUserID: ownerUserID})
|
||||
fs2 = append(fs2, &relation.FriendModel{OwnerUserID: v.FriendUserID, FriendUserID: ownerUserID})
|
||||
}
|
||||
fs22 := utils.DistinctAny(fs2, func(e *table.FriendModel) string {
|
||||
fs22 := utils.DistinctAny(fs2, func(e *relation.FriendModel) string {
|
||||
return utils.UniqueJoin(e.OwnerUserID, e.FriendUserID)
|
||||
})
|
||||
err = f.friend.Create(ctx, fs22, tx)
|
||||
@ -199,9 +219,9 @@ func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, f
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
friendRequest.HandleResult = constant.FriendResponseRefuse
|
||||
err = f.friendRequest.Update(ctx, []*table.FriendRequestModel{friendRequest})
|
||||
err = f.friendRequest.Update(ctx, []*relation.FriendRequestModel{friendRequest})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -209,7 +229,7 @@ func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return f.friend.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
fs1, err := f.friend.FindFriends(ctx, friendRequest.FromUserID, []string{friendRequest.ToUserID}, tx)
|
||||
@ -217,8 +237,8 @@ func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *
|
||||
return err
|
||||
}
|
||||
if len(fs1) == 0 {
|
||||
err = f.friend.Create(ctx, []*table.FriendModel{
|
||||
&table.FriendModel{
|
||||
err = f.friend.Create(ctx, []*relation.FriendModel{
|
||||
&relation.FriendModel{
|
||||
OwnerUserID: friendRequest.FromUserID,
|
||||
FriendUserID: friendRequest.ToUserID,
|
||||
OperatorUserID: friendRequest.ToUserID,
|
||||
@ -230,8 +250,8 @@ func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *
|
||||
}
|
||||
fs2, err := f.friend.FindReversalFriends(ctx, friendRequest.ToUserID, []string{friendRequest.FromUserID}, tx)
|
||||
if len(fs2) == 0 {
|
||||
err = f.friend.Create(ctx, []*table.FriendModel{
|
||||
&table.FriendModel{
|
||||
err = f.friend.Create(ctx, []*relation.FriendModel{
|
||||
&relation.FriendModel{
|
||||
OwnerUserID: friendRequest.ToUserID,
|
||||
FriendUserID: friendRequest.FromUserID,
|
||||
OperatorUserID: friendRequest.ToUserID,
|
||||
@ -242,7 +262,7 @@ func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *
|
||||
}
|
||||
}
|
||||
friendRequest.HandleResult = constant.FriendResponseAgree
|
||||
err = f.friendRequest.Update(ctx, []*table.FriendRequestModel{friendRequest}, tx)
|
||||
err = f.friendRequest.Update(ctx, []*relation.FriendRequestModel{friendRequest}, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -261,27 +281,27 @@ func (f *FriendDatabase) UpdateRemark(ctx context.Context, ownerUserID, friendUs
|
||||
}
|
||||
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
func (f *FriendDatabase) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendDatabase) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.friend.FindOwnerFriends(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.friend.FindInWhoseFriends(ctx, friendUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.friendRequest.FindFromUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.friendRequest.FindToUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriends 获取某人指定好友的信息 如果有一个不存在,也返回错误
|
||||
func (f *FriendDatabase) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendDatabase) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error) {
|
||||
friends, err = f.friend.FindFriends(ctx, ownerUserID, friendUserIDs)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -9,12 +9,12 @@ import (
|
||||
)
|
||||
|
||||
type FriendDB interface {
|
||||
Create(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||
Create(ctx context.Context, friends []*relation.FriendModel) (err error)
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||
Update(ctx context.Context, friends []*relation.FriendModel) (err error)
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*table.FriendModel, err error)
|
||||
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendGorm struct {
|
||||
@ -30,7 +30,7 @@ type FriendUser struct {
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Create(ctx context.Context, friends []*table.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
func (f *FriendGorm) Create(ctx context.Context, friends []*relation.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
@ -52,7 +52,7 @@ func (f *FriendGorm) UpdateByMap(ctx context.Context, ownerUserID string, args m
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Update(ctx context.Context, friends []*table.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
func (f *FriendGorm) Update(ctx context.Context, friends []*relation.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
@ -66,27 +66,27 @@ func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("friend_user_id = ?", friendUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *table.FriendModel, err error) {
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.FriendModel, err error) {
|
||||
friend = &table.FriendModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "friend", friend)
|
||||
return friend, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "userID1", userID1, "userID2", userID2)
|
||||
}()
|
||||
@ -94,7 +94,7 @@ func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string)
|
||||
}
|
||||
|
||||
// 获取 owner的好友列表 如果不存在也不返回错误
|
||||
func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, tx ...*gorm.DB) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, tx ...*gorm.DB) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserIDs", friendUserIDs, "friends", friends)
|
||||
}()
|
||||
@ -102,14 +102,14 @@ func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friend
|
||||
}
|
||||
|
||||
// 获取哪些人添加了friendUserID 如果不存在也不返回错误
|
||||
func (f *FriendGorm) FindReversalFriends(ctx context.Context, friendUserID string, ownerUserIDs []string, tx ...*gorm.DB) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindReversalFriends(ctx context.Context, friendUserID string, ownerUserIDs []string, tx ...*gorm.DB) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(getDBConn(f.DB, tx).Where("friend_user_id = ? AND owner_user_id in (?)", friendUserID, ownerUserIDs).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
}()
|
||||
@ -121,7 +121,7 @@ func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, p
|
||||
return
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendGorm) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
}()
|
||||
|
@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -20,69 +20,68 @@ type FriendRequestGorm struct {
|
||||
DB *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Create(ctx context.Context, friends []*table.FriendRequestModel) (err error) {
|
||||
func (f *FriendRequestGorm) Create(ctx context.Context, friends []*relation.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Create(&friends).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Create(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&table.FriendRequestModel{}).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&relation.FriendRequestModel{}).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, formUserID string, toUserID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "formUserID", formUserID, "toUserID", toUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? AND to_user_id ", formUserID, toUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests []*table.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests []*relation.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendRequests", friendRequests)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Updates(&friendRequests).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Updates(&friendRequests).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, ownerUserID string) (friends []*table.FriendRequestModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Take(ctx context.Context, fromUserID, toUserID string) (friend *table.FriendRequestModel, err error) {
|
||||
friend = &table.FriendRequestModel{}
|
||||
func (f *FriendRequestGorm) Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequestModel, err error) {
|
||||
friend = &relation.FriendRequestModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID, "friend", friend)
|
||||
return friend, utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friend).Error, "")
|
||||
return friend, utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindToUserID(ctx context.Context, toUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, fromUserID, toUserID string, tx ...*gorm.DB) (friend *relation.FriendRequestModel, err error) {
|
||||
friend = &relation.FriendRequestModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID, "friend", friend)
|
||||
return friend, utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Find(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindToUserID(ctx context.Context, toUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "toUserID", toUserID, "friends", friends)
|
||||
}()
|
||||
|
||||
err = getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Count(&total).Error
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "friends", friends)
|
||||
}()
|
||||
|
||||
err = getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Count(&total).Error
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user