Backend: Add folder as alias for path in search form

Due to popular request, see https://twitter.com/browseyourlife/status/1263442036570697731

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-05-21 16:46:22 +02:00
parent 872865f8fd
commit 0eb30715b3
2 changed files with 42 additions and 9 deletions

View file

@ -10,6 +10,7 @@ type PhotoSearch struct {
ID string `form:"id"`
Type string `form:"type"`
Path string `form:"path"`
Folder string `form:"folder"` // Alias for Path
Name string `form:"name"`
Title string `form:"title"`
Hash string `form:"hash"`
@ -59,7 +60,13 @@ func (f *PhotoSearch) SetQuery(q string) {
}
func (f *PhotoSearch) ParseQueryString() error {
return ParseQueryString(f)
err := ParseQueryString(f)
if f.Path == "" && f.Folder != "" {
f.Path = f.Folder
}
return err
}
func NewPhotoSearch(query string) PhotoSearch {

View file

@ -16,7 +16,33 @@ func TestPhotoSearchForm(t *testing.T) {
}
func TestParseQueryString(t *testing.T) {
t.Run("path", func(t *testing.T) {
form := &PhotoSearch{Query: "path:123abc/,EFG"}
err := form.ParseQueryString()
log.Debugf("%+v\n", form)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "123abc/,EFG", form.Path)
})
t.Run("folder", func(t *testing.T) {
form := &PhotoSearch{Query: "folder:123abc/,EFG"}
err := form.ParseQueryString()
log.Debugf("%+v\n", form)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "123abc/,EFG", form.Path)
})
t.Run("valid query", func(t *testing.T) {
form := &PhotoSearch{Query: "label:cat query:\"fooBar baz\" before:2019-01-15 camera:23 favorite:false dist:25000 lat:33.45343166666667"}
@ -25,7 +51,7 @@ func TestParseQueryString(t *testing.T) {
log.Debugf("%+v\n", form)
if err != nil {
t.Fatal("err should be nil")
t.Fatal(err)
}
assert.Equal(t, "cat", form.Label)
@ -61,7 +87,7 @@ func TestParseQueryString(t *testing.T) {
log.Debugf("%+v\n", form)
if err != nil {
t.Fatal("err should be nil")
t.Fatal(err)
}
assert.Equal(t, "tübingen", form.Title)
@ -72,7 +98,7 @@ func TestParseQueryString(t *testing.T) {
err := form.ParseQueryString()
if err == nil {
t.Fatal("err should NOT be nil")
t.Fatal(err)
}
log.Debugf("%+v\n", form)
@ -85,7 +111,7 @@ func TestParseQueryString(t *testing.T) {
err := form.ParseQueryString()
if err != nil {
t.Fatal("err should NOT be nil")
t.Fatal(err)
}
assert.True(t, form.Favorite)
@ -96,7 +122,7 @@ func TestParseQueryString(t *testing.T) {
err := form.ParseQueryString()
if err == nil {
t.Fatal("err should NOT be nil")
t.Fatal(err)
}
log.Debugf("%+v\n", form)
@ -109,7 +135,7 @@ func TestParseQueryString(t *testing.T) {
err := form.ParseQueryString()
if err == nil {
t.Fatal("err should NOT be nil")
t.Fatal(err)
}
log.Debugf("%+v\n", form)
@ -122,7 +148,7 @@ func TestParseQueryString(t *testing.T) {
err := form.ParseQueryString()
if err == nil {
t.Fatal("err should NOT be nil")
t.Fatal(err)
}
log.Debugf("%+v\n", form)
@ -135,7 +161,7 @@ func TestParseQueryString(t *testing.T) {
err := form.ParseQueryString()
if err == nil {
t.Fatal("err should NOT be nil")
t.Fatal(err)
}
log.Debugf("%+v\n", form)