Skip to content

Commit

Permalink
fix: problem with headers and location in created
Browse files Browse the repository at this point in the history
  • Loading branch information
algebraic-dev committed Aug 22, 2023
1 parent cf9f2f7 commit fd2f143
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ open Rinha.Environment
/--
Rinha de backend basic application monad
-/
def app (db: Pgsql.Connection) : Ash.App Unit := do
def app (env: Environment) (db: Pgsql.Connection) : Ash.App Unit := do
post "/pessoas" $ λ conn => do
let person : Option Person := conn.json
match person with
| none => conn.unprocessableEntity "Invalid JSON"
| some person =>
let res ← person.create! db
match res with
| some person => conn.created person
| some person => do
let location := s!"http://{env.host}:{env.port}/pessoas/{person.id}"
conn.created person location
| none => conn.unprocessableEntity "Already exists."

get "/pessoas/:id" $ λ conn => do
Expand Down Expand Up @@ -49,7 +51,7 @@ def main : IO Unit := do

-- Connects to the database using the environment variables.
let conn ← Pgsql.connect $ env.postgres.toConnectionString
let app := app conn
let app := app env conn
IO.println s!"INFO: Database connection set up"

-- Run the application with the environment variables host and port.
Expand Down
2 changes: 1 addition & 1 deletion lake-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
{"git":
{"url": "https://github.com/algebraic-sofia/ash.git",
"subDir?": null,
"rev": "b771f1bae9301e6131e9b08b039787f6c97db043",
"rev": "236b99b537f8b9d36b37b647f1b9827631335013",
"name": "ash",
"inputRev?": null}}]}

0 comments on commit fd2f143

Please sign in to comment.