Added request list by user
Input for what will be the main journal view
This commit is contained in:
parent
c98c7bd5bf
commit
d5635ef37c
26
src/App.fs
26
src/App.fs
@ -19,7 +19,7 @@ open Suave.Successful
|
|||||||
|
|
||||||
let utf8 = System.Text.Encoding.UTF8
|
let utf8 = System.Text.Encoding.UTF8
|
||||||
|
|
||||||
type JsonNetCookieSerializer() =
|
type JsonNetCookieSerializer () =
|
||||||
interface CookieSerialiser with
|
interface CookieSerialiser with
|
||||||
member x.serialise m =
|
member x.serialise m =
|
||||||
utf8.GetBytes (JsonConvert.SerializeObject m)
|
utf8.GetBytes (JsonConvert.SerializeObject m)
|
||||||
@ -147,22 +147,34 @@ module Auth =
|
|||||||
|
|
||||||
/// Add the logged on user Id to the context if it exists
|
/// Add the logged on user Id to the context if it exists
|
||||||
let loggedOn = warbler (fun ctx ->
|
let loggedOn = warbler (fun ctx ->
|
||||||
match ctx |> HttpContext.state with
|
match HttpContext.state ctx with
|
||||||
| Some state -> Writers.setUserData "user" (state.get "auth-token" |> getIdFromToken)
|
| Some state -> Writers.setUserData "user" (state.get "auth-token" |> getIdFromToken)
|
||||||
| _ -> Writers.setUserData "user" None)
|
| _ -> Writers.setUserData "user" None)
|
||||||
|
|
||||||
/// Create a user context for the currently assigned user
|
/// Create a user context for the currently assigned user
|
||||||
let userCtx ctx = { Id = ctx.userState.["user"] :?> string option }
|
let userCtx ctx = { Id = ctx.userState.["user"] :?> string option }
|
||||||
|
|
||||||
|
/// Read an item from the user state, downcast to the expected type
|
||||||
|
let read ctx key : 'value =
|
||||||
|
ctx.userState |> Map.tryFind key |> Option.map (fun x -> x :?> 'value) |> Option.get
|
||||||
|
|
||||||
/// Create a new data context
|
/// Create a new data context
|
||||||
let dataCtx () =
|
let dataCtx () =
|
||||||
new DataContext (((DbContextOptionsBuilder<DataContext>()).UseNpgsql cfg.Conn).Options)
|
new DataContext (((DbContextOptionsBuilder<DataContext>()).UseNpgsql cfg.Conn).Options)
|
||||||
|
|
||||||
|
/// Return an HTML page
|
||||||
|
let html ctx content =
|
||||||
|
Views.page (Auth.userCtx ctx) content
|
||||||
|
|
||||||
/// Home page
|
/// Home page
|
||||||
let viewHome = warbler (fun ctx -> OK (Views.page (Auth.userCtx ctx) Views.home))
|
let viewHome = warbler (fun ctx -> OK (Views.home |> html ctx))
|
||||||
|
|
||||||
/// Journal page
|
/// Journal page
|
||||||
let viewJournal = warbler (fun ctx -> OK (Views.page (Auth.userCtx ctx) Views.journal))
|
let viewJournal =
|
||||||
|
context (fun ctx ->
|
||||||
|
use dataCtx = dataCtx ()
|
||||||
|
let reqs = Data.Requests.allForUser (defaultArg (read ctx "user") "") dataCtx
|
||||||
|
OK (Views.journal reqs |> html ctx))
|
||||||
|
|
||||||
/// Suave application
|
/// Suave application
|
||||||
let app =
|
let app =
|
||||||
@ -180,16 +192,16 @@ let app =
|
|||||||
/// Ensure the EF context is created in the right format
|
/// Ensure the EF context is created in the right format
|
||||||
let ensureDatabase () =
|
let ensureDatabase () =
|
||||||
async {
|
async {
|
||||||
use data = dataCtx()
|
use data = dataCtx ()
|
||||||
do! data.Database.MigrateAsync ()
|
do! data.Database.MigrateAsync ()
|
||||||
}
|
}
|
||||||
|> Async.RunSynchronously
|
|> Async.RunSynchronously
|
||||||
|
|
||||||
let suaveCfg =
|
let suaveCfg =
|
||||||
{ defaultConfig with
|
{ defaultConfig with
|
||||||
homeFolder = Some (Path.GetFullPath "./wwwroot/")
|
homeFolder = Some (Path.GetFullPath "./wwwroot/")
|
||||||
serverKey = Text.Encoding.UTF8.GetBytes("12345678901234567890123456789012")
|
serverKey = Text.Encoding.UTF8.GetBytes("12345678901234567890123456789012")
|
||||||
cookieSerialiser = new JsonNetCookieSerializer()
|
cookieSerialiser = JsonNetCookieSerializer ()
|
||||||
}
|
}
|
||||||
|
|
||||||
[<EntryPoint>]
|
[<EntryPoint>]
|
||||||
|
21
src/Data.fs
21
src/Data.fs
@ -1,6 +1,7 @@
|
|||||||
namespace MyPrayerJournal
|
namespace MyPrayerJournal
|
||||||
|
|
||||||
open Microsoft.EntityFrameworkCore
|
open Microsoft.EntityFrameworkCore
|
||||||
|
open System.Linq
|
||||||
open System.Runtime.CompilerServices
|
open System.Runtime.CompilerServices
|
||||||
|
|
||||||
/// Data context for myPrayerJournal
|
/// Data context for myPrayerJournal
|
||||||
@ -34,3 +35,23 @@ type DataContext =
|
|||||||
|> Request.ConfigureEF
|
|> Request.ConfigureEF
|
||||||
|> History.ConfigureEF
|
|> History.ConfigureEF
|
||||||
|> ignore
|
|> ignore
|
||||||
|
|
||||||
|
/// Data access
|
||||||
|
module Data =
|
||||||
|
|
||||||
|
/// Data access for prayer requests
|
||||||
|
module Requests =
|
||||||
|
|
||||||
|
/// Get all prayer requests for a user
|
||||||
|
let allForUser userId (ctx : DataContext) =
|
||||||
|
query {
|
||||||
|
for req in ctx.Requests do
|
||||||
|
where (req.UserId = userId)
|
||||||
|
select req
|
||||||
|
}
|
||||||
|
|> Seq.sortBy
|
||||||
|
(fun req ->
|
||||||
|
match req.History |> Seq.sortBy (fun hist -> hist.AsOf) |> Seq.tryLast with
|
||||||
|
| Some hist -> hist.AsOf
|
||||||
|
| _ -> 0L)
|
||||||
|
|> List.ofSeq
|
||||||
|
@ -107,7 +107,7 @@ let home =
|
|||||||
p [ text "This site is currently in very limited alpha, as it is being developed with a core group of test users. If this is something you are interested in using, check back around mid-February 2017 to check on the development progress." ]
|
p [ text "This site is currently in very limited alpha, as it is being developed with a core group of test users. If this is something you are interested in using, check back around mid-February 2017 to check on the development progress." ]
|
||||||
]
|
]
|
||||||
|
|
||||||
let journal =
|
let journal (reqs : Request list) =
|
||||||
fullRow [
|
fullRow [
|
||||||
p [ text "journal goes here" ]
|
p [ text "journal goes here" ]
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user