2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-12-04 15:14:04 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Photos can be added to multiple albums
|
|
|
|
type PhotoAlbum struct {
|
2019-12-27 05:18:52 +01:00
|
|
|
PhotoUUID string `gorm:"type:varbinary(36);primary_key;auto_increment:false"`
|
|
|
|
AlbumUUID string `gorm:"type:varbinary(36);primary_key;auto_increment:false;index"`
|
2019-12-04 15:14:04 +01:00
|
|
|
Order int
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
Photo *Photo
|
|
|
|
Album *Album
|
|
|
|
}
|
|
|
|
|
|
|
|
func (PhotoAlbum) TableName() string {
|
|
|
|
return "photos_albums"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPhotoAlbum(photoUUID, albumUUID string) *PhotoAlbum {
|
|
|
|
result := &PhotoAlbum{
|
|
|
|
PhotoUUID: photoUUID,
|
|
|
|
AlbumUUID: albumUUID,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *PhotoAlbum) FirstOrCreate(db *gorm.DB) *PhotoAlbum {
|
2019-12-19 09:37:10 +01:00
|
|
|
if err := db.FirstOrCreate(m, "photo_uuid = ? AND album_uuid = ?", m.PhotoUUID, m.AlbumUUID).Error; err != nil {
|
|
|
|
log.Errorf("photo album: %s", err)
|
|
|
|
}
|
2019-12-04 15:14:04 +01:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|