From c7d629645c15798e0f4652eaddef22f41984b597 Mon Sep 17 00:00:00 2001 From: Erika Rowland Date: Sun, 31 Mar 2024 12:01:12 -0700 Subject: [PATCH] [ring] Simplify types --- src/ring/router.gleam | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/ring/router.gleam b/src/ring/router.gleam index 507cb21..ae44a4d 100644 --- a/src/ring/router.gleam +++ b/src/ring/router.gleam @@ -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 =