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.

55 lines
1.2 KiB

  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 GetConversationDetailById(id string) (Models.ConversationDetail, error) {
  8. var (
  9. messageThread Models.ConversationDetail
  10. err error
  11. )
  12. err = DB.Preload(clause.Associations).
  13. Where("id = ?", id).
  14. First(&messageThread).
  15. Error
  16. return messageThread, err
  17. }
  18. func GetConversationDetailsByIds(id []string) ([]Models.ConversationDetail, error) {
  19. var (
  20. messageThread []Models.ConversationDetail
  21. err error
  22. )
  23. err = DB.Preload(clause.Associations).
  24. Where("id IN ?", id).
  25. First(&messageThread).
  26. Error
  27. return messageThread, err
  28. }
  29. func CreateConversationDetail(messageThread *Models.ConversationDetail) error {
  30. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  31. Create(messageThread).
  32. Error
  33. }
  34. func UpdateConversationDetail(messageThread *Models.ConversationDetail) error {
  35. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  36. Where("id = ?", messageThread.ID).
  37. Updates(messageThread).
  38. Error
  39. }
  40. func DeleteConversationDetail(messageThread *Models.ConversationDetail) error {
  41. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  42. Delete(messageThread).
  43. Error
  44. }