photoprism/internal/entity/country.go

49 lines
965 B
Go
Raw Normal View History

package entity
2018-09-19 07:20:57 +00:00
import (
"github.com/gosimple/slug"
2018-09-19 07:20:57 +00:00
"github.com/jinzhu/gorm"
)
type Country struct {
ID string `gorm:"primary_key"`
CountrySlug string
2018-09-19 07:20:57 +00:00
CountryName string
CountryDescription string `gorm:"type:text;"`
CountryNotes string `gorm:"type:text;"`
CountryPhoto *Photo
CountryPhotoID uint
New bool `gorm:"-"`
2018-09-19 07:20:57 +00:00
}
2018-11-06 18:02:03 +00:00
// Create a new country
func NewCountry(countryCode string, countryName string) *Country {
if countryCode == "" {
countryCode = "zz"
}
if countryName == "" {
countryName = "Unknown"
}
countrySlug := slug.MakeLang(countryName, "en")
result := &Country{
ID: countryCode,
CountryName: countryName,
CountrySlug: countrySlug,
}
return result
}
func (m *Country) FirstOrCreate(db *gorm.DB) *Country {
db.FirstOrCreate(m, "id = ?", m.ID)
return m
}
func (m *Country) AfterCreate(scope *gorm.Scope) error {
return scope.SetColumn("New", true)
}