Compare commits

...

3 commits

3 changed files with 30 additions and 4 deletions

View file

@ -10,6 +10,7 @@ mist = "~> 0.14"
gleam_http = "~> 3.5"
wisp = "~> 0.14"
sqlight = "~> 0.9"
lustre = "~> 4.1"
[dev-dependencies]
gleeunit = "~> 1.0"

View file

@ -14,6 +14,7 @@ packages = [
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "glisten", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "73BC09C8487C2FFC0963BFAB33ED2F0D636FDFA43B966E65C1251CBAB8458099" },
{ name = "logging", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "82C112ED9B6C30C1772A6FE2613B94B13F62EA35F5869A2630D13948D297BD39" },
{ name = "lustre", version = "4.1.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "09530DF24E7E540CA59AB2486909B52EEA5C39AE1A41EBC640AD04E5418FD67A" },
{ name = "marceau", version = "1.1.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "1AAD727A30BE0F95562C3403BB9B27C823797AD90037714255EEBF617B1CDA81" },
{ name = "mist", version = "0.17.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "glisten"], otp_app = "mist", source = "hex", outer_checksum = "DA8ACEE52C1E4892A75181B3166A4876D8CBC69D555E4770250BC84C80F75524" },
{ name = "simplifile", version = "1.6.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "B75D3C64E526D9D7EDEED5F3BA31DAAF5F2B4D80A4183FE17FDB02ED526E4E96" },
@ -27,6 +28,7 @@ gleam_erlang = { version = "~> 0.23" }
gleam_http = { version = "~> 3.5" }
gleam_stdlib = { version = "~> 0.30" }
gleeunit = { version = "~> 1.0" }
lustre = { version = "~> 4.1"}
mist = { version = "~> 0.14" }
sqlight = { version = "~> 0.9"}
sqlight = { version = "~> 0.9" }
wisp = { version = "~> 0.14" }

View file

@ -1,10 +1,13 @@
import wisp.{type Request, type Response}
import gleam/string_builder
import gleam/http.{Get}
import gleam/io
import gleam/list
import gleam/result
import gleam/dynamic
import ring/web
import sqlight
import lustre/attribute
import lustre/element/html
import lustre/element
pub fn handle_request(req: Request) -> Response {
use req <- web.middleware(req)
@ -77,8 +80,28 @@ fn home_page(req: Request) -> Response {
// The home page can only be accessed via GET requests, so this middleware is
// used to return a 405: Method Not Allowed response for all other methods.
use <- wisp.require_method(req, Get)
let db_path = "members.db"
use conn <- sqlight.with_connection(db_path)
let members =
sqlight.query(
"select member from ring order by member asc",
on: conn,
with: [],
expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
)
let members =
result.unwrap(members, [])
|> list.map(fn(row) {
let Row(member) = row
html.li([], [html.a([attribute.href(member)], [html.text(member)])])
})
let html =
html.body([], [
html.h1([], [html.text("The Constellation Webring")]),
html.ul([], members),
])
|> element.to_document_string_builder()
let html = string_builder.from_string("Hello, Joe!")
wisp.ok()
|> wisp.html_body(html)
}