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.

50 lines
1.1 KiB

package Database
import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
// Attachment holds the attachment data
type Attachment struct {
Base
FilePath string `gorm:"not null" json:"-"`
Mimetype string `gorm:"not null" json:"mimetype"`
Extension string `gorm:"not null" json:"extension"`
Data string `gorm:"-" json:"data"`
ImageLink string `gorm:"-" json:"image_link"`
}
// GetAttachmentByID gets the attachment record by the id
func GetAttachmentByID(id string) (MessageData, error) {
var (
messageData MessageData
err error
)
err = DB.Preload(clause.Associations).
First(&messageData, "id = ?", id).
Error
return messageData, err
}
// CreateAttachment creates the attachment record
func (attachment *Attachment) CreateAttachment() error {
var (
err error
)
err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
Create(attachment).
Error
return err
}
// DeleteAttachment deletes the attachment record
func (attachment *Attachment) DeleteAttachment() error {
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
Delete(attachment).
Error
}