photoprism/internal/entity/album.go

66 lines
1.4 KiB
Go
Raw Normal View History

package entity
2018-07-18 15:17:56 +02:00
import (
"strings"
"time"
"github.com/gosimple/slug"
2018-07-18 15:17:56 +02:00
"github.com/jinzhu/gorm"
)
2018-11-06 19:02:03 +01:00
// Photo album
2018-07-18 15:17:56 +02:00
type Album struct {
ID uint `gorm:"primary_key"`
CoverUUID string `gorm:"type:varbinary(36);"`
AlbumUUID string `gorm:"type:varbinary(36);unique_index;"`
AlbumSlug string `gorm:"index;"`
AlbumName string `gorm:"type:varchar(128);"`
AlbumDescription string `gorm:"type:text;"`
AlbumNotes string `gorm:"type:text;"`
AlbumViews uint
2019-06-17 21:45:06 +02:00
AlbumFavorite bool
AlbumPublic bool
AlbumLat float64
AlbumLng float64
AlbumRadius float64
AlbumOrder string `gorm:"type:varchar(16);"`
AlbumTemplate string `gorm:"type:varchar(128);"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time `sql:"index"`
2018-07-18 15:17:56 +02:00
}
func (m *Album) BeforeCreate(scope *gorm.Scope) error {
if err := scope.SetColumn("AlbumUUID", ID('a')); err != nil {
return err
}
return nil
}
func NewAlbum(albumName string) *Album {
albumName = strings.TrimSpace(albumName)
if albumName == "" {
albumName = time.Now().Format("January 2006")
}
albumSlug := slug.Make(albumName)
result := &Album{
AlbumSlug: albumSlug,
AlbumName: albumName,
}
return result
}
func (m *Album) Rename(albumName string) {
if albumName == "" {
albumName = m.CreatedAt.Format("January 2006")
}
m.AlbumName = strings.TrimSpace(albumName)
m.AlbumSlug = slug.Make(m.AlbumName)
}