aboutsummaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/query.go3
-rw-r--r--internal/api/query_test.go39
2 files changed, 42 insertions, 0 deletions
diff --git a/internal/api/query.go b/internal/api/query.go
index 3468163..d5428f0 100644
--- a/internal/api/query.go
+++ b/internal/api/query.go
@@ -62,5 +62,8 @@ 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 cbfe89a..a1effe7 100644
--- a/internal/api/query_test.go
+++ b/internal/api/query_test.go
@@ -1,6 +1,7 @@
package api
import (
+ "net/http"
"net/http/httptest"
"testing"
@@ -209,3 +210,41 @@ func TestParseQueryOrderWithoutSort(t *testing.T) {
)
}
}
+
+func TestParseQueryExtension(t *testing.T) {
+ req := httptest.NewRequest(
+ http.MethodGet,
+ "/api/photos?extension=jpg",
+ nil,
+ )
+
+ got, err := parseQuery(req)
+ if err != nil {
+ t.Fatalf("parseQuery() error = %v", err)
+ }
+
+ if got.Extension != "jpg" {
+ 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,
+ )
+ }
+}