this repo has no description

:recycle: creating function for common pattern in controller

Changed files
+16 -18
src
web
+16 -18
src/web/controllers/payment_controller.gleam
··· 68 68 |> json.object 69 69 } 70 70 71 + fn all_payments_empty_body() { 72 + let body = 73 + get_all_payments_response( 74 + count_provider.new("default"), 75 + count_provider.new("fallback"), 76 + ) 77 + |> json.to_string_tree 78 + 79 + wisp.ok() 80 + |> wisp.json_body(body) 81 + } 82 + 71 83 pub fn get_all_payments( 72 84 req: wisp.Request, 73 85 ctx: server.Context, ··· 83 95 }) 84 96 |> dict.from_list 85 97 86 - use <- bool.guard( 98 + use <- bool.lazy_guard( 87 99 when: !dict.has_key(params, "from"), 88 - return: wisp.ok() 89 - |> wisp.json_body( 90 - get_all_payments_response( 91 - count_provider.new("default"), 92 - count_provider.new("fallback"), 93 - ) 94 - |> json.to_string_tree, 95 - ), 100 + return: all_payments_empty_body, 96 101 ) 97 102 98 - use <- bool.guard( 103 + use <- bool.lazy_guard( 99 104 when: !dict.has_key(params, "to"), 100 - return: wisp.ok() 101 - |> wisp.json_body( 102 - get_all_payments_response( 103 - count_provider.new("default"), 104 - count_provider.new("fallback"), 105 - ) 106 - |> json.to_string_tree, 107 - ), 105 + return: all_payments_empty_body, 108 106 ) 109 107 110 108 let assert Ok(from) = dict.get(params, "from")