From 27530bc0bedbf7009105f1f721182b43ac1a1a38 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Sun, 16 Jun 2019 21:04:29 -0700 Subject: [PATCH] Add shares table for sharing photos and albums --- internal/config/config.go | 1 + internal/models/share.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 internal/models/share.go diff --git a/internal/config/config.go b/internal/config/config.go index 66ac2790a..e715de70b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -412,6 +412,7 @@ func (c *Config) MigrateDb() { &models.Camera{}, &models.Lens{}, &models.Country{}, + &models.Share{}, ) } diff --git a/internal/models/share.go b/internal/models/share.go new file mode 100644 index 000000000..0ce519c18 --- /dev/null +++ b/internal/models/share.go @@ -0,0 +1,29 @@ +package models + +import ( + "time" + + "github.com/jinzhu/gorm" + + uuid "github.com/satori/go.uuid" +) + +// Shared photos and/or albums +type Share struct { + ShareUUID string `gorm:"primary_key;auto_increment:false"` + PhotoID uint + AlbumID uint + ShareSecret string + SharePassword string + ShareExpires time.Time + Photo *Photo + Album *Album +} + +func (Share) TableName() string { + return "shares" +} + +func (s *Share) BeforeCreate(scope *gorm.Scope) error { + return scope.SetColumn("ShareUUID", uuid.NewV4().String()) +}