diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-08-25 19:40:36 +0530 |
|---|---|---|
| committer | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-08-25 19:40:36 +0530 |
| commit | cce66ffa45779bc8752c0237a1dfad34083479bf (patch) | |
| tree | 58b61114ae6f433acdec0b5edbb3773370af243f /internal | |
| parent | 2ca59223f20029a3a4a351b22706b2b4d47ad6e3 (diff) | |
| download | galleryd-cce66ffa45779bc8752c0237a1dfad34083479bf.tar.xz galleryd-cce66ffa45779bc8752c0237a1dfad34083479bf.zip | |
feat(api): parse search query parameter
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/query.go | 1 | ||||
| -rw-r--r-- | internal/api/query_test.go | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/internal/api/query.go b/internal/api/query.go index d33027f..d5428f0 100644 --- a/internal/api/query.go +++ b/internal/api/query.go @@ -63,6 +63,7 @@ func parseQuery(r *http.Request) (gallery.Query, error) { } query.Extension = values.Get("extension") + query.Search = values.Get("q") return query, nil } diff --git a/internal/api/query_test.go b/internal/api/query_test.go index 0c3c1ae..a1effe7 100644 --- a/internal/api/query_test.go +++ b/internal/api/query_test.go @@ -227,3 +227,24 @@ func TestParseQueryExtension(t *testing.T) { t.Fatalf("expected extension %q, got %q", "jpg", got.Extension) } } + +func TestParseQuerySearch(t *testing.T) { + req := httptest.NewRequest( + "http.MethodGet", + "/api/photos?q=vacation", + nil, + ) + + got, err := parseQuery(req) + if err != nil { + t.Fatalf("parseQuery() error = %v", err) + } + + if got.Search != "vacation" { + t.Fatalf( + "expected search %q, got %q", + "vacation", + got.Search, + ) + } +} |