Added request list by user

Input for what will be the main journal view
This commit is contained in:
Daniel J. Summers 2017-04-30 21:16:45 -05:00
parent c98c7bd5bf
commit d5635ef37c
3 changed files with 41 additions and 8 deletions

View File

@ -147,22 +147,34 @@ module Auth =
/// Add the logged on user Id to the context if it exists
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)
| _ -> Writers.setUserData "user" None)
/// Create a user context for the currently assigned user
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
let dataCtx () =
new DataContext (((DbContextOptionsBuilder<DataContext>()).UseNpgsql cfg.Conn).Options)
/// Return an HTML page
let html ctx content =
Views.page (Auth.userCtx ctx) content
/// 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
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
let app =
@ -189,7 +201,7 @@ let suaveCfg =
{ defaultConfig with
homeFolder = Some (Path.GetFullPath "./wwwroot/")
serverKey = Text.Encoding.UTF8.GetBytes("12345678901234567890123456789012")
cookieSerialiser = new JsonNetCookieSerializer()
cookieSerialiser = JsonNetCookieSerializer ()
}
[<EntryPoint>]

View File

@ -1,6 +1,7 @@
namespace MyPrayerJournal
open Microsoft.EntityFrameworkCore
open System.Linq
open System.Runtime.CompilerServices
/// Data context for myPrayerJournal
@ -34,3 +35,23 @@ type DataContext =
|> Request.ConfigureEF
|> History.ConfigureEF
|> 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

View File

@ -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." ]
]
let journal =
let journal (reqs : Request list) =
fullRow [
p [ text "journal goes here" ]
]