2018-09-16 19:09:40 +02:00
|
|
|
package models
|
2018-07-18 15:17:56 +02:00
|
|
|
|
|
|
|
import (
|
2019-06-18 06:37:10 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/gosimple/slug"
|
2018-07-18 15:17:56 +02:00
|
|
|
"github.com/jinzhu/gorm"
|
2019-06-09 05:22:53 +02:00
|
|
|
uuid "github.com/satori/go.uuid"
|
2018-07-18 15:17:56 +02:00
|
|
|
)
|
|
|
|
|
2018-11-06 19:02:03 +01:00
|
|
|
// Photo album
|
2018-07-18 15:17:56 +02:00
|
|
|
type Album struct {
|
2019-06-04 18:26:35 +02:00
|
|
|
Model
|
|
|
|
AlbumUUID string `gorm:"unique_index;"`
|
2019-06-18 06:37:10 +02:00
|
|
|
AlbumSlug string `gorm:"index;"`
|
2018-09-19 11:16:18 +02:00
|
|
|
AlbumName string
|
2018-09-27 08:59:53 +02:00
|
|
|
AlbumDescription string `gorm:"type:text;"`
|
|
|
|
AlbumNotes string `gorm:"type:text;"`
|
2019-06-17 06:43:59 +02:00
|
|
|
AlbumViews uint
|
2018-09-19 11:16:18 +02:00
|
|
|
AlbumPhoto *Photo
|
|
|
|
AlbumPhotoID uint
|
2019-06-17 21:45:06 +02:00
|
|
|
AlbumFavorite bool
|
2018-09-19 11:16:18 +02:00
|
|
|
Photos []Photo `gorm:"many2many:album_photos;"`
|
2018-07-18 15:17:56 +02:00
|
|
|
}
|
2019-06-04 18:26:35 +02:00
|
|
|
|
|
|
|
func (m *Album) BeforeCreate(scope *gorm.Scope) error {
|
|
|
|
return scope.SetColumn("AlbumUUID", uuid.NewV4().String())
|
|
|
|
}
|
2019-06-18 06:37:10 +02:00
|
|
|
|
|
|
|
func NewAlbum(albumName string) *Album {
|
|
|
|
albumName = strings.TrimSpace(albumName)
|
|
|
|
|
|
|
|
if albumName == "" {
|
|
|
|
albumName = "New Album"
|
|
|
|
}
|
|
|
|
|
|
|
|
albumSlug := slug.Make(albumName)
|
|
|
|
albumUUID := uuid.NewV4().String()
|
|
|
|
|
|
|
|
result := &Album{
|
|
|
|
AlbumUUID: albumUUID,
|
|
|
|
AlbumSlug: albumSlug,
|
|
|
|
AlbumName: albumName,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|