1
Fork 0

fsharp(todolist-api): feat: todo listing

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2020-01-02 17:50:27 +02:00 committed by prescientmoon
parent 886d8be8bb
commit 5b0365ed44
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
2 changed files with 21 additions and 3 deletions

View file

@ -1,6 +1,6 @@
// Learn more about F# at http://fsharp.org
open System
open FSharpPlus.Operators
open Suave
open Suave.Operators
open Suave.Successful
@ -62,13 +62,25 @@ module App =
return! respondWithTodo todo ctx
})
let listTodos _ =
Context.getContext()
|> Queries.getAllTodos
|>> todoToRecord
|> Json.serialize
|> Json.format
|> OK
let mainWebPart: WebPart = choose [
pathScan "/todos/%i" (fun (id) -> choose [
GET >=> todoById id
PUT >=> updateTodo id
PATCH >=> patchTodo id
DELETE >=> deleteTodo id
])]
])
path "/todos/" >=> choose [
GET >=> warbler listTodos
]]
[<EntryPoint>]
let main _ =

View file

@ -78,6 +78,12 @@ module Queries =
}
|> Seq.tryHead
let getAllTodos (ctx: DbContext): DbTodo list =
query {
for todo in ctx.Public.Todos do
select todo
}
|> Seq.toList
let updateTodoById (todo: DbTodo) (details: TodoDetails) (ctx: DbContext) =
todo.Name <- details.name