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.

56 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 err error
  26. err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
  27. Create(userConversation).
  28. Error
  29. return err
  30. }
  31. func CreateUserConversations(userConversations *[]Models.UserConversation) error {
  32. var err error
  33. err = DB.Create(userConversations).
  34. Error
  35. return err
  36. }
  37. func DeleteUserConversation(userConversation *Models.UserConversation) error {
  38. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  39. Delete(userConversation).
  40. Error
  41. }