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