From c1c723894ba9dd32d456f286e5cbe364b96f1f65 Mon Sep 17 00:00:00 2001 From: Lansong <62054128+Lansongxx@users.noreply.github.com> Date: Sat, 17 Feb 2024 11:50:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Duser=E9=80=9A=E8=BF=87?= =?UTF-8?q?userId=E6=89=B9=E9=87=8F=E6=9F=A5=E8=AF=A2=E7=9A=84bug=20(#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/adaptor/server.go | 4 ++++ biz/application/service/file.go | 12 ++++++------ biz/application/service/user.go | 28 +++++++++++++++++----------- go.mod | 2 +- go.sum | 27 ++------------------------- provider/wire_gen.go | 1 + 6 files changed, 31 insertions(+), 43 deletions(-) diff --git a/biz/adaptor/server.go b/biz/adaptor/server.go index 321d577..606f6fb 100644 --- a/biz/adaptor/server.go +++ b/biz/adaptor/server.go @@ -168,6 +168,10 @@ func (s *ContentServerImpl) GetUsers(ctx context.Context, req *content.GetUsersR return s.UserService.GetUsers(ctx, req) } +func (s *ContentServerImpl) GetUsersByUserIds(ctx context.Context, req *content.GetUsersByUserIdsReq) (res *content.GetUsersByUserIdsResp, err error) { + return s.UserService.GetUsersByUserIds(ctx, req) +} + func (s *ContentServerImpl) CreateUser(ctx context.Context, req *content.CreateUserReq) (resp *content.CreateUserResp, err error) { return s.UserService.CreateUser(ctx, req) } diff --git a/biz/application/service/file.go b/biz/application/service/file.go index 0ae11d0..71f93dc 100644 --- a/biz/application/service/file.go +++ b/biz/application/service/file.go @@ -48,7 +48,7 @@ type IFileService interface { } type FileService struct { - config config.Config + Config *config.Config FileMongoMapper filemapper.IMongoMapper FileEsMapper filemapper.IFileEsMapper ShareFileMongoMapper sharefilemapper.IMongoMapper @@ -390,7 +390,7 @@ func (s *FileService) DeleteFile(ctx context.Context, req *gencontent.DeleteFile consts.Labels: "", } } - ids := make([]string, 0, s.config.InitialSliceLength) + ids := make([]string, 0, s.Config.InitialSliceLength) tx := s.FileMongoMapper.StartClient() err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { if err = sessionContext.StartTransaction(); err != nil { @@ -429,7 +429,7 @@ func (s *FileService) RecoverRecycleBinFile(ctx context.Context, req *gencontent "$unset": bson.M{consts.DeletedAt: ""}, } - ids := make([]string, 0, s.config.InitialSliceLength) + ids := make([]string, 0, s.Config.InitialSliceLength) tx := s.FileMongoMapper.StartClient() err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { if err = sessionContext.StartTransaction(); err != nil { @@ -497,7 +497,7 @@ func (s *FileService) CreateShareCode(ctx context.Context, req *gencontent.Creat data := convertor.ShareFileToShareFileMapper(req.ShareFile) data.CreateAt = time.Now() if req.ShareFile.EffectiveTime >= 0 { - data.DeletedAt = data.CreateAt.Add(time.Duration(req.ShareFile.EffectiveTime)*time.Second + time.Duration(s.config.DeletionCoolingOffPeriod)*time.Hour) + data.DeletedAt = data.CreateAt.Add(time.Duration(req.ShareFile.EffectiveTime)*time.Second + time.Duration(s.Config.DeletionCoolingOffPeriod)*time.Hour) } if resp.Code, resp.Key, err = s.ShareFileMongoMapper.Insert(ctx, data); err != nil { return resp, err @@ -568,7 +568,7 @@ func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *genconten } if req.SpaceSize == int64(gencontent.Folder_Folder_Size) { // 若是文件夹,开始根据原文件夹层层创建 var front kv - queue := make([]kv, 0, s.config.InitialSliceLength) + queue := make([]kv, 0, s.Config.InitialSliceLength) queue = append(queue, kv{id: req.FileId, path: req.NewPath + "/" + resp.FileId}) for len(queue) > 0 { front = queue[0] @@ -646,7 +646,7 @@ func (s *FileService) AddFileToPublicSpace(ctx context.Context, req *gencontent. consts.Labels: req.Labels, }, } - ids := make([]string, 0, s.config.InitialSliceLength) + ids := make([]string, 0, s.Config.InitialSliceLength) tx := s.FileMongoMapper.StartClient() err = tx.UseSession(ctx, func(sessionContext mongo.SessionContext) error { if err = sessionContext.StartTransaction(); err != nil { diff --git a/biz/application/service/user.go b/biz/application/service/user.go index eed59b3..30e9b1a 100644 --- a/biz/application/service/user.go +++ b/biz/application/service/user.go @@ -7,7 +7,6 @@ import ( "github.com/CloudStriver/cloudmind-content/biz/infrastructure/convertor" usermapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/user" "github.com/CloudStriver/go-pkg/utils/pagination/esp" - "github.com/CloudStriver/go-pkg/utils/pagination/mongop" "github.com/CloudStriver/go-pkg/utils/pconvertor" gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content" "github.com/google/wire" @@ -22,6 +21,7 @@ type IUserService interface { UpdateUser(ctx context.Context, req *gencontent.UpdateUserReq) (resp *gencontent.UpdateUserResp, err error) GetUsers(ctx context.Context, req *gencontent.GetUsersReq) (resp *gencontent.GetUsersResp, err error) DeleteUser(ctx context.Context, req *gencontent.DeleteUserReq) (resp *gencontent.DeleteUserResp, err error) + GetUsersByUserIds(ctx context.Context, req *gencontent.GetUsersByUserIdsReq) (resp *gencontent.GetUsersByUserIdsResp, err error) } type UserService struct { @@ -36,6 +36,17 @@ var UserSet = wire.NewSet( wire.Bind(new(IUserService), new(*UserService)), ) +func (s *UserService) GetUsersByUserIds(ctx context.Context, req *gencontent.GetUsersByUserIdsReq) (resp *gencontent.GetUsersByUserIdsResp, err error) { + resp = new(gencontent.GetUsersByUserIdsResp) + users, err := s.UserMongoMapper.FindManyByIds(ctx, req.UserIds) + if err != nil { + return resp, err + } + resp.Users = lo.Map[*usermapper.User, *gencontent.User](users, func(item *usermapper.User, _ int) *gencontent.User { + return convertor.UserMapperToUser(item) + }) + return resp, nil +} func (s *UserService) DeleteUser(ctx context.Context, req *gencontent.DeleteUserReq) (resp *gencontent.DeleteUserResp, err error) { if _, err = s.UserMongoMapper.Delete(ctx, req.UserId); err != nil { return resp, err @@ -50,16 +61,11 @@ func (s *UserService) GetUsers(ctx context.Context, req *gencontent.GetUsersReq) ) p := pconvertor.PaginationOptionsToModelPaginationOptions(req.PaginationOptions) - if req.SearchOptions != nil { - switch o := req.SearchOptions.Type.(type) { - case *gencontent.SearchOptions_AllFieldsKey: - users, _, err = s.UserEsMapper.Search(ctx, convertor.ConvertUserAllFieldsSearchQuery(o), p, esp.ScoreCursorType) - case *gencontent.SearchOptions_MultiFieldsKey: - users, _, err = s.UserEsMapper.Search(ctx, convertor.ConvertUserMultiFieldsSearchQuery(o), p, esp.ScoreCursorType) - } - } else { - users, err = s.UserMongoMapper.FindMany(ctx, convertor.UserFilterToUserFilterMapper(req.UserFilterOptions), - p, mongop.IdCursorType) + switch o := req.SearchOptions.Type.(type) { + case *gencontent.SearchOptions_AllFieldsKey: + users, _, err = s.UserEsMapper.Search(ctx, convertor.ConvertUserAllFieldsSearchQuery(o), p, esp.ScoreCursorType) + case *gencontent.SearchOptions_MultiFieldsKey: + users, _, err = s.UserEsMapper.Search(ctx, convertor.ConvertUserMultiFieldsSearchQuery(o), p, esp.ScoreCursorType) } if err != nil { return resp, err diff --git a/go.mod b/go.mod index 0d15966..e0acab2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/CloudStriver/go-pkg v0.0.0-20231229114943-910edcb8788d - github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217031415-a5bd5496cc27 + github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217034102-8561f3df92ca github.com/bytedance/sonic v1.10.2 github.com/cloudwego/kitex v0.8.0 github.com/elastic/go-elasticsearch/v8 v8.11.1 diff --git a/go.sum b/go.sum index 93e02e5..b962e23 100644 --- a/go.sum +++ b/go.sum @@ -6,31 +6,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CloudStriver/go-pkg v0.0.0-20231229114943-910edcb8788d h1:c5M3637HJJN+pD3erToZAw0vutEMLmC+5I63szm5PYU= github.com/CloudStriver/go-pkg v0.0.0-20231229114943-910edcb8788d/go.mod h1:Oj6+J8ixQxqNunSpl9v64q6tAQ83wY/rRFI+3rhHVCk= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211013020-a79ff79a2608 h1:2bHkcHJ/rU8SrwRhujqyO6f9e65RJVTQAM2zH0ueo1A= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211013020-a79ff79a2608/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211052850-770a3944778c h1:eGqGFWc4cW8CEPUYbvVbaYecBcqr77bfx9d/NIseT7Y= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211052850-770a3944778c/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211084619-f9a18d01eddc h1:mSGwznYqr3MR9ofjeMEnB9e3K9CyRFcWUdsA11NWIME= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211084619-f9a18d01eddc/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211095735-6297dd4f7912 h1:3wvm8bGkpcoU13ybVeyGkd1qM3U0FEciFAjtvDWXP90= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211095735-6297dd4f7912/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211102054-e091e312444a h1:tzTIsj2uK3va1lLLwTC1fQ0r0lL4KmmC80JnNTk72kc= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240211102054-e091e312444a/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240212104255-b4e84c911157 h1:FsKE7z7855NMnOlSzfEibKP2v3iHdpjPObIGjzc4jiY= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240212104255-b4e84c911157/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240212113028-3917c4369591/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240213120542-0056e2f6440a h1:AdmKfNmLRoCjV2qYsgDWB2xgIurFDx1gCQEoipUjAp8= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240213120542-0056e2f6440a/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240213134755-c3d60bb8a84f h1:0MQXrJ3mPFqa0DOJKjMmudo6fbdO/NgUJtuCeEy4isI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240213134755-c3d60bb8a84f/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240214113023-7f499612a42e h1:N5hfOrkerrx5woyxW4i/zFHdIHjBGAhu5aSAbceGl7Y= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240214113023-7f499612a42e/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240216034153-d1b5d05e4bc4 h1:6Pfhx18HP+QNavq2VRJa/GpytHoCrZDjar4Qz31J1wY= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240216034153-d1b5d05e4bc4/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217020757-af1570b246dc h1:dNH83A+pRHSQNV7xfROtcFSuNJqxylhpPAmHw9abuTA= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217020757-af1570b246dc/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217031415-a5bd5496cc27 h1:l87gE+ctothfoCCtiS9DKNtcMTPUAUhIDsxwa/WS6BI= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217031415-a5bd5496cc27/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217034102-8561f3df92ca h1:ybV/UvI8myzQYALWYrvtpvH4AAUoLxLNscOm5KLh7YA= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240217034102-8561f3df92ca/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= diff --git a/provider/wire_gen.go b/provider/wire_gen.go index c793ec8..4d4aabe 100644 --- a/provider/wire_gen.go +++ b/provider/wire_gen.go @@ -33,6 +33,7 @@ func NewContentServerImpl() (*adaptor.ContentServerImpl, error) { iFileEsMapper := file.NewEsMapper(configConfig) sharefileIMongoMapper := sharefile.NewMongoMapper(configConfig) fileService := &service.FileService{ + Config: configConfig, FileMongoMapper: iMongoMapper, FileEsMapper: iFileEsMapper, ShareFileMongoMapper: sharefileIMongoMapper,