mirror of
https://github.com/valitydev/capi-v2.git
synced 2024-11-06 01:55:20 +00:00
deps: Update dmt_client (#550)
* deps: Update dmt_client * fix: Fix opts passing * fix: Fix capi_domain * test: Fix tests for new ordering * refactor: Fix get_objects_by_type signature * refactor: Fix copypaste
This commit is contained in:
parent
0f7a5f92a8
commit
2fc4f66070
@ -3,7 +3,6 @@
|
||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||
-include_lib("damsel/include/dmsl_domain_config_thrift.hrl").
|
||||
|
||||
-export([get_categories/1]).
|
||||
-export([get_payment_institutions/1]).
|
||||
-export([get/2]).
|
||||
-export([get_objects_by_type/2]).
|
||||
@ -12,65 +11,48 @@
|
||||
-type ref() :: dmsl_domain_thrift:'Reference'().
|
||||
-type data() :: _.
|
||||
|
||||
-type category() :: #domain_CategoryObject{}.
|
||||
-type payment_institution() :: #domain_PaymentInstitutionObject{}.
|
||||
|
||||
-spec get_categories(context()) -> {ok, [category()]}.
|
||||
get_categories(Context) ->
|
||||
get_objects_by_type(Context, 'category').
|
||||
|
||||
-spec get_objects_by_type(context(), Type :: atom()) -> {ok, [dmsl_domain_thrift:'DomainObject'()]}.
|
||||
get_objects_by_type(Context, Type) ->
|
||||
#'Snapshot'{domain = Domain} = get_shapshot(Context),
|
||||
Objects = maps:fold(
|
||||
fun
|
||||
({Variant, _}, {Variant, Object}, Acc) when Variant =:= Type ->
|
||||
[Object | Acc];
|
||||
(_, _, Acc) ->
|
||||
Acc
|
||||
end,
|
||||
[],
|
||||
Domain
|
||||
),
|
||||
{ok, Objects}.
|
||||
|
||||
-spec get_payment_institutions(context()) -> {ok, [payment_institution()]}.
|
||||
get_payment_institutions(Context) ->
|
||||
% All this mess was done to reduce requests to dominant.
|
||||
% TODO rewrite this with dmt_client, cache, unicorns and rainbows.
|
||||
#'Snapshot'{domain = Domain} = get_shapshot(Context),
|
||||
Ref = {globals, #domain_GlobalsRef{}},
|
||||
{ok, {globals, #domain_GlobalsObject{data = Globals}}} = dmt_domain:get_object(Ref, Domain),
|
||||
{ok, get_payment_institutions(Globals, Domain)}.
|
||||
Opts = #{woody_context => Context},
|
||||
|
||||
get_payment_institutions(#domain_Globals{payment_institutions = PaymentInstitutionRefs}, Domain) when
|
||||
PaymentInstitutionRefs /= undefined
|
||||
->
|
||||
lists:map(
|
||||
fun(Ref) ->
|
||||
{ok, {payment_institution, Object}} = dmt_domain:get_object({payment_institution, Ref}, Domain),
|
||||
Object
|
||||
#'VersionedObject'{
|
||||
version = Version,
|
||||
object = {globals, #domain_GlobalsObject{data = Globals}}
|
||||
} = dmt_client:checkout_versioned_object(latest, globals(), Opts),
|
||||
|
||||
PaymentInstitutionRefs =
|
||||
case Globals#domain_Globals.payment_institutions of
|
||||
undefined -> [];
|
||||
List -> List
|
||||
end,
|
||||
ordsets:to_list(PaymentInstitutionRefs)
|
||||
);
|
||||
get_payment_institutions(#domain_Globals{payment_institutions = undefined}, _) ->
|
||||
[].
|
||||
|
||||
PaymentInstitutions =
|
||||
lists:map(
|
||||
fun(Ref) ->
|
||||
{payment_institution, Object} = dmt_client:checkout_object(Version, {payment_institution, Ref}, Opts),
|
||||
Object
|
||||
end,
|
||||
PaymentInstitutionRefs
|
||||
),
|
||||
|
||||
{ok, PaymentInstitutions}.
|
||||
|
||||
-spec get(ref(), context()) -> {ok, data()} | {error, not_found}.
|
||||
get(Ref, Context) ->
|
||||
#'Snapshot'{domain = Domain} = get_shapshot(Context),
|
||||
case dmt_domain:get_object(Ref, Domain) of
|
||||
{ok, {_Type, C}} ->
|
||||
{ok, C};
|
||||
error ->
|
||||
try
|
||||
{_Type, Object} = dmt_client:checkout_object(latest, Ref, #{woody_context => Context}),
|
||||
{ok, Object}
|
||||
catch
|
||||
throw:#'ObjectNotFound'{} ->
|
||||
{error, not_found}
|
||||
end.
|
||||
|
||||
get_shapshot(Context) ->
|
||||
get_shapshot(head(), Context).
|
||||
globals() ->
|
||||
{globals, #domain_GlobalsRef{}}.
|
||||
|
||||
get_shapshot(Reference, _Context) ->
|
||||
dmt_client:checkout(Reference).
|
||||
|
||||
head() ->
|
||||
{'head', #'Head'{}}.
|
||||
-spec get_objects_by_type(Type :: atom(), context()) -> {ok, [dmsl_domain_thrift:'DomainObject'()]}.
|
||||
get_objects_by_type(Type, Context) ->
|
||||
Objects = dmt_client:checkout_objects_by_type(latest, Type, #{woody_context => Context}),
|
||||
{ok, Objects}.
|
||||
|
@ -19,7 +19,7 @@ prepare(OperationID = 'GetCategories', Req, Context = #{woody_context := WoodyCo
|
||||
{ok, capi_auth:authorize_operation(Prototypes, Context, Req)}
|
||||
end,
|
||||
Process = fun() ->
|
||||
Categories = capi_utils:unwrap(capi_domain:get_categories(WoodyContext)),
|
||||
Categories = capi_utils:unwrap(capi_domain:get_objects_by_type(category, WoodyContext)),
|
||||
{ok, {200, #{}, [decode_category(C) || C <- Categories]}}
|
||||
end,
|
||||
{ok, #{authorize => Authorize, process => Process}};
|
||||
|
@ -22,7 +22,7 @@ prepare(_OperationID, _Req, _Context) ->
|
||||
{error, noimpl}.
|
||||
|
||||
process_request('GetCountries', _Req, #{woody_context := WoodyContext}) ->
|
||||
Countries = unwrap(capi_domain:get_objects_by_type(WoodyContext, country)),
|
||||
Countries = unwrap(capi_domain:get_objects_by_type(country, WoodyContext)),
|
||||
{ok, {200, #{}, lists:map(fun decode_country_object/1, Countries)}};
|
||||
process_request('GetCountryByID', Req, #{woody_context := WoodyContext}) ->
|
||||
CountryCode = capi_coder_utils:encode_country_code(maps:get(countryID, Req)),
|
||||
|
@ -23,8 +23,8 @@ prepare(_OperationID, _Req, _Context) ->
|
||||
{error, noimpl}.
|
||||
|
||||
process_request('GetTradeBlocs', _Req, #{woody_context := WoodyContext}) ->
|
||||
Countries = unwrap(capi_domain:get_objects_by_type(WoodyContext, trade_bloc)),
|
||||
{ok, {200, #{}, lists:map(fun decode_trade_bloc_object/1, Countries)}};
|
||||
TradeBlocs = unwrap(capi_domain:get_objects_by_type(trade_bloc, WoodyContext)),
|
||||
{ok, {200, #{}, lists:map(fun decode_trade_bloc_object/1, TradeBlocs)}};
|
||||
process_request('GetTradeBlocByID', Req, #{woody_context := WoodyContext}) ->
|
||||
Ref = {trade_bloc, #domain_TradeBlocRef{id = maps:get('tradeBlocID', Req)}},
|
||||
case capi_domain:get(Ref, WoodyContext) of
|
||||
|
@ -2382,14 +2382,14 @@ get_country_by_id_not_found_test(Config) ->
|
||||
get_countries_test(Config) ->
|
||||
?assertEqual(
|
||||
{ok, [
|
||||
#{
|
||||
<<"id">> => <<"RUS">>,
|
||||
<<"name">> => <<"Russia">>
|
||||
},
|
||||
#{
|
||||
<<"id">> => <<"DEU">>,
|
||||
<<"name">> => <<"Germany">>,
|
||||
<<"tradeBlocs">> => [<<"EEA">>]
|
||||
},
|
||||
#{
|
||||
<<"id">> => <<"RUS">>,
|
||||
<<"name">> => <<"Russia">>
|
||||
}
|
||||
]},
|
||||
capi_client_countries:get_countries(?config(context, Config))
|
||||
|
@ -43,7 +43,7 @@
|
||||
0},
|
||||
{<<"dmt_client">>,
|
||||
{git,"https://github.com/rbkmoney/dmt_client.git",
|
||||
{ref,"37f376e239a2182cbb2a7a052797e99955edbaad"}},
|
||||
{ref,"53924f4de479d6a5e05199b5d25931237150d72d"}},
|
||||
0},
|
||||
{<<"dmt_core">>,
|
||||
{git,"https://github.com/rbkmoney/dmt_core.git",
|
||||
|
Loading…
Reference in New Issue
Block a user