Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Created April 14, 2018 11:07
Show Gist options
  • Save samueleresca/20d22cd3d10d935ea513c9d64b9abec1 to your computer and use it in GitHub Desktop.
Save samueleresca/20d22cd3d10d935ea513c9d64b9abec1 to your computer and use it in GitHub Desktop.
let labelUpdateHandler (id : int) =
fun (next : HttpFunc) (ctx : HttpContext) ->
task {
let context = ctx.RequestServices.GetService(typeof<LabelsContext>) :?> LabelsContext
let! label = ctx.BindJsonAsync<CreateUpdateLabelRequest>()
match label.HasErrors with
| Some msg -> return! (setStatusCode 400 >=> json msg) next ctx
| None ->
return! updateLabel context label.GetLabel id |> function
| Some l -> ctx.WriteJsonAsync l
| None -> (setStatusCode 400 >=> json "Label not updated") next ctx
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment