Commit 4d09c023 authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

add email stuff in database

parent d978cb5f
......@@ -20,7 +20,8 @@ type Share struct {
DownloadLimit uint `json:"download_limit,omitempty"`
IsPublic bool `json:"is_public" gorm:"not null; default:false; index"`
Password string `json:"-"`
Emails string `json:"email,omitempty"`
Emails []string `json:"emails,omitempty" gorm:"-"`
EMailsDB string `json:"-"`
IsTemporary bool `json:"-" gorm:"not null"`
Attachments []Attachment `json:"files,omitempty" gorm:"constraint:OnDelete:CASCADE"`
......@@ -35,6 +36,14 @@ type Attachment struct {
ShareID uuid.UUID `json:"-" gorm:"not null"`
}
/////////////////////////////////
/////////// Hoooks //////////////
/////////////////////////////////
func (sh *Share) AfterFind(scope *gorm.DB) error {
sh.Emails = []string{sh.EMailsDB}
return nil
}
func (sh *Share) BeforeCreate(scope *gorm.DB) error {
if sh.ID.String() == "00000000-0000-0000-0000-000000000000" {
uid, err := uuid.NewRandom()
......@@ -49,6 +58,7 @@ func (sh *Share) BeforeCreate(scope *gorm.DB) error {
} else {
return os.MkdirAll(filepath.Join(config.mediaDir, "data", sh.ID.String()), os.ModePerm)
}
// TODO convert email adresses
}
func (sh *Share) BeforeDelete(scope *gorm.DB) error {
......@@ -73,6 +83,9 @@ func (att *Attachment) BeforeDelete(scope *gorm.DB) error {
return os.Remove(filepath.Join(config.mediaDir, "data", att.ShareID.String(), att.ID.String()))
}
/////////////////////////////////
/////////// Functions ///////////
/////////////////////////////////
func GetDatabase() (*gorm.DB, error) {
dsn := os.Getenv("DATABASE_URI")
split := strings.SplitN(dsn, ":", 2)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment