Merge pull request #2670 from kvalev/kvv-search-by-city

Search photos by city
This commit is contained in:
Theresa Gresch 2022-09-05 11:14:43 +02:00 committed by GitHub
commit fe5db3ed9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View File

@ -55,6 +55,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

View File

@ -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").

View File

@ -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"