Merge pull request #2670 from kvalev/kvv-search-by-city
Search photos by city
This commit is contained in:
commit
fe5db3ed9d
|
@ -55,6 +55,7 @@ type SearchPhotos struct {
|
||||||
Category string `form:"category" notes:"Location Category Name"` // Moments
|
Category string `form:"category" notes:"Location Category Name"` // Moments
|
||||||
Country string `form:"country" example:"country:\"de|us\"" notes:"Country Code, OR search with |"` // 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
|
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
|
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
|
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
|
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))
|
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?
|
// Filter by location category?
|
||||||
if txt.NotEmpty(f.Category) {
|
if txt.NotEmpty(f.Category) {
|
||||||
s = s.Joins("JOIN cells ON photos.cell_id = cells.id").
|
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))
|
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) {
|
t.Run("form.title", func(t *testing.T) {
|
||||||
var f form.SearchPhotos
|
var f form.SearchPhotos
|
||||||
|
@ -976,6 +996,23 @@ func TestPhotos(t *testing.T) {
|
||||||
|
|
||||||
assert.LessOrEqual(t, 1, len(photos))
|
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) {
|
t.Run("search for category", func(t *testing.T) {
|
||||||
var f form.SearchPhotos
|
var f form.SearchPhotos
|
||||||
f.Category = "botanical garden"
|
f.Category = "botanical garden"
|
||||||
|
|
Loading…
Reference in a new issue