summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2020-06-14 19:07:39 -0400
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2020-06-14 19:07:39 -0400
commite8020d1ec67c3f6e2e645ba80039d30db45950a9 (patch)
tree50787657de987c1e0c3d39bac2b33cb958e6c3ed
parent94d3fd454b8f70a430fc787357fdaccd7397e347 (diff)
Update semantics for web API (query string vs tag list).
-rw-r--r--README.md9
-rw-r--r--src/birka-web.rs14
-rw-r--r--templates/image.hbs4
-rw-r--r--templates/index.hbs4
4 files changed, 15 insertions, 16 deletions
diff --git a/README.md b/README.md
index 2476df6..99299ef 100644
--- a/README.md
+++ b/README.md
@@ -85,13 +85,12 @@ Suppose we denote the following shape of JSON object as a `ImageResult`.
```
The images in the tag database can be enumerated with the 'posts' endpoint,
-which takes two parameters: `tags`, a comma-separated list of zero or more
-strings, and `last`, which is the last `ImageResult` identifier which was seen.
-This endpoint will return, at most, 50 entries, which is why the `last`
-parameter is necessary.
+which takes two parameters: `query`, a query string, and `last`, which is the
+last `ImageResult` identifier which was seen. This endpoint will return, at
+most, 50 entries, which is why the `last` parameter is necessary.
```
-GET /api/posts?last=number,tags=[string, ...]
+GET /api/posts?last=number,query=string
[zero or more ImageResult]
```
diff --git a/src/birka-web.rs b/src/birka-web.rs
index 76a194f..e9bb81a 100644
--- a/src/birka-web.rs
+++ b/src/birka-web.rs
@@ -113,8 +113,8 @@ fn thumb_filename<T: AsRef<Path>>(id: i64, path: T) -> String {
}
}
-#[get("/posts?<tags>&<last>")]
-fn get_posts(conn: SiteState, tags: String, last: Option<i64>) -> Result<Json<Vec<FileResult>>> {
+#[get("/posts?<query>&<last>")]
+fn get_posts(conn: SiteState, query: String, last: Option<i64>) -> Result<Json<Vec<FileResult>>> {
let tb = &conn
.inner()
.lock()
@@ -132,7 +132,7 @@ fn get_posts(conn: SiteState, tags: String, last: Option<i64>) -> Result<Json<Ve
how_many: RESULTS_PER_QUERY,
}
};
- let results = tb.query(&database::parse_query(tags)?, Some(keyset))?;
+ let results = tb.query(&database::parse_query(query)?, Some(keyset))?;
Ok(Json(
results
@@ -231,8 +231,8 @@ fn upload() -> Template {
Template::render("upload", None::<()>)
}
-#[get("/posts?<tags>&<last>")]
-fn display_posts(conn: SiteState, tags: String, last: Option<i64>) -> Result<Template> {
+#[get("/posts?<query>&<last>")]
+fn display_posts(conn: SiteState, query: String, last: Option<i64>) -> Result<Template> {
#[derive(Serialize)]
struct TagResult {
name: String,
@@ -246,7 +246,7 @@ fn display_posts(conn: SiteState, tags: String, last: Option<i64>) -> Result<Tem
next_page: String,
}
- let base_params = format!("/posts?tags={}", tags);
+ let base_params = format!("/posts?query={}", query);
let tag_results = {
// This is done in a block because `tb` needs to go out of scope before
// calling out to `get_posts` to perform the query. Otherwise, we
@@ -265,7 +265,7 @@ fn display_posts(conn: SiteState, tags: String, last: Option<i64>) -> Result<Tem
})
.collect()
};
- let images = get_posts(conn, tags, last)?.into_inner();
+ let images = get_posts(conn, query, last)?.into_inner();
let context = Context {
tags: tag_results,
next_page: if images.len() as i64 == RESULTS_PER_QUERY {
diff --git a/templates/image.hbs b/templates/image.hbs
index fab65d5..ae24f06 100644
--- a/templates/image.hbs
+++ b/templates/image.hbs
@@ -17,7 +17,7 @@
<section id="search">
<h2>Search</h2>
<form id="search-box" method="GET" action="/posts">
- <input id="tags" name="tags" type="text" autocomplete="off">
+ <input id="tags" name="query" type="text" autocomplete="off">
<button id="search-box-submit" type="submit">Search</button>
</form>
</section>
@@ -26,7 +26,7 @@
<h2>Tags</h2>
<ul>
{{#each tags}}
- <li><a href="/posts?tags={{ . }}">{{ . }}</a></li>
+ <li><a href="/posts?query={{ . }}">{{ . }}</a></li>
{{/each}}
</ul>
diff --git a/templates/index.hbs b/templates/index.hbs
index 1279a5e..e481203 100644
--- a/templates/index.hbs
+++ b/templates/index.hbs
@@ -21,7 +21,7 @@
<section id="search">
<h2>Search</h2>
<form id="search-box" method="GET" action="/posts">
- <input id="tags" name="tags" type="text" autocomplete="off">
+ <input id="tags" name="query" type="text" autocomplete="off">
<button id="search-box-submit" type="submit">Search</button>
</form>
</section>
@@ -30,7 +30,7 @@
<h2>Tags</h2>
<ul>
{{#each tags}}
- <li><a href="/posts?tags={{ name }}">{{ name }}</a> {{ count }}</li>
+ <li><a href="/posts?query={{ name }}">{{ name }}</a> {{ count }}</li>
{{/each}}
</ul>
</section>