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.

42 lines
876 B

  1. package Database
  2. import (
  3. "git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
  4. "gorm.io/gorm"
  5. "gorm.io/gorm/clause"
  6. )
  7. // GetAttachmentByID gets the attachment record by the id
  8. func GetAttachmentByID(id string) (Models.MessageData, error) {
  9. var (
  10. messageData Models.MessageData
  11. err error
  12. )
  13. err = DB.Preload(clause.Associations).
  14. First(&messageData, "id = ?", id).
  15. Error
  16. return messageData, err
  17. }
  18. // CreateAttachment creates the attachment record
  19. func CreateAttachment(messageData *Models.MessageData) error {
  20. var (
  21. err error
  22. )
  23. err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
  24. Create(messageData).
  25. Error
  26. return err
  27. }
  28. // DeleteAttachment deletes the attachment record
  29. func DeleteAttachment(messageData *Models.MessageData) error {
  30. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  31. Delete(messageData).
  32. Error
  33. }