57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
|
package entity
|
||
|
|
||
|
import (
|
||
|
"github.com/jinzhu/gorm"
|
||
|
"github.com/photoprism/photoprism/internal/mutex"
|
||
|
)
|
||
|
|
||
|
// Description stores additional metadata fields for each photo to improve search performance.
|
||
|
type Description struct {
|
||
|
PhotoID uint `gorm:"primary_key;auto_increment:false"`
|
||
|
PhotoDescription string `gorm:"type:text;" json:"PhotoDescription"`
|
||
|
PhotoKeywords string `gorm:"type:text;" json:"PhotoKeywords"`
|
||
|
PhotoNotes string `gorm:"type:text;" json:"PhotoNotes"`
|
||
|
PhotoSubject string `json:"PhotoSubject"`
|
||
|
PhotoArtist string `json:"PhotoArtist"`
|
||
|
PhotoCopyright string `json:"PhotoCopyright"`
|
||
|
PhotoLicense string `json:"PhotoLicense"`
|
||
|
}
|
||
|
|
||
|
// FirstOrCreate returns the matching entity or creates a new one.
|
||
|
func (m *Description) FirstOrCreate(db *gorm.DB) error {
|
||
|
mutex.Db.Lock()
|
||
|
defer mutex.Db.Unlock()
|
||
|
|
||
|
return db.FirstOrCreate(m, "photo_id = ?", m.PhotoID).Error
|
||
|
}
|
||
|
|
||
|
// NoDescription checks if the photo has no Description
|
||
|
func (m *Description) NoDescription() bool {
|
||
|
return m.PhotoDescription == ""
|
||
|
}
|
||
|
|
||
|
// NoKeywords checks if the photo has no Keywords
|
||
|
func (m *Description) NoKeywords() bool {
|
||
|
return m.PhotoKeywords == ""
|
||
|
}
|
||
|
|
||
|
// NoSubject checks if the photo has no Subject
|
||
|
func (m *Description) NoSubject() bool {
|
||
|
return m.PhotoSubject == ""
|
||
|
}
|
||
|
|
||
|
// NoNotes checks if the photo has no Notes
|
||
|
func (m *Description) NoNotes() bool {
|
||
|
return m.PhotoNotes == ""
|
||
|
}
|
||
|
|
||
|
// NoArtist checks if the photo has no Artist
|
||
|
func (m *Description) NoArtist() bool {
|
||
|
return m.PhotoArtist == ""
|
||
|
}
|
||
|
|
||
|
// NoCopyright checks if the photo has no Copyright
|
||
|
func (m *Description) NoCopyright() bool {
|
||
|
return m.PhotoCopyright == ""
|
||
|
}
|