Ver a proveniência

add isFriends rpc api

master
DengBiao há 1 ano
ascendente
cometimento
f07438bcf9
4 ficheiros alterados com 86 adições e 47 eliminações
  1. +42
    -4
      internal/business/api/business_ext.go
  2. +40
    -40
      pkg/pb/business.ext.pb.go
  3. +3
    -2
      pkg/proto/business.ext.proto
  4. +1
    -1
      sql/create_table.sql

+ 42
- 4
internal/business/api/business_ext.go Ver ficheiro

@@ -2,10 +2,12 @@ package api

import (
"context"
"errors"
"gim/internal/business/app"
comm "gim/internal/business/comm"
"gim/internal/business/comm/utils"
"gim/internal/business/domain/user/repo"
friend2 "gim/internal/logic/domain/friend"
"gim/internal/logic/domain/message/service"
"gim/pkg/grpclib"
"gim/pkg/pb"
@@ -14,10 +16,46 @@ import (

type BusinessExtServer struct{}

func (s *BusinessExtServer) IsFriends(ctx context.Context, req *pb.IsFriendsReq) (*pb.EmoticonListResp, error) {
//masterId, err := grpclib.GetCtxMasterId(ctx)
//TODO implement me
panic("implement me")
func (s *BusinessExtServer) IsFriends(ctx context.Context, req *pb.IsFriendsReq) (*pb.IsFriendsResp, error) {
masterId, err := grpclib.GetCtxMasterId(ctx)
if err != nil {
return nil, err
}
user, err := repo.UserRepo.GetByPhoneNumber(req.UserPhone, utils.StrToInt64(masterId))
if err != nil {
return nil, err
}
if user == nil {
return nil, errors.New("未查询到自身用户信息")
}

userFriend, err := repo.UserRepo.GetByPhoneNumber(req.FriendPhone, utils.StrToInt64(masterId))
if err != nil {
return nil, err
}
if userFriend == nil {
return nil, errors.New("未查询到好友用户信息")
}
friend, err := friend2.FriendRepo.Get(user.Id, userFriend.Id)
if err != nil {
return nil, err
}
var isFriend = int64(0)
if friend == nil {
isFriend = 0
}

return &pb.IsFriendsResp{
User: &pb.User{
UserId: user.Id,
Nickname: user.Nickname,
Sex: user.Sex,
AvatarUrl: user.AvatarUrl,
MasterId: user.MasterId,
IsAutoAddedFriends: int64(user.IsAutoAddedFriends),
},
IsFriend: isFriend,
}, err
}

func (s *BusinessExtServer) EmoticonList(ctx context.Context, empty *pb.Empty) (*pb.EmoticonListResp, error) {


+ 40
- 40
pkg/pb/business.ext.pb.go Ver ficheiro

@@ -85,7 +85,7 @@ type IsFriendsResp struct {
unknownFields protoimpl.UnknownFields

IsFriend int64 `protobuf:"varint,1,opt,name=is_friend,json=isFriend,proto3" json:"is_friend,omitempty"`
IsCanAdd int64 `protobuf:"varint,2,opt,name=is_can_add,json=isCanAdd,proto3" json:"is_can_add,omitempty"`
User *User `protobuf:"bytes,2,opt,name=user,proto3" json:"user,omitempty"` // 用户信息
}

func (x *IsFriendsResp) Reset() {
@@ -127,11 +127,11 @@ func (x *IsFriendsResp) GetIsFriend() int64 {
return 0
}

func (x *IsFriendsResp) GetIsCanAdd() int64 {
func (x *IsFriendsResp) GetUser() *User {
if x != nil {
return x.IsCanAdd
return x.User
}
return 0
return nil
}

type Emoticon struct {
@@ -935,9 +935,9 @@ var file_business_ext_proto_rawDesc = []byte{
0x0b, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x68, 0x6f, 0x6e, 0x65, 0x22, 0x4a, 0x0a, 0x0d,
0x49, 0x73, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a,
0x09, 0x69, 0x73, 0x5f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03,
0x52, 0x08, 0x69, 0x73, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x12, 0x1c, 0x0a, 0x0a, 0x69, 0x73,
0x5f, 0x63, 0x61, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08,
0x69, 0x73, 0x43, 0x61, 0x6e, 0x41, 0x64, 0x64, 0x22, 0x5f, 0x0a, 0x08, 0x45, 0x6d, 0x6f, 0x74,
0x52, 0x08, 0x69, 0x73, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73,
0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73,
0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x5f, 0x0a, 0x08, 0x45, 0x6d, 0x6f, 0x74,
0x69, 0x63, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x6d, 0x67, 0x5f,
0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x6d, 0x67, 0x55, 0x72,
@@ -1015,7 +1015,7 @@ var file_business_ext_proto_rawDesc = []byte{
0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x49, 0x64, 0x22, 0x30, 0x0a, 0x0e, 0x53, 0x65, 0x61, 0x72,
0x63, 0x68, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x05, 0x75, 0x73,
0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55,
0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x32, 0xed, 0x02, 0x0a, 0x0b, 0x42,
0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x32, 0xea, 0x02, 0x0a, 0x0b, 0x42,
0x75, 0x73, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x45, 0x78, 0x74, 0x12, 0x27, 0x0a, 0x06, 0x53, 0x69,
0x67, 0x6e, 0x49, 0x6e, 0x12, 0x0d, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e,
0x52, 0x65, 0x71, 0x1a, 0x0e, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x49, 0x6e, 0x52,
@@ -1035,12 +1035,11 @@ var file_business_ext_proto_rawDesc = []byte{
0x52, 0x65, 0x73, 0x70, 0x12, 0x2f, 0x0a, 0x0c, 0x45, 0x6d, 0x6f, 0x74, 0x69, 0x63, 0x6f, 0x6e,
0x4c, 0x69, 0x73, 0x74, 0x12, 0x09, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a,
0x14, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x6f, 0x74, 0x69, 0x63, 0x6f, 0x6e, 0x4c, 0x69, 0x73,
0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x33, 0x0a, 0x09, 0x49, 0x73, 0x46, 0x72, 0x69, 0x65, 0x6e,
0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x30, 0x0a, 0x09, 0x49, 0x73, 0x46, 0x72, 0x69, 0x65, 0x6e,
0x64, 0x73, 0x12, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x49, 0x73, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64,
0x73, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x6f, 0x74, 0x69, 0x63,
0x6f, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x42, 0x0d, 0x5a, 0x0b, 0x67, 0x69,
0x6d, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
0x73, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x70, 0x62, 0x2e, 0x49, 0x73, 0x46, 0x72, 0x69, 0x65,
0x6e, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x42, 0x0d, 0x5a, 0x0b, 0x67, 0x69, 0x6d, 0x2f, 0x70,
0x6b, 0x67, 0x2f, 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}

var (
@@ -1074,28 +1073,29 @@ var file_business_ext_proto_goTypes = []interface{}{
(*Empty)(nil), // 14: pb.Empty
}
var file_business_ext_proto_depIdxs = []int32{
2, // 0: pb.EmoticonListResp.emoticons:type_name -> pb.Emoticon
8, // 1: pb.GetUserResp.user:type_name -> pb.User
8, // 2: pb.SearchUserResp.users:type_name -> pb.User
4, // 3: pb.BusinessExt.SignIn:input_type -> pb.SignInReq
9, // 4: pb.BusinessExt.GetUser:input_type -> pb.GetUserReq
11, // 5: pb.BusinessExt.UpdateUser:input_type -> pb.UpdateUserReq
12, // 6: pb.BusinessExt.SearchUser:input_type -> pb.SearchUserReq
6, // 7: pb.BusinessExt.CloudUploadFile:input_type -> pb.CloudUploadFileReq
14, // 8: pb.BusinessExt.EmoticonList:input_type -> pb.Empty
0, // 9: pb.BusinessExt.IsFriends:input_type -> pb.IsFriendsReq
5, // 10: pb.BusinessExt.SignIn:output_type -> pb.SignInResp
10, // 11: pb.BusinessExt.GetUser:output_type -> pb.GetUserResp
14, // 12: pb.BusinessExt.UpdateUser:output_type -> pb.Empty
13, // 13: pb.BusinessExt.SearchUser:output_type -> pb.SearchUserResp
7, // 14: pb.BusinessExt.CloudUploadFile:output_type -> pb.CloudUploadFileResp
3, // 15: pb.BusinessExt.EmoticonList:output_type -> pb.EmoticonListResp
3, // 16: pb.BusinessExt.IsFriends:output_type -> pb.EmoticonListResp
10, // [10:17] is the sub-list for method output_type
3, // [3:10] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
8, // 0: pb.IsFriendsResp.user:type_name -> pb.User
2, // 1: pb.EmoticonListResp.emoticons:type_name -> pb.Emoticon
8, // 2: pb.GetUserResp.user:type_name -> pb.User
8, // 3: pb.SearchUserResp.users:type_name -> pb.User
4, // 4: pb.BusinessExt.SignIn:input_type -> pb.SignInReq
9, // 5: pb.BusinessExt.GetUser:input_type -> pb.GetUserReq
11, // 6: pb.BusinessExt.UpdateUser:input_type -> pb.UpdateUserReq
12, // 7: pb.BusinessExt.SearchUser:input_type -> pb.SearchUserReq
6, // 8: pb.BusinessExt.CloudUploadFile:input_type -> pb.CloudUploadFileReq
14, // 9: pb.BusinessExt.EmoticonList:input_type -> pb.Empty
0, // 10: pb.BusinessExt.IsFriends:input_type -> pb.IsFriendsReq
5, // 11: pb.BusinessExt.SignIn:output_type -> pb.SignInResp
10, // 12: pb.BusinessExt.GetUser:output_type -> pb.GetUserResp
14, // 13: pb.BusinessExt.UpdateUser:output_type -> pb.Empty
13, // 14: pb.BusinessExt.SearchUser:output_type -> pb.SearchUserResp
7, // 15: pb.BusinessExt.CloudUploadFile:output_type -> pb.CloudUploadFileResp
3, // 16: pb.BusinessExt.EmoticonList:output_type -> pb.EmoticonListResp
1, // 17: pb.BusinessExt.IsFriends:output_type -> pb.IsFriendsResp
11, // [11:18] is the sub-list for method output_type
4, // [4:11] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension type_name
4, // [4:4] is the sub-list for extension extendee
0, // [0:4] is the sub-list for field type_name
}

func init() { file_business_ext_proto_init() }
@@ -1316,7 +1316,7 @@ type BusinessExtClient interface {
// 获取表情
EmoticonList(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*EmoticonListResp, error)
// 判断是否为好友关系
IsFriends(ctx context.Context, in *IsFriendsReq, opts ...grpc.CallOption) (*EmoticonListResp, error)
IsFriends(ctx context.Context, in *IsFriendsReq, opts ...grpc.CallOption) (*IsFriendsResp, error)
}

type businessExtClient struct {
@@ -1381,8 +1381,8 @@ func (c *businessExtClient) EmoticonList(ctx context.Context, in *Empty, opts ..
return out, nil
}

func (c *businessExtClient) IsFriends(ctx context.Context, in *IsFriendsReq, opts ...grpc.CallOption) (*EmoticonListResp, error) {
out := new(EmoticonListResp)
func (c *businessExtClient) IsFriends(ctx context.Context, in *IsFriendsReq, opts ...grpc.CallOption) (*IsFriendsResp, error) {
out := new(IsFriendsResp)
err := c.cc.Invoke(ctx, "/pb.BusinessExt/IsFriends", in, out, opts...)
if err != nil {
return nil, err
@@ -1407,7 +1407,7 @@ type BusinessExtServer interface {
// 获取表情
EmoticonList(context.Context, *Empty) (*EmoticonListResp, error)
// 判断是否为好友关系
IsFriends(context.Context, *IsFriendsReq) (*EmoticonListResp, error)
IsFriends(context.Context, *IsFriendsReq) (*IsFriendsResp, error)
}

// UnimplementedBusinessExtServer must be embedded to have forward compatible implementations.
@@ -1432,7 +1432,7 @@ func (UnimplementedBusinessExtServer) CloudUploadFile(context.Context, *CloudUpl
func (UnimplementedBusinessExtServer) EmoticonList(context.Context, *Empty) (*EmoticonListResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method EmoticonList not implemented")
}
func (UnimplementedBusinessExtServer) IsFriends(context.Context, *IsFriendsReq) (*EmoticonListResp, error) {
func (UnimplementedBusinessExtServer) IsFriends(context.Context, *IsFriendsReq) (*IsFriendsResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method IsFriends not implemented")
}



+ 3
- 2
pkg/proto/business.ext.proto Ver ficheiro

@@ -18,7 +18,7 @@ service BusinessExt {
// 获取表情
rpc EmoticonList (Empty) returns (EmoticonListResp);
// 判断是否为好友关系
rpc IsFriends (IsFriendsReq) returns (EmoticonListResp);
rpc IsFriends (IsFriendsReq) returns (IsFriendsResp);
}


@@ -29,8 +29,9 @@ message IsFriendsReq {

message IsFriendsResp {
int64 is_friend = 1;
int64 is_can_add = 2;
User user = 2; // 用户信息
}

message Emoticon {
string name = 1; // 名称
string img_url = 2; // 图片地址


+ 1
- 1
sql/create_table.sql Ver ficheiro

@@ -33,7 +33,7 @@ CREATE TABLE `friend`
`friend_id` bigint(20) unsigned NOT NULL COMMENT '好友id',
`remarks` varchar(20) NOT NULL COMMENT '备注',
`extra` varchar(1024) NOT NULL COMMENT '附加属性',
`status` tinyint(4) NOT NULL COMMENT '状态,1:申请,2:同意',
`status` tinyint(4) NOT NULL COMMENT '状态,0:申请,1:同意',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),


Carregando…
Cancelar
Guardar