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.
 
 
 
 

38 lines
865 B

  1. package friend
  2. import (
  3. "gim/pkg/db"
  4. "gim/pkg/gerrors"
  5. "github.com/jinzhu/gorm"
  6. )
  7. type friendRepo struct{}
  8. var FriendRepo = new(friendRepo)
  9. // Get 获取好友
  10. func (*friendRepo) Get(userId, friendId int64) (*Friend, error) {
  11. friend := Friend{}
  12. err := db.DB.First(&friend, "user_id = ? and friend_id = ?", userId, friendId).Error
  13. if err != nil && err != gorm.ErrRecordNotFound {
  14. return nil, err
  15. }
  16. if err == gorm.ErrRecordNotFound {
  17. return nil, nil
  18. }
  19. return &friend, nil
  20. }
  21. // Save 添加好友
  22. func (*friendRepo) Save(friend *Friend) error {
  23. return gerrors.WrapError(db.DB.Save(&friend).Error)
  24. }
  25. // List 获取好友列表
  26. func (*friendRepo) List(userId int64, status int) ([]Friend, error) {
  27. var friends []Friend
  28. err := db.DB.Where("user_id = ? and status = ?", userId, status).Find(&friends).Error
  29. return friends, gerrors.WrapError(err)
  30. }