From f6881afaa5a0c31f7cc9a9767f84a4c3635938b9 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 5 Aug 2018 20:16:18 -0500 Subject: [PATCH] Feature parity achieved The F#/Giraffe API backend now does everything the Go one did; now to finish request snoozing... --- src/api/MyPrayerJournal.Api/Data.fs | 30 ++++++++----------- src/api/MyPrayerJournal.Api/Handlers.fs | 5 ++-- src/app/src/components/AnsweredDetail.vue | 7 +++-- .../components/request/FullRequestHistory.vue | 8 ++--- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/api/MyPrayerJournal.Api/Data.fs b/src/api/MyPrayerJournal.Api/Data.fs index 45b4831..fefb8de 100644 --- a/src/api/MyPrayerJournal.Api/Data.fs +++ b/src/api/MyPrayerJournal.Api/Data.fs @@ -37,8 +37,6 @@ module Entities = status : string /// The text of the update, if applicable text : string option - /// The request to which this history entry applies - request : Request } with /// An empty history entry @@ -47,7 +45,6 @@ module Entities = asOf = 0L status = "" text = None - request = Request.empty } static member configureEF (mb : ModelBuilder) = @@ -58,11 +55,7 @@ module Entities = m.Property(fun e -> e.requestId).IsRequired () |> ignore m.Property(fun e -> e.asOf).IsRequired () |> ignore m.Property(fun e -> e.status).IsRequired() |> ignore - m.Property(fun e -> e.text) |> ignore - m.HasOne(fun e -> e.request) - .WithMany(fun r -> r.history :> IEnumerable) - .HasForeignKey(fun e -> e.requestId :> obj) - |> ignore) + m.Property(fun e -> e.text) |> ignore) |> ignore let typ = mb.Model.FindEntityType(typeof) let prop = typ.FindProperty("text") @@ -76,8 +69,6 @@ module Entities = asOf : int64 /// The text of the notes notes : string - /// The request to which this note applies - request : Request } with /// An empty note @@ -85,7 +76,6 @@ module Entities = { requestId = "" asOf = 0L notes = "" - request = Request.empty } static member configureEF (mb : ModelBuilder) = @@ -95,11 +85,7 @@ module Entities = m.HasKey ("requestId", "asOf") |> ignore m.Property(fun e -> e.requestId).IsRequired () |> ignore m.Property(fun e -> e.asOf).IsRequired () |> ignore - m.Property(fun e -> e.notes).IsRequired () |> ignore - m.HasOne(fun e -> e.request) - .WithMany(fun r -> r.notes :> IEnumerable) - .HasForeignKey(fun e -> e.requestId :> obj) - |> ignore) + m.Property(fun e -> e.notes).IsRequired () |> ignore) |> ignore // Request is the identifying record for a prayer request. @@ -136,7 +122,15 @@ module Entities = m.Property(fun e -> e.requestId).IsRequired () |> ignore m.Property(fun e -> e.enteredOn).IsRequired () |> ignore m.Property(fun e -> e.userId).IsRequired () |> ignore - m.Property(fun e -> e.snoozedUntil).IsRequired () |> ignore) + m.Property(fun e -> e.snoozedUntil).IsRequired () |> ignore + m.HasMany(fun e -> e.history :> IEnumerable) + .WithOne() + .HasForeignKey(fun e -> e.requestId :> obj) + |> ignore + m.HasMany(fun e -> e.notes :> IEnumerable) + .WithOne() + .HasForeignKey(fun e -> e.requestId :> obj) + |> ignore) |> ignore /// JournalRequest is the form of a prayer request returned for the request journal display. It also contains @@ -230,7 +224,7 @@ type AppDbContext (opts : DbContextOptions) = member this.JournalByUserId userId : JournalRequest seq = upcast this.Journal .Where(fun r -> r.userId = userId && r.lastStatus <> "Answered") - .OrderByDescending(fun r -> r.asOf) + .OrderBy(fun r -> r.asOf) /// Retrieve a request by its ID and user ID member this.TryRequestById reqId userId : Task = diff --git a/src/api/MyPrayerJournal.Api/Handlers.fs b/src/api/MyPrayerJournal.Api/Handlers.fs index ca839c9..b16c167 100644 --- a/src/api/MyPrayerJournal.Api/Handlers.fs +++ b/src/api/MyPrayerJournal.Api/Handlers.fs @@ -54,7 +54,7 @@ module private Helpers = /// The "now" time in JavaScript let jsNow () = - DateTime.Now.Subtract(DateTime (1970, 1, 1)).TotalSeconds |> int64 |> (*) 1000L + DateTime.UtcNow.Subtract(DateTime (1970, 1, 1, 0, 0, 0)).TotalSeconds |> int64 |> (*) 1000L /// Handler to return a 403 Not Authorized reponse let notAuthorized : HttpHandler = @@ -102,6 +102,7 @@ module Models = until : int64 } + /// /api/journal URLs module Journal = @@ -206,7 +207,7 @@ module Request = authorize >=> fun next ctx -> task { - let! req = (db ctx).TryRequestById reqId (userId ctx) + let! req = (db ctx).TryJournalById reqId (userId ctx) match req with | Some r -> return! json r next ctx | None -> return! Error.notFound next ctx diff --git a/src/app/src/components/AnsweredDetail.vue b/src/app/src/components/AnsweredDetail.vue index 47a0f4b..eeb1b12 100644 --- a/src/app/src/components/AnsweredDetail.vue +++ b/src/app/src/components/AnsweredDetail.vue @@ -10,6 +10,7 @@ article b-table(small hover :fields='fields' :items='log') template(slot='action' scope='data'). {{ data.item.status }} on #[span.text-nowrap {{ formatDate(data.item.asOf) }}] + template(slot='text' scope='data' v-if='data.item.text') {{ data.item.text.fields[0] }}