fsharp(todolist-api): refactor: removed duplicate Some checks
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
67ae890717
commit
6400fd753b
|
@ -25,22 +25,19 @@ module App =
|
||||||
open Utils
|
open Utils
|
||||||
open Db
|
open Db
|
||||||
|
|
||||||
let todoById (id): WebPart =
|
let withTodoById f (id): WebPart =
|
||||||
let todo =
|
let ctx = Context.getContext()
|
||||||
Context.getContext()
|
let dbTodo = ctx |> Queries.getTodosById id
|
||||||
|> Queries.getTodosById id
|
|
||||||
|>> todoToRecord
|
|
||||||
|
|
||||||
match todo with
|
match dbTodo with
|
||||||
| Some inner -> inner |> jsonToString |> OK
|
| Some inner -> f (inner, ctx, id)
|
||||||
| None -> id |> sprintf "Cannot find todo with id %i" |> NOT_FOUND
|
| None -> id |> sprintf "Cannot find todo with id %i" |> NOT_FOUND
|
||||||
|
|
||||||
let updateTodo (id): WebPart =
|
let todoById =
|
||||||
let dbContext = Context.getContext()
|
(fun (inner, _, _) -> inner |> todoToRecord |> jsonToString |> OK) |> withTodoById
|
||||||
let todo = dbContext |> Queries.getTodosById id
|
|
||||||
|
|
||||||
match todo with
|
let updateTodo =
|
||||||
| Some todo ->
|
(fun (todo, dbContext, id) ->
|
||||||
fun ctx -> async {
|
fun ctx -> async {
|
||||||
let body: Types.TodoDetails = ctx.request.rawForm |> fromJson
|
let body: Types.TodoDetails = ctx.request.rawForm |> fromJson
|
||||||
|
|
||||||
|
@ -55,10 +52,7 @@ module App =
|
||||||
let withNewBody = newBody |> toJson |> ok
|
let withNewBody = newBody |> toJson |> ok
|
||||||
return! withNewBody ctx
|
return! withNewBody ctx
|
||||||
}
|
}
|
||||||
|
) |> withTodoById
|
||||||
| None -> id |> sprintf "Cannot find todo with id %i" |> NOT_FOUND
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mainWebPart: WebPart = choose [
|
let mainWebPart: WebPart = choose [
|
||||||
GET >=> pathScan "/todos/%i" todoById
|
GET >=> pathScan "/todos/%i" todoById
|
||||||
|
|
Loading…
Reference in a new issue