Skip to content

Commit

Permalink
fix: 修复user通过userId批量查询的bug (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx authored Feb 17, 2024
1 parent 061a3d6 commit c1c7238
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 43 deletions.
4 changes: 4 additions & 0 deletions biz/adaptor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions biz/application/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 17 additions & 11 deletions biz/application/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 2 additions & 25 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions provider/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1c7238

Please sign in to comment.