golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

71 lines
1.2 KiB

  1. package repo
  2. import (
  3. "gim/internal/logic/domain/group/model"
  4. )
  5. type groupRepo struct{}
  6. var GroupRepo = new(groupRepo)
  7. // Get 获取群组信息
  8. func (*groupRepo) Get(groupId int64) (*model.Group, error) {
  9. group, err := GroupCache.Get(groupId)
  10. if err != nil {
  11. return nil, err
  12. }
  13. if group != nil {
  14. return group, nil
  15. }
  16. group, err = GroupDao.Get(groupId)
  17. if err != nil {
  18. return nil, err
  19. }
  20. members, err := GroupUserRepo.ListUser(groupId)
  21. if err != nil {
  22. return nil, err
  23. }
  24. group.Members = members
  25. err = GroupCache.Set(group)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return group, nil
  30. }
  31. // Save 获取群组信息
  32. func (*groupRepo) Save(group *model.Group) error {
  33. groupId := group.Id
  34. err := GroupDao.Save(group)
  35. if err != nil {
  36. return err
  37. }
  38. members := group.Members
  39. for i := range members {
  40. members[i].GroupId = group.Id
  41. if members[i].UpdateType == model.UpdateTypeUpdate {
  42. err = GroupUserRepo.Save(&(members[i]))
  43. if err != nil {
  44. return err
  45. }
  46. }
  47. if members[i].UpdateType == model.UpdateTypeDelete {
  48. err = GroupUserRepo.Delete(group.Id, members[i].UserId)
  49. if err != nil {
  50. return err
  51. }
  52. }
  53. }
  54. if groupId != 0 {
  55. err = GroupCache.Del(groupId)
  56. if err != nil {
  57. return err
  58. }
  59. }
  60. return nil
  61. }