2020-01-15 04:04:33 +01:00
|
|
|
package form
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2021-09-19 13:35:44 +02:00
|
|
|
// PhotoSearchGeo represents search form fields for "/api/v1/geo".
|
|
|
|
type PhotoSearchGeo struct {
|
2020-04-24 10:07:13 +02:00
|
|
|
Query string `form:"q"`
|
2020-05-23 20:58:58 +02:00
|
|
|
Type string `form:"type"`
|
|
|
|
Path string `form:"path"`
|
|
|
|
Folder string `form:"folder"` // Alias for Path
|
|
|
|
Name string `form:"name"`
|
2021-09-29 22:57:26 +02:00
|
|
|
Title string `form:"title"`
|
2020-04-24 10:07:13 +02:00
|
|
|
Before time.Time `form:"before" time_format:"2006-01-02"`
|
|
|
|
After time.Time `form:"after" time_format:"2006-01-02"`
|
|
|
|
Favorite bool `form:"favorite"`
|
2020-05-23 20:58:58 +02:00
|
|
|
Video bool `form:"video"`
|
|
|
|
Photo bool `form:"photo"`
|
2020-06-04 14:56:27 +02:00
|
|
|
Archived bool `form:"archived"`
|
|
|
|
Public bool `form:"public"`
|
|
|
|
Private bool `form:"private"`
|
|
|
|
Review bool `form:"review"`
|
|
|
|
Quality int `form:"quality"`
|
2021-05-26 10:46:32 +02:00
|
|
|
Faces string `form:"faces"` // Find or exclude faces if detected.
|
2020-04-26 11:41:54 +02:00
|
|
|
Lat float32 `form:"lat"`
|
|
|
|
Lng float32 `form:"lng"`
|
2020-04-24 10:07:13 +02:00
|
|
|
S2 string `form:"s2"`
|
|
|
|
Olc string `form:"olc"`
|
|
|
|
Dist uint `form:"dist"`
|
2021-09-18 15:32:39 +02:00
|
|
|
Face string `form:"face"` // UIDs
|
2021-08-29 16:16:49 +02:00
|
|
|
Subject string `form:"subject"` // UIDs
|
2021-09-20 12:36:59 +02:00
|
|
|
Person string `form:"person"` // Alias for Subject
|
2021-08-29 16:16:49 +02:00
|
|
|
Subjects string `form:"subjects"` // Text
|
|
|
|
People string `form:"people"` // Alias for Subjects
|
|
|
|
Keywords string `form:"keywords"`
|
2020-05-23 20:58:58 +02:00
|
|
|
Album string `form:"album"`
|
2021-08-29 16:16:49 +02:00
|
|
|
Albums string `form:"albums"`
|
2020-05-23 20:58:58 +02:00
|
|
|
Country string `form:"country"`
|
2021-09-20 23:32:35 +02:00
|
|
|
Year string `form:"year"` // Moments
|
|
|
|
Month string `form:"month"` // Moments
|
|
|
|
Day string `form:"day"` // Moments
|
2020-05-23 20:58:58 +02:00
|
|
|
Color string `form:"color"`
|
|
|
|
Camera int `form:"camera"`
|
|
|
|
Lens int `form:"lens"`
|
2020-01-15 04:04:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetQuery returns the query parameter as string.
|
2021-09-19 13:35:44 +02:00
|
|
|
func (f *PhotoSearchGeo) GetQuery() string {
|
2020-01-15 04:04:33 +01:00
|
|
|
return f.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetQuery sets the query parameter.
|
2021-09-19 13:35:44 +02:00
|
|
|
func (f *PhotoSearchGeo) SetQuery(q string) {
|
2020-01-15 04:04:33 +01:00
|
|
|
f.Query = q
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseQueryString parses the query parameter if possible.
|
2021-09-19 13:35:44 +02:00
|
|
|
func (f *PhotoSearchGeo) ParseQueryString() error {
|
2020-05-23 20:58:58 +02:00
|
|
|
err := ParseQueryString(f)
|
|
|
|
|
|
|
|
if f.Path == "" && f.Folder != "" {
|
|
|
|
f.Path = f.Folder
|
2021-09-20 12:36:59 +02:00
|
|
|
f.Folder = ""
|
2020-05-23 20:58:58 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 12:36:59 +02:00
|
|
|
if f.Subject == "" && f.Person != "" {
|
|
|
|
f.Subject = f.Person
|
|
|
|
f.Person = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Subjects == "" && f.People != "" {
|
2021-08-29 16:16:49 +02:00
|
|
|
f.Subjects = f.People
|
2021-09-20 12:36:59 +02:00
|
|
|
f.People = ""
|
2021-08-29 16:16:49 +02:00
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize returns a string containing non-empty fields and values of a struct.
|
2021-09-19 13:35:44 +02:00
|
|
|
func (f *PhotoSearchGeo) Serialize() string {
|
2020-05-23 20:58:58 +02:00
|
|
|
return Serialize(f, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SerializeAll returns a string containing all non-empty fields and values of a struct.
|
2021-09-19 13:35:44 +02:00
|
|
|
func (f *PhotoSearchGeo) SerializeAll() string {
|
2020-05-23 20:58:58 +02:00
|
|
|
return Serialize(f, true)
|
2020-01-15 04:04:33 +01:00
|
|
|
}
|
2020-01-28 22:16:59 +01:00
|
|
|
|
2021-09-19 13:35:44 +02:00
|
|
|
func NewGeoSearch(query string) PhotoSearchGeo {
|
|
|
|
return PhotoSearchGeo{Query: query}
|
2020-01-28 22:16:59 +01:00
|
|
|
}
|