mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 10:45:21 +00:00
[WIP] Implement 'ListProviders'
This commit is contained in:
parent
5aeaaf8c83
commit
06fd8a51e7
@ -10,6 +10,7 @@
|
||||
-export_type([maybe/1]).
|
||||
|
||||
-export([from_result/1]).
|
||||
-export([to_list/1]).
|
||||
|
||||
%%
|
||||
|
||||
@ -20,3 +21,11 @@ from_result({ok, T}) ->
|
||||
T;
|
||||
from_result({error, _}) ->
|
||||
undefined.
|
||||
|
||||
-spec to_list(maybe(T)) ->
|
||||
[T].
|
||||
|
||||
to_list(undefined) ->
|
||||
[];
|
||||
to_list(T) ->
|
||||
[T].
|
||||
|
@ -36,6 +36,7 @@
|
||||
-export([residences/1]).
|
||||
-export([payinst/1]).
|
||||
|
||||
-export([list/0]).
|
||||
-export([get/1]).
|
||||
-export([list_identity_classes/1]).
|
||||
-export([get_identity_class/2]).
|
||||
@ -60,6 +61,15 @@ payinst(#{payinst_ref := V}) -> V.
|
||||
|
||||
%%
|
||||
|
||||
-spec list() ->
|
||||
[provider()].
|
||||
|
||||
list() ->
|
||||
[Provider ||
|
||||
ID <- list_providers(),
|
||||
{ok, Provider} <- [ff_provider:get(ID)]
|
||||
].
|
||||
|
||||
-spec get(id()) ->
|
||||
{ok, provider()} |
|
||||
{error, notfound}.
|
||||
@ -154,3 +164,9 @@ get_provider_config(ID) ->
|
||||
#{} ->
|
||||
{error, notfound}
|
||||
end.
|
||||
|
||||
-spec list_providers() ->
|
||||
[id()].
|
||||
|
||||
list_providers() ->
|
||||
maps:keys(genlib_app:env(fistful, providers, #{})).
|
||||
|
@ -46,8 +46,15 @@
|
||||
%% Providers
|
||||
|
||||
-spec get_providers(_, _) -> no_return().
|
||||
get_providers(_Params, _Context) ->
|
||||
not_implemented().
|
||||
get_providers(Residences, _Context) ->
|
||||
ResidenceSet = ordsets:from_list(from_swag(list, {residence, Residences})),
|
||||
to_swag(list, {provider, [P ||
|
||||
P <- ff_provider:list(),
|
||||
ordsets:is_subset(
|
||||
ResidenceSet,
|
||||
ordsets:from_list(ff_provider:residences(P))
|
||||
)
|
||||
]}).
|
||||
|
||||
-spec get_provider(_, _) -> _.
|
||||
get_provider(ProviderId, _Context) ->
|
||||
|
@ -37,12 +37,10 @@ handle_request(OperationID, Req, SwagContext, Opts) ->
|
||||
%% Providers
|
||||
-spec process_request(operation_id(), req_data(), handler_context(), handler_opts()) ->
|
||||
request_result().
|
||||
process_request('ListProviders', _Req, #{woody_context := _Context}, _Opts) ->
|
||||
%% case wapi_wallet_ff_backend:get_providers(maps:with(['residence'], Req), Context) of
|
||||
%% {ok, Providers} -> wapi_handler_utils:reply_ok(200, Providers);
|
||||
%% {error, notfound} -> wapi_handler_utils:reply_ok(200, [])
|
||||
%% end;
|
||||
not_implemented();
|
||||
process_request('ListProviders', Req, #{woody_context := Context}, _Opts) ->
|
||||
Residences = ff_maybe:to_list(maps:get('residence', Req)),
|
||||
Providers = wapi_wallet_ff_backend:get_providers(Residences, Context),
|
||||
wapi_handler_utils:reply_ok(200, Providers);
|
||||
process_request('GetProvider', #{'providerID' := Id}, #{woody_context := Context}, _Opts) ->
|
||||
case wapi_wallet_ff_backend:get_provider(Id, Context) of
|
||||
{ok, Provider} -> wapi_handler_utils:reply_ok(200, Provider);
|
||||
|
Loading…
Reference in New Issue
Block a user