photoprism/internal/models/camera.go

41 lines
833 B
Go
Raw Normal View History

2018-09-16 19:09:40 +02:00
package models
import (
2018-09-13 20:54:34 +02:00
"github.com/gosimple/slug"
"github.com/jinzhu/gorm"
)
2018-11-06 19:02:03 +01:00
// Camera model and make (as extracted from EXIF metadata)
type Camera struct {
gorm.Model
2018-09-19 09:20:57 +02:00
CameraSlug string
CameraModel string
CameraMake string
2018-09-19 09:20:57 +02:00
CameraType string
CameraOwner string
CameraDescription string `gorm:"type:text;"`
CameraNotes string `gorm:"type:text;"`
}
func NewCamera(modelName string, makeName string) *Camera {
if modelName == "" {
modelName = "Unknown"
}
2018-09-13 20:54:34 +02:00
cameraSlug := slug.MakeLang(modelName, "en")
result := &Camera{
CameraModel: modelName,
CameraMake: makeName,
2018-09-17 18:40:57 +02:00
CameraSlug: cameraSlug,
}
return result
}
func (c *Camera) FirstOrCreate(db *gorm.DB) *Camera {
db.FirstOrCreate(c, "camera_model = ? AND camera_make = ?", c.CameraModel, c.CameraMake)
return c
}