2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2018-09-16 19:09:40 +02:00
|
|
|
|
2019-12-20 20:23:16 +01:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/photoprism/photoprism/internal/maps"
|
|
|
|
"github.com/photoprism/photoprism/internal/util"
|
|
|
|
)
|
2019-12-16 20:22:46 +01:00
|
|
|
|
2018-11-06 19:02:03 +01:00
|
|
|
// Photo location
|
2018-09-16 19:09:40 +02:00
|
|
|
type Location struct {
|
2019-12-20 20:23:16 +01:00
|
|
|
maps.Location
|
2019-12-21 17:24:29 +01:00
|
|
|
LocNotes string `gorm:"type:text;"`
|
|
|
|
LocFavorite bool
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
2019-12-20 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewLocation(lat, lng float64) *Location {
|
|
|
|
result := &Location{}
|
|
|
|
|
2019-12-27 05:18:52 +01:00
|
|
|
result.ID = maps.ID(lat, lng)
|
2019-12-20 20:23:16 +01:00
|
|
|
result.LocLat = lat
|
|
|
|
result.LocLng = lng
|
|
|
|
|
|
|
|
return result
|
2018-09-17 18:40:57 +02:00
|
|
|
}
|
2019-12-16 20:22:46 +01:00
|
|
|
|
2019-12-20 23:05:44 +01:00
|
|
|
func (m *Location) Category() string {
|
|
|
|
return m.LocCategory
|
2019-12-20 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Location) Find(db *gorm.DB) error {
|
2019-12-21 17:24:29 +01:00
|
|
|
if err := db.First(m, "id LIKE ?", m.ID+"%").Error; err == nil {
|
2019-12-20 20:23:16 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.Query(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := db.Create(m).Error; err != nil {
|
|
|
|
log.Errorf("location: %s", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Location) Keywords() []string {
|
|
|
|
result := []string{
|
|
|
|
strings.ToLower(m.LocCity),
|
|
|
|
strings.ToLower(m.LocSuburb),
|
|
|
|
strings.ToLower(m.LocState),
|
|
|
|
strings.ToLower(m.CountryName()),
|
2019-12-20 23:05:44 +01:00
|
|
|
strings.ToLower(m.LocCategory),
|
2019-12-20 20:23:16 +01:00
|
|
|
}
|
|
|
|
|
2019-12-27 05:18:52 +01:00
|
|
|
result = append(result, util.Keywords(m.LocName)...)
|
|
|
|
result = append(result, util.Keywords(m.LocPlace)...)
|
2019-12-20 20:23:16 +01:00
|
|
|
result = append(result, util.Keywords(m.LocNotes)...)
|
|
|
|
|
|
|
|
return result
|
2019-12-16 20:22:46 +01:00
|
|
|
}
|