Photos: Search by city
This commit is contained in:
parent
26200a5c71
commit
3badce1bc8
3 changed files with 43 additions and 0 deletions
|
@ -53,6 +53,7 @@ type SearchPhotos struct {
|
|||
Category string `form:"category" notes:"Location Category Name"` // Moments
|
||||
Country string `form:"country" example:"country:\"de|us\"" notes:"Country Code, OR search with |"` // Moments
|
||||
State string `form:"state" example:"state:\"Baden-Württemberg\"" notes:"Name of State (Location), OR search with |"` // Moments
|
||||
City string `form:"city" example:"city:\"Berlin\"" notes:"Name of City (Location), OR search with |"` // Moments
|
||||
Year string `form:"year" example:"year:1990|2003" notes:"Year Number, OR search with |"` // Moments
|
||||
Month string `form:"month" example:"month:7|10" notes:"Month (1-12), OR search with |"` // Moments
|
||||
Day string `form:"day" example:"day:3|13" notes:"Day of Month (1-31), OR search with |"` // Moments
|
||||
|
|
|
@ -401,6 +401,11 @@ func searchPhotos(f form.SearchPhotos, resultCols string) (results PhotoResults,
|
|||
s = s.Where("places.place_state IN (?)", SplitOr(f.State))
|
||||
}
|
||||
|
||||
// Filter by location city?
|
||||
if txt.NotEmpty(f.City) {
|
||||
s = s.Where("places.place_city IN (?)", SplitOr(f.City))
|
||||
}
|
||||
|
||||
// Filter by location category?
|
||||
if txt.NotEmpty(f.Category) {
|
||||
s = s.Joins("JOIN cells ON photos.cell_id = cells.id").
|
||||
|
|
|
@ -479,6 +479,26 @@ func TestPhotos(t *testing.T) {
|
|||
|
||||
assert.LessOrEqual(t, 1, len(photos))
|
||||
|
||||
})
|
||||
t.Run("form.city", func(t *testing.T) {
|
||||
var f form.SearchPhotos
|
||||
f.Query = "city:Mandeni"
|
||||
f.Count = 10
|
||||
f.Offset = 0
|
||||
|
||||
// Parse query string and filter.
|
||||
if err := f.ParseQueryString(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
photos, _, err := Photos(f)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.LessOrEqual(t, 1, len(photos))
|
||||
|
||||
})
|
||||
t.Run("form.title", func(t *testing.T) {
|
||||
var f form.SearchPhotos
|
||||
|
@ -976,6 +996,23 @@ func TestPhotos(t *testing.T) {
|
|||
|
||||
assert.LessOrEqual(t, 1, len(photos))
|
||||
})
|
||||
t.Run("search for city", func(t *testing.T) {
|
||||
var f form.SearchPhotos
|
||||
f.City = "Mandeni"
|
||||
|
||||
// Parse query string and filter.
|
||||
if err := f.ParseQueryString(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
photos, _, err := Photos(f)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.LessOrEqual(t, 1, len(photos))
|
||||
})
|
||||
t.Run("search for category", func(t *testing.T) {
|
||||
var f form.SearchPhotos
|
||||
f.Category = "botanical garden"
|
||||
|
|
Loading…
Reference in a new issue