Use FunctionalCuid for CUIDs

This commit is contained in:
Daniel J. Summers 2019-08-09 17:00:09 -05:00
parent bf489cc4a8
commit d4671c044d
4 changed files with 14 additions and 17 deletions

View File

@ -2,13 +2,7 @@
/// The data model for myPrayerJournal
module MyPrayerJournal.Domain
/// A Collision-resistant Unique IDentifier
type Cuid =
| Cuid of string
module Cuid =
/// The string value of the CUID
let toString x = match x with Cuid y -> y
open Cuid
/// Request ID is a CUID
type RequestId =

View File

@ -2,10 +2,7 @@
[<RequireQualifiedAccess>]
module MyPrayerJournal.Handlers
open FSharp.Control.Tasks.V2.ContextInsensitive
open Giraffe
open MyPrayerJournal
open System
/// Handler to return Vue files
module Vue =
@ -13,6 +10,7 @@ module Vue =
/// The application index page
let app : HttpHandler = htmlFile "wwwroot/index.html"
open System
/// Handlers for error conditions
module Error =
@ -34,6 +32,7 @@ module Error =
| 0 -> (setStatusCode 404 >=> json ([ "error", "not found" ] |> dict)) next ctx
| _ -> Vue.app next ctx
open Cuid
/// Handler helpers
[<AutoOpen>]
@ -60,7 +59,12 @@ module private Helpers =
((user >> Option.get) ctx).Value |> UserId
/// Create a request ID from a string
let toReqId = Cuid >> RequestId
let toReqId x =
let reqId =
match Cuid.ofString x with
| Ok cuid -> cuid
| Error msg -> invalidOp msg
RequestId reqId
/// Return a 201 CREATED response
let created next ctx =
@ -136,6 +140,8 @@ module Models =
until : int64
}
open FSharp.Control.Tasks.V2.ContextInsensitive
/// /api/journal URLs
module Journal =
@ -155,8 +161,6 @@ module Journal =
/// /api/request URLs
module Request =
open NCuid
/// POST /api/request
let add : HttpHandler =
authorize
@ -164,7 +168,7 @@ module Request =
task {
let! r = ctx.BindJsonAsync<Models.Request> ()
use sess = session ctx
let reqId = (Cuid.Generate >> toReqId) ()
let reqId = (Cuid.generate >> RequestId) ()
let usrId = userId ctx
let now = jsNow ()
do! Data.addRequest

View File

@ -13,18 +13,18 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FunctionalCuid" Version="1.0.0" />
<PackageReference Include="Giraffe" Version="3.6.0" />
<PackageReference Include="Giraffe.TokenRouter" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.FSharpLu" Version="0.10.29" />
<PackageReference Include="Microsoft.FSharpLu.Json" Version="0.10.29" />
<PackageReference Include="NCuid.NetCore" Version="1.0.1" />
<PackageReference Include="RavenDb.Client" Version="4.2.1" />
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.6.2" />
<PackageReference Update="FSharp.Core" Version="4.7.0" />
</ItemGroup>
<ItemGroup>

View File

@ -40,7 +40,6 @@ module Configure =
open Giraffe.TokenRouter
open Microsoft.AspNetCore.Authentication.JwtBearer
open Microsoft.Extensions.DependencyInjection
open MyPrayerJournal
open MyPrayerJournal.Indexes
open Newtonsoft.Json
open Newtonsoft.Json.Serialization