|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package app
-
- import (
- "context"
- "egg-im/internal/business/comm/utils"
- "egg-im/internal/business/domain/user/repo"
- "egg-im/pkg/pb"
- "time"
- )
-
- type userApp struct{}
-
- var UserApp = new(userApp)
-
- func (*userApp) Get(ctx context.Context, userId int64) (*pb.User, error) {
- user, err := repo.UserRepo.Get(userId)
- return user.ToProto(), err
- }
-
- func (*userApp) Update(ctx context.Context, userId int64, req *pb.UpdateUserReq) error {
- utils.FilePutContents("update_info", utils.SerializeStr(map[string]interface{}{
- "user_id": userId,
- "nickname": req.Nickname,
- "args": req,
- "time": time.Now().Format("2006-01-02 15:04:05"),
- }))
- u, err := repo.UserRepo.Get(userId)
- if err != nil {
- return err
- }
- if u == nil {
- return nil
- }
-
- u.Nickname = req.Nickname
- u.Sex = req.Sex
- u.AvatarUrl = req.AvatarUrl
- u.Extra = req.Extra
- u.UpdateTime = time.Now()
-
- err = repo.UserRepo.Save(u)
- if err != nil {
- return err
- }
- return nil
- }
-
- func (*userApp) GetByIds(ctx context.Context, userIds []int64) (map[int64]*pb.User, error) {
- users, err := repo.UserRepo.GetByIds(userIds)
- if err != nil {
- return nil, err
- }
-
- pbUsers := make(map[int64]*pb.User, len(users))
- for i := range users {
- pbUsers[users[i].Id] = users[i].ToProto()
- }
- return pbUsers, nil
- }
-
- func (*userApp) Search(ctx context.Context, key string) ([]*pb.User, error) {
- users, err := repo.UserRepo.Search(key)
- if err != nil {
- return nil, err
- }
-
- pbUsers := make([]*pb.User, len(users))
- for i, v := range users {
- pbUsers[i] = v.ToProto()
- }
- return pbUsers, nil
- }
|