2018-09-24 19:07:43 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gosimple/slug"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
)
|
|
|
|
|
2019-12-09 08:04:41 +01:00
|
|
|
// Camera lens (as extracted from UpdateExif metadata)
|
2018-09-24 19:07:43 +02:00
|
|
|
type Lens struct {
|
2019-06-04 18:26:35 +02:00
|
|
|
Model
|
2018-09-24 19:07:43 +02:00
|
|
|
LensSlug string
|
|
|
|
LensModel string
|
|
|
|
LensMake string
|
|
|
|
LensType string
|
|
|
|
LensOwner string
|
|
|
|
LensDescription string `gorm:"type:text;"`
|
|
|
|
LensNotes string `gorm:"type:text;"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Lens) TableName() string {
|
|
|
|
return "lenses"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLens(modelName string, makeName string) *Lens {
|
|
|
|
if modelName == "" {
|
|
|
|
modelName = "Unknown"
|
|
|
|
}
|
|
|
|
|
|
|
|
lensSlug := slug.MakeLang(modelName, "en")
|
|
|
|
|
|
|
|
result := &Lens{
|
|
|
|
LensModel: modelName,
|
|
|
|
LensMake: makeName,
|
|
|
|
LensSlug: lensSlug,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-06-04 18:26:35 +02:00
|
|
|
func (m *Lens) FirstOrCreate(db *gorm.DB) *Lens {
|
|
|
|
db.FirstOrCreate(m, "lens_model = ? AND lens_make = ?", m.LensModel, m.LensMake)
|
2018-09-24 19:07:43 +02:00
|
|
|
|
2019-06-04 18:26:35 +02:00
|
|
|
return m
|
2018-09-24 19:07:43 +02:00
|
|
|
}
|