diff --git a/src/web/controllers/payment_controller.gleam b/src/web/controllers/payment_controller.gleam index 34dbad8..fef00ad 100644 --- a/src/web/controllers/payment_controller.gleam +++ b/src/web/controllers/payment_controller.gleam @@ -68,6 +68,18 @@ fn get_all_payments_response( |> json.object } +fn all_payments_empty_body() { + let body = + get_all_payments_response( + count_provider.new("default"), + count_provider.new("fallback"), + ) + |> json.to_string_tree + + wisp.ok() + |> wisp.json_body(body) +} + pub fn get_all_payments( req: wisp.Request, ctx: server.Context, @@ -83,28 +95,14 @@ pub fn get_all_payments( }) |> dict.from_list - use <- bool.guard( + use <- bool.lazy_guard( when: !dict.has_key(params, "from"), - return: wisp.ok() - |> wisp.json_body( - get_all_payments_response( - count_provider.new("default"), - count_provider.new("fallback"), - ) - |> json.to_string_tree, - ), + return: all_payments_empty_body, ) - use <- bool.guard( + use <- bool.lazy_guard( when: !dict.has_key(params, "to"), - return: wisp.ok() - |> wisp.json_body( - get_all_payments_response( - count_provider.new("default"), - count_provider.new("fallback"), - ) - |> json.to_string_tree, - ), + return: all_payments_empty_body, ) let assert Ok(from) = dict.get(params, "from")