[ring] Simplify types

This commit is contained in:
Erika Rowland 2024-03-31 12:01:12 -07:00
parent 0a6d1dc171
commit c7d629645c
1 changed files with 8 additions and 12 deletions

View File

@ -24,10 +24,6 @@ pub fn handle_request(req: Request) -> Response {
}
}
type Row {
Row(String)
}
fn handle_previous(hash) {
let db_path = "members.db"
use conn <- sqlight.with_connection(db_path)
@ -36,10 +32,10 @@ fn handle_previous(hash) {
"select previous from ring where hash = ?",
on: conn,
with: [sqlight.text(hash)],
expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
expecting: dynamic.element(0, dynamic.string),
)
case previous {
Ok([Row(previous_link)]) -> wisp.redirect(previous_link)
Ok([previous_link]) -> wisp.redirect(previous_link)
_ -> wisp.not_found()
}
}
@ -52,10 +48,10 @@ fn handle_next(hash) {
"select next from ring where hash = ?",
on: conn,
with: [sqlight.text(hash)],
expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
expecting: dynamic.element(0, dynamic.string),
)
case next {
Ok([Row(next_link)]) -> wisp.redirect(next_link)
Ok([next_link]) -> wisp.redirect(next_link)
_ -> wisp.not_found()
}
}
@ -68,10 +64,10 @@ fn handle_random() {
"select next from ring order by random() limit 1",
on: conn,
with: [],
expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
expecting: dynamic.element(0, dynamic.string),
)
case random {
Ok([Row(random_link)]) -> wisp.redirect(random_link)
Ok([random_link]) -> wisp.redirect(random_link)
_ -> wisp.not_found()
}
}
@ -87,12 +83,12 @@ fn home_page(req: Request) -> Response {
"select member from ring order by member asc",
on: conn,
with: [],
expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
expecting: dynamic.element(0, dynamic.string),
)
let members =
result.unwrap(members, [])
|> list.map(fn(row) {
let Row(member) = row
let member = row
html.li([], [html.a([attribute.href(member)], [html.text(member)])])
})
let html =