Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

73 rindas
1.5 KiB

  1. package app
  2. import (
  3. "context"
  4. "egg-im/internal/business/comm/utils"
  5. "egg-im/internal/business/domain/user/repo"
  6. "egg-im/pkg/pb"
  7. "time"
  8. )
  9. type userApp struct{}
  10. var UserApp = new(userApp)
  11. func (*userApp) Get(ctx context.Context, userId int64) (*pb.User, error) {
  12. user, err := repo.UserRepo.Get(userId)
  13. return user.ToProto(), err
  14. }
  15. func (*userApp) Update(ctx context.Context, userId int64, req *pb.UpdateUserReq) error {
  16. utils.FilePutContents("update_info", utils.SerializeStr(map[string]interface{}{
  17. "user_id": userId,
  18. "nickname": req.Nickname,
  19. "args": req,
  20. "time": time.Now().Format("2006-01-02 15:04:05"),
  21. }))
  22. u, err := repo.UserRepo.Get(userId)
  23. if err != nil {
  24. return err
  25. }
  26. if u == nil {
  27. return nil
  28. }
  29. u.Nickname = req.Nickname
  30. u.Sex = req.Sex
  31. u.AvatarUrl = req.AvatarUrl
  32. u.Extra = req.Extra
  33. u.UpdateTime = time.Now()
  34. err = repo.UserRepo.Save(u)
  35. if err != nil {
  36. return err
  37. }
  38. return nil
  39. }
  40. func (*userApp) GetByIds(ctx context.Context, userIds []int64) (map[int64]*pb.User, error) {
  41. users, err := repo.UserRepo.GetByIds(userIds)
  42. if err != nil {
  43. return nil, err
  44. }
  45. pbUsers := make(map[int64]*pb.User, len(users))
  46. for i := range users {
  47. pbUsers[users[i].Id] = users[i].ToProto()
  48. }
  49. return pbUsers, nil
  50. }
  51. func (*userApp) Search(ctx context.Context, key string) ([]*pb.User, error) {
  52. users, err := repo.UserRepo.Search(key)
  53. if err != nil {
  54. return nil, err
  55. }
  56. pbUsers := make([]*pb.User, len(users))
  57. for i, v := range users {
  58. pbUsers[i] = v.ToProto()
  59. }
  60. return pbUsers, nil
  61. }