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.
 
 
 
 

85 lines
1.6 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. // GetForBanned 获取群组禁言用户信息
  32. func (*groupRepo) GetForBanned(groupId int64) (*model.Group, error) {
  33. group, err := GroupDao.Get(groupId)
  34. if err != nil {
  35. return nil, err
  36. }
  37. members, err := GroupUserRepo.ListBannedUser(groupId)
  38. if err != nil {
  39. return nil, err
  40. }
  41. group.Members = members
  42. return group, nil
  43. }
  44. // Save 获取群组信息
  45. func (*groupRepo) Save(group *model.Group) error {
  46. groupId := group.Id
  47. err := GroupDao.Save(group)
  48. if err != nil {
  49. return err
  50. }
  51. members := group.Members
  52. for i := range members {
  53. members[i].GroupId = group.Id
  54. if members[i].UpdateType == model.UpdateTypeUpdate {
  55. err = GroupUserRepo.Save(&(members[i]))
  56. if err != nil {
  57. return err
  58. }
  59. }
  60. if members[i].UpdateType == model.UpdateTypeDelete {
  61. err = GroupUserRepo.Delete(group.Id, members[i].UserId)
  62. if err != nil {
  63. return err
  64. }
  65. }
  66. }
  67. if groupId != 0 {
  68. err = GroupCache.Del(groupId)
  69. if err != nil {
  70. return err
  71. }
  72. }
  73. return nil
  74. }