Encrypted messaging app
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.

47 lines
855 B

  1. package Database
  2. import (
  3. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
  4. "gorm.io/gorm"
  5. "gorm.io/gorm/clause"
  6. )
  7. func GetFriendById(id string) (Models.Friend, error) {
  8. var (
  9. friend Models.Friend
  10. err error
  11. )
  12. err = DB.Preload(clause.Associations).
  13. First(&friend, "id = ?", id).
  14. Error
  15. return friend, err
  16. }
  17. func GetFriendsByUserId(userID string) ([]Models.Friend, error) {
  18. var (
  19. friends []Models.Friend
  20. err error
  21. )
  22. err = DB.Model(Models.Friend{}).
  23. Where("user_id = ?", userID).
  24. Find(&friends).
  25. Error
  26. return friends, err
  27. }
  28. func CreateFriendRequest(friend *Models.Friend) error {
  29. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  30. Create(friend).
  31. Error
  32. }
  33. func DeleteFriend(friend *Models.Friend) error {
  34. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  35. Delete(friend).
  36. Error
  37. }