feat: 添加 GetUsersByIds 批量用户查询接口
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"juwan-backend/app/users/rpc/internal/models/users"
|
||||
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUsersByIdsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetUsersByIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUsersByIdsLogic {
|
||||
return &GetUsersByIdsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUsersByIdsLogic) GetUsersByIds(in *pb.GetUsersByIdsReq) (*pb.GetUsersByIdsResp, error) {
|
||||
if len(in.Ids) == 0 {
|
||||
return &pb.GetUsersByIdsResp{}, nil
|
||||
}
|
||||
|
||||
userList, err := l.svcCtx.UsersModelRO.Users.Query().Where(users.IDIn(in.Ids...)).All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.GetUsersByIdsResp{Users: ConvertEntUsersToProto(userList)}, nil
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// goctl 1.10.1
|
||||
// Source: users.proto
|
||||
|
||||
package server
|
||||
@@ -44,6 +44,11 @@ func (s *UsercenterServer) GetUsersById(ctx context.Context, in *pb.GetUsersById
|
||||
return l.GetUsersById(in)
|
||||
}
|
||||
|
||||
func (s *UsercenterServer) GetUsersByIds(ctx context.Context, in *pb.GetUsersByIdsReq) (*pb.GetUsersByIdsResp, error) {
|
||||
l := logic.NewGetUsersByIdsLogic(ctx, s.svcCtx)
|
||||
return l.GetUsersByIds(in)
|
||||
}
|
||||
|
||||
func (s *UsercenterServer) SearchUsers(ctx context.Context, in *pb.SearchUsersReq) (*pb.SearchUsersResp, error) {
|
||||
l := logic.NewSearchUsersLogic(ctx, s.svcCtx)
|
||||
return l.SearchUsers(in)
|
||||
|
||||
+321
-223
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.1
|
||||
// - protoc v5.29.6
|
||||
// - protoc v7.34.1
|
||||
// source: users.proto
|
||||
|
||||
package pb
|
||||
@@ -23,6 +23,7 @@ const (
|
||||
Usercenter_UpdateUsers_FullMethodName = "/pb.usercenter/UpdateUsers"
|
||||
Usercenter_DelUsers_FullMethodName = "/pb.usercenter/DelUsers"
|
||||
Usercenter_GetUsersById_FullMethodName = "/pb.usercenter/GetUsersById"
|
||||
Usercenter_GetUsersByIds_FullMethodName = "/pb.usercenter/GetUsersByIds"
|
||||
Usercenter_SearchUsers_FullMethodName = "/pb.usercenter/SearchUsers"
|
||||
Usercenter_GetUserByUsername_FullMethodName = "/pb.usercenter/GetUserByUsername"
|
||||
Usercenter_Login_FullMethodName = "/pb.usercenter/Login"
|
||||
@@ -53,6 +54,7 @@ type UsercenterClient interface {
|
||||
UpdateUsers(ctx context.Context, in *UpdateUsersReq, opts ...grpc.CallOption) (*UpdateUsersResp, error)
|
||||
DelUsers(ctx context.Context, in *DelUsersReq, opts ...grpc.CallOption) (*DelUsersResp, error)
|
||||
GetUsersById(ctx context.Context, in *GetUsersByIdReq, opts ...grpc.CallOption) (*GetUsersByIdResp, error)
|
||||
GetUsersByIds(ctx context.Context, in *GetUsersByIdsReq, opts ...grpc.CallOption) (*GetUsersByIdsResp, error)
|
||||
SearchUsers(ctx context.Context, in *SearchUsersReq, opts ...grpc.CallOption) (*SearchUsersResp, error)
|
||||
GetUserByUsername(ctx context.Context, in *GetUserByUsernameReq, opts ...grpc.CallOption) (*GetUserByUsernameResp, error)
|
||||
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*LoginResp, error)
|
||||
@@ -124,6 +126,16 @@ func (c *usercenterClient) GetUsersById(ctx context.Context, in *GetUsersByIdReq
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usercenterClient) GetUsersByIds(ctx context.Context, in *GetUsersByIdsReq, opts ...grpc.CallOption) (*GetUsersByIdsResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetUsersByIdsResp)
|
||||
err := c.cc.Invoke(ctx, Usercenter_GetUsersByIds_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usercenterClient) SearchUsers(ctx context.Context, in *SearchUsersReq, opts ...grpc.CallOption) (*SearchUsersResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(SearchUsersResp)
|
||||
@@ -323,6 +335,7 @@ type UsercenterServer interface {
|
||||
UpdateUsers(context.Context, *UpdateUsersReq) (*UpdateUsersResp, error)
|
||||
DelUsers(context.Context, *DelUsersReq) (*DelUsersResp, error)
|
||||
GetUsersById(context.Context, *GetUsersByIdReq) (*GetUsersByIdResp, error)
|
||||
GetUsersByIds(context.Context, *GetUsersByIdsReq) (*GetUsersByIdsResp, error)
|
||||
SearchUsers(context.Context, *SearchUsersReq) (*SearchUsersResp, error)
|
||||
GetUserByUsername(context.Context, *GetUserByUsernameReq) (*GetUserByUsernameResp, error)
|
||||
Login(context.Context, *LoginReq) (*LoginResp, error)
|
||||
@@ -366,6 +379,9 @@ func (UnimplementedUsercenterServer) DelUsers(context.Context, *DelUsersReq) (*D
|
||||
func (UnimplementedUsercenterServer) GetUsersById(context.Context, *GetUsersByIdReq) (*GetUsersByIdResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetUsersById not implemented")
|
||||
}
|
||||
func (UnimplementedUsercenterServer) GetUsersByIds(context.Context, *GetUsersByIdsReq) (*GetUsersByIdsResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetUsersByIds not implemented")
|
||||
}
|
||||
func (UnimplementedUsercenterServer) SearchUsers(context.Context, *SearchUsersReq) (*SearchUsersResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method SearchUsers not implemented")
|
||||
}
|
||||
@@ -516,6 +532,24 @@ func _Usercenter_GetUsersById_Handler(srv interface{}, ctx context.Context, dec
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Usercenter_GetUsersByIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUsersByIdsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UsercenterServer).GetUsersByIds(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Usercenter_GetUsersByIds_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UsercenterServer).GetUsersByIds(ctx, req.(*GetUsersByIdsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Usercenter_SearchUsers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchUsersReq)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -881,6 +915,10 @@ var Usercenter_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "GetUsersById",
|
||||
Handler: _Usercenter_GetUsersById_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUsersByIds",
|
||||
Handler: _Usercenter_GetUsersByIds_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SearchUsers",
|
||||
Handler: _Usercenter_SearchUsers_Handler,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// goctl 1.10.1
|
||||
// Source: users.proto
|
||||
|
||||
package usercenter
|
||||
@@ -36,6 +36,8 @@ type (
|
||||
GetUserPreferencesByIdResp = pb.GetUserPreferencesByIdResp
|
||||
GetUsersByIdReq = pb.GetUsersByIdReq
|
||||
GetUsersByIdResp = pb.GetUsersByIdResp
|
||||
GetUsersByIdsReq = pb.GetUsersByIdsReq
|
||||
GetUsersByIdsResp = pb.GetUsersByIdsResp
|
||||
LoginReq = pb.LoginReq
|
||||
LoginResp = pb.LoginResp
|
||||
LogoutReq = pb.LogoutReq
|
||||
@@ -70,6 +72,7 @@ type (
|
||||
UpdateUsers(ctx context.Context, in *UpdateUsersReq, opts ...grpc.CallOption) (*UpdateUsersResp, error)
|
||||
DelUsers(ctx context.Context, in *DelUsersReq, opts ...grpc.CallOption) (*DelUsersResp, error)
|
||||
GetUsersById(ctx context.Context, in *GetUsersByIdReq, opts ...grpc.CallOption) (*GetUsersByIdResp, error)
|
||||
GetUsersByIds(ctx context.Context, in *GetUsersByIdsReq, opts ...grpc.CallOption) (*GetUsersByIdsResp, error)
|
||||
SearchUsers(ctx context.Context, in *SearchUsersReq, opts ...grpc.CallOption) (*SearchUsersResp, error)
|
||||
GetUserByUsername(ctx context.Context, in *GetUserByUsernameReq, opts ...grpc.CallOption) (*GetUserByUsernameResp, error)
|
||||
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*LoginResp, error)
|
||||
@@ -125,6 +128,11 @@ func (m *defaultUsercenter) GetUsersById(ctx context.Context, in *GetUsersByIdRe
|
||||
return client.GetUsersById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUsercenter) GetUsersByIds(ctx context.Context, in *GetUsersByIdsReq, opts ...grpc.CallOption) (*GetUsersByIdsResp, error) {
|
||||
client := pb.NewUsercenterClient(m.cli.Conn())
|
||||
return client.GetUsersByIds(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUsercenter) SearchUsers(ctx context.Context, in *SearchUsersReq, opts ...grpc.CallOption) (*SearchUsersResp, error) {
|
||||
client := pb.NewUsercenterClient(m.cli.Conn())
|
||||
return client.SearchUsers(ctx, in, opts...)
|
||||
|
||||
Reference in New Issue
Block a user