|
@@ -1,36 +1,33 @@
|
|
module Stock
|
|
module Stock
|
|
|
|
|
|
open Giraffe
|
|
open Giraffe
|
|
|
|
+open Giraffe.ViewEngine
|
|
open Dapper
|
|
open Dapper
|
|
open Npgsql
|
|
open Npgsql
|
|
open Models
|
|
open Models
|
|
open FSharp.Control.Tasks
|
|
open FSharp.Control.Tasks
|
|
-open App
|
|
|
|
|
|
|
|
-let application : HttpHandler =
|
|
|
|
-
|
|
|
|
- let fortunes : HttpHandler =
|
|
|
|
- let extra = {id = 0; message = "Additional fortune added at request time."}
|
|
|
|
-
|
|
|
|
- fun _ ctx ->
|
|
|
|
- task {
|
|
|
|
- use conn = new NpgsqlConnection(ConnectionString)
|
|
|
|
- let! data = conn.QueryAsync<Fortune>("SELECT id, message FROM fortune")
|
|
|
|
|
|
+let extra = {id = 0; message = "Additional fortune added at request time."}
|
|
|
|
|
|
- let view =
|
|
|
|
- let xs = data.AsList()
|
|
|
|
- xs.Add extra
|
|
|
|
- xs.Sort FortuneComparer
|
|
|
|
- HtmlViews.fortunes xs
|
|
|
|
|
|
+let fortunes : HttpHandler =
|
|
|
|
+ fun _ ctx ->
|
|
|
|
+ task {
|
|
|
|
+ use conn = new NpgsqlConnection(ConnectionString)
|
|
|
|
+ let! data = conn.QueryAsync<Fortune>("SELECT id, message FROM fortune")
|
|
|
|
|
|
- let bytes =
|
|
|
|
- view
|
|
|
|
- |> StatefullRendering.renderHtmlToBytes
|
|
|
|
|
|
+ let view =
|
|
|
|
+ let xs = data.AsList()
|
|
|
|
+ xs.Add extra
|
|
|
|
+ xs.Sort FortuneComparer
|
|
|
|
+ HtmlViews.fortunes xs
|
|
|
|
|
|
- ctx.SetContentType "text/html;charset=utf-8"
|
|
|
|
- return! ctx.WriteBytesAsync bytes
|
|
|
|
- }
|
|
|
|
|
|
+ let bytes = RenderView.AsBytes.htmlDocument view
|
|
|
|
+
|
|
|
|
+ ctx.SetContentType "text/html;charset=utf-8"
|
|
|
|
+ return! ctx.WriteBytesAsync bytes
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+let application : HttpHandler =
|
|
choose [
|
|
choose [
|
|
route "/plaintext" >=> text "Hello, World!"
|
|
route "/plaintext" >=> text "Hello, World!"
|
|
route "/json" >=> json {| message = "Hello, World!" |}
|
|
route "/json" >=> json {| message = "Hello, World!" |}
|