2021-09-03 16:14:09 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-09-30 13:44:23 +02:00
|
|
|
SubjPerson = "person" // SubjType for people.
|
2021-09-03 16:14:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// People represents a list of people.
|
|
|
|
type People []Person
|
|
|
|
|
|
|
|
// Person represents a subject with type person.
|
|
|
|
type Person struct {
|
2021-09-17 14:26:12 +02:00
|
|
|
SubjUID string `json:"UID"`
|
|
|
|
SubjName string `json:"Name"`
|
|
|
|
SubjAlias string `json:"Alias"`
|
|
|
|
SubjFavorite bool `json:"Favorite"`
|
2021-10-06 15:27:17 +02:00
|
|
|
SubjHidden bool `json:"Hidden"`
|
2021-09-03 16:14:09 +02:00
|
|
|
}
|
|
|
|
|
2022-04-04 14:21:43 +02:00
|
|
|
// AfterFind is a hook that updates the name cache after querying.
|
|
|
|
func (m *Person) AfterFind() (err error) {
|
|
|
|
SubjNames.Set(m.SubjUID, m.SubjName)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-03 16:14:09 +02:00
|
|
|
// NewPerson returns a new entity.
|
|
|
|
func NewPerson(subj Subject) *Person {
|
|
|
|
result := &Person{
|
2021-09-17 14:26:12 +02:00
|
|
|
SubjUID: subj.SubjUID,
|
|
|
|
SubjName: subj.SubjName,
|
|
|
|
SubjAlias: subj.SubjAlias,
|
|
|
|
SubjFavorite: subj.SubjFavorite,
|
2021-10-06 15:27:17 +02:00
|
|
|
SubjHidden: subj.SubjHidden,
|
2021-09-03 16:14:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON returns the JSON encoding.
|
|
|
|
func (m *Person) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
UID string
|
|
|
|
Name string
|
|
|
|
Keywords []string `json:",omitempty"`
|
|
|
|
Favorite bool `json:",omitempty"`
|
2021-10-06 15:27:17 +02:00
|
|
|
Hidden bool `json:",omitempty"`
|
2021-09-03 16:14:09 +02:00
|
|
|
}{
|
2021-09-17 14:26:12 +02:00
|
|
|
UID: m.SubjUID,
|
|
|
|
Name: m.SubjName,
|
|
|
|
Keywords: txt.NameKeywords(m.SubjName, m.SubjAlias),
|
|
|
|
Favorite: m.SubjFavorite,
|
2021-10-06 15:27:17 +02:00
|
|
|
Hidden: m.SubjHidden,
|
2021-09-03 16:14:09 +02:00
|
|
|
})
|
|
|
|
}
|