Skip to content

Commit

Permalink
fix: 修改user参数 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx authored Feb 7, 2024
1 parent 45b5f24 commit 24f8f6b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 47 deletions.
39 changes: 27 additions & 12 deletions biz/application/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
usermapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/user"
"github.com/CloudStriver/go-pkg/utils/pagination/esp"
"github.com/CloudStriver/go-pkg/utils/pconvertor"
"github.com/CloudStriver/go-pkg/utils/util/log"
gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content"
"github.com/google/wire"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/stores/redis"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type IUserService interface {
Expand All @@ -35,7 +35,6 @@ var UserSet = wire.NewSet(
)

func (s *UserService) DeleteUser(ctx context.Context, req *gencontent.DeleteUserReq) (resp *gencontent.DeleteUserResp, err error) {
resp = new(gencontent.DeleteUserResp)
if _, err = s.UserMongoMapper.Delete(ctx, req.UserId); err != nil {
return resp, err
}
Expand Down Expand Up @@ -63,29 +62,45 @@ func (s *UserService) SearchUser(ctx context.Context, req *gencontent.SearchUser
}

func (s *UserService) GetUser(ctx context.Context, req *gencontent.GetUserReq) (resp *gencontent.GetUserResp, err error) {
resp = new(gencontent.GetUserResp)
var user *usermapper.User
if user, err = s.UserMongoMapper.FindOne(ctx, req.UserId); err != nil {
return resp, err
}

resp.User = convertor.UserMapperToUser(user)
return resp, nil
return &gencontent.GetUserResp{
Name: user.Name,
Sex: user.Sex,
FullName: user.FullName,
IdCard: user.IdCard,
CreateTime: user.CreateAt.UnixMilli(),
UpdateTime: user.UpdateAt.UnixMilli(),
Description: user.Description,
Url: user.Url,
}, nil
}

func (s *UserService) CreateUser(ctx context.Context, req *gencontent.CreateUserReq) (resp *gencontent.CreateUserResp, err error) {
resp = new(gencontent.CreateUserResp)
if _, err = s.UserMongoMapper.Insert(ctx, convertor.UserToUserMapper(req.User)); err != nil {
log.CtxError(ctx, "插入用户信息异常[%v]\n", err)
oid, _ := primitive.ObjectIDFromHex(req.UserId)
if _, err = s.UserMongoMapper.Insert(ctx, &usermapper.User{
ID: oid,
Name: req.Name,
Sex: req.Sex,
}); err != nil {
return resp, err
}
return resp, nil
}

func (s *UserService) UpdateUser(ctx context.Context, req *gencontent.UpdateUserReq) (resp *gencontent.UpdateUserResp, err error) {
resp = new(gencontent.UpdateUserResp)
if _, err = s.UserMongoMapper.Update(ctx, convertor.UserToUserMapper(req.User)); err != nil {
log.CtxError(ctx, "修改用户信息异常[%v]\n", err)
oid, _ := primitive.ObjectIDFromHex(req.UserId)
if _, err = s.UserMongoMapper.Update(ctx, &usermapper.User{
ID: oid,
Name: req.Name,
Sex: req.Sex,
FullName: req.FullName,
IdCard: req.IdCard,
Description: req.Description,
Url: req.Url,
}); err != nil {
return resp, err
}
return resp, nil
Expand Down
26 changes: 0 additions & 26 deletions biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ func UserMapperToUser(in *usermapper.User) *gencontent.User {
}
}

func UserToUserMapper(in *gencontent.User) *usermapper.User {
oid, _ := primitive.ObjectIDFromHex(in.UserId)
return &usermapper.User{
ID: oid,
Name: in.Name,
Sex: in.Sex,
FullName: in.FullName,
IdCard: in.IdCard,
Description: in.Description,
Url: in.Url,
}
}

func FileMapperToFile(data *file.File) *gencontent.FileInfo {
return &gencontent.FileInfo{
FileId: data.ID.Hex(),
Expand Down Expand Up @@ -213,19 +200,6 @@ func PostFilterOptionsToFilterOptions(in *gencontent.PostFilterOptions) *postmap
}
}

func PostToPostMapper(in *gencontent.Post) *postmapper.Post {
oid, _ := primitive.ObjectIDFromHex(in.PostId)
return &postmapper.Post{
ID: oid,
Title: in.Title,
Text: in.Text,
Url: in.Url,
Tags: in.Tags,
UserId: in.UserId,
Status: in.Status,
}
}

func PostMapperToPost(in *postmapper.Post) *gencontent.Post {
if in == nil {
return &gencontent.Post{}
Expand Down
4 changes: 3 additions & 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-20240206150308-c7a07fdf6d24
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240207021724-cb53dcdaf182
github.com/bytedance/sonic v1.10.2
github.com/cloudwego/kitex v0.8.0
github.com/elastic/go-elasticsearch/v8 v8.11.1
Expand All @@ -19,6 +19,8 @@ require (
google.golang.org/grpc v1.60.1
)

//replace github.com/CloudStriver/service-idl-gen-go => ../service-idl-gen-go

require (
github.com/apache/thrift v0.16.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +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-20240202114307-d5edc26b91e1 h1:9ZenrqB/o8sJn0QWpdBPMvCBbhfZ1e1fb4QqeNrgVdE=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240202114307-d5edc26b91e1/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240206035429-8096c700ad87 h1:OGZxm1tDqseEZkbS+9gDu9R+T5KSuezqNV67ONxsgwg=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240206035429-8096c700ad87/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240206130055-0d56397126c5 h1:0dYU5eoQG10ijYOJEUrXmaETPhguipbELFK13PcYIQA=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240206130055-0d56397126c5/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240206150308-c7a07fdf6d24 h1:FOehlH0eYMaWp4GcvcgUeJIKYp8MrYYjN0t1kxnKmAQ=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240206150308-c7a07fdf6d24/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240207021724-cb53dcdaf182 h1:5ASoJ6SmuXz4SDQqxhXYgdoiHi1Up3Ce2+K6LVoFEDs=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240207021724-cb53dcdaf182/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

0 comments on commit 24f8f6b

Please sign in to comment.