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.

61 lines
1.1 KiB

  1. package Database
  2. import (
  3. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
  4. "gorm.io/gorm"
  5. )
  6. func GetUserConversationById(id string) (Models.UserConversation, error) {
  7. var (
  8. message Models.UserConversation
  9. err error
  10. )
  11. err = DB.First(&message, "id = ?", id).
  12. Error
  13. return message, err
  14. }
  15. func GetUserConversationsByUserId(id string) ([]Models.UserConversation, error) {
  16. var (
  17. conversations []Models.UserConversation
  18. err error
  19. )
  20. err = DB.Find(&conversations, "user_id = ?", id).
  21. Error
  22. return conversations, err
  23. }
  24. func CreateUserConversation(userConversation *Models.UserConversation) error {
  25. var (
  26. err error
  27. )
  28. err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
  29. Create(userConversation).
  30. Error
  31. return err
  32. }
  33. func CreateUserConversations(userConversations *[]Models.UserConversation) error {
  34. var (
  35. err error
  36. )
  37. err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
  38. Create(userConversations).
  39. Error
  40. return err
  41. }
  42. func DeleteUserConversation(userConversation *Models.UserConversation) error {
  43. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  44. Delete(userConversation).
  45. Error
  46. }