mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
parent
2b1fa632a6
commit
f599a4e394
@ -30,7 +30,8 @@ marshal_deposit_state(DepositState, Context) ->
|
||||
reverts = [ff_deposit_revert_codec:marshal(revert_state, R) || R <- Reverts],
|
||||
adjustments = [ff_deposit_adjustment_codec:marshal(adjustment_state, A) || A <- Adjustments],
|
||||
context = marshal(ctx, Context),
|
||||
metadata = marshal(ctx, ff_deposit:metadata(DepositState))
|
||||
metadata = marshal(ctx, ff_deposit:metadata(DepositState)),
|
||||
description = maybe_marshal(string, ff_deposit:description(DepositState))
|
||||
}.
|
||||
|
||||
%% API
|
||||
@ -78,7 +79,8 @@ marshal(deposit, Deposit) ->
|
||||
domain_revision = maybe_marshal(domain_revision, ff_deposit:domain_revision(Deposit)),
|
||||
party_revision = maybe_marshal(party_revision, ff_deposit:party_revision(Deposit)),
|
||||
created_at = maybe_marshal(timestamp_ms, ff_deposit:created_at(Deposit)),
|
||||
metadata = maybe_marshal(ctx, ff_deposit:metadata(Deposit))
|
||||
metadata = maybe_marshal(ctx, ff_deposit:metadata(Deposit)),
|
||||
description = maybe_marshal(string, ff_deposit:description(Deposit))
|
||||
};
|
||||
marshal(deposit_params, DepositParams) ->
|
||||
#deposit_DepositParams{
|
||||
@ -87,7 +89,8 @@ marshal(deposit_params, DepositParams) ->
|
||||
wallet_id = marshal(id, maps:get(wallet_id, DepositParams)),
|
||||
source_id = marshal(id, maps:get(source_id, DepositParams)),
|
||||
external_id = maybe_marshal(id, maps:get(external_id, DepositParams, undefined)),
|
||||
metadata = maybe_marshal(ctx, maps:get(metadata, DepositParams, undefined))
|
||||
metadata = maybe_marshal(ctx, maps:get(metadata, DepositParams, undefined)),
|
||||
description = maybe_marshal(string, maps:get(description, DepositParams, undefined))
|
||||
};
|
||||
marshal(ctx, Ctx) ->
|
||||
maybe_marshal(context, Ctx);
|
||||
@ -144,7 +147,8 @@ unmarshal(deposit, Deposit) ->
|
||||
party_revision => maybe_unmarshal(party_revision, Deposit#deposit_Deposit.party_revision),
|
||||
domain_revision => maybe_unmarshal(domain_revision, Deposit#deposit_Deposit.domain_revision),
|
||||
created_at => maybe_unmarshal(timestamp_ms, Deposit#deposit_Deposit.created_at),
|
||||
metadata => maybe_unmarshal(ctx, Deposit#deposit_Deposit.metadata)
|
||||
metadata => maybe_unmarshal(ctx, Deposit#deposit_Deposit.metadata),
|
||||
description => maybe_unmarshal(string, Deposit#deposit_Deposit.description)
|
||||
});
|
||||
unmarshal(deposit_params, DepositParams) ->
|
||||
genlib_map:compact(#{
|
||||
@ -153,7 +157,8 @@ unmarshal(deposit_params, DepositParams) ->
|
||||
wallet_id => unmarshal(id, DepositParams#deposit_DepositParams.wallet_id),
|
||||
source_id => unmarshal(id, DepositParams#deposit_DepositParams.source_id),
|
||||
metadata => maybe_unmarshal(ctx, DepositParams#deposit_DepositParams.metadata),
|
||||
external_id => maybe_unmarshal(id, DepositParams#deposit_DepositParams.external_id)
|
||||
external_id => maybe_unmarshal(id, DepositParams#deposit_DepositParams.external_id),
|
||||
description => maybe_unmarshal(string, DepositParams#deposit_DepositParams.description)
|
||||
});
|
||||
unmarshal(ctx, Ctx) ->
|
||||
maybe_unmarshal(context, Ctx);
|
||||
@ -201,6 +206,7 @@ deposit_symmetry_test() ->
|
||||
-spec deposit_params_symmetry_test() -> _.
|
||||
deposit_params_symmetry_test() ->
|
||||
Metadata = ff_entity_context_codec:marshal(#{<<"metadata">> => #{<<"some key">> => <<"some data">>}}),
|
||||
Description = <<"testDesc">>,
|
||||
Encoded = #deposit_DepositParams{
|
||||
body = #'fistful_base_Cash'{
|
||||
amount = 10101,
|
||||
@ -210,7 +216,8 @@ deposit_params_symmetry_test() ->
|
||||
wallet_id = genlib:unique(),
|
||||
external_id = undefined,
|
||||
id = genlib:unique(),
|
||||
metadata = Metadata
|
||||
metadata = Metadata,
|
||||
description = Description
|
||||
},
|
||||
?assertEqual(Encoded, marshal(deposit_params, unmarshal(deposit_params, Encoded))).
|
||||
|
||||
|
@ -215,13 +215,15 @@ create_ok_test(C) ->
|
||||
ExternalID = generate_id(),
|
||||
Context = #{<<"NS">> => #{generate_id() => generate_id()}},
|
||||
Metadata = ff_entity_context_codec:marshal(#{<<"metadata">> => #{<<"some key">> => <<"some data">>}}),
|
||||
Description = <<"testDesc">>,
|
||||
Params = #deposit_DepositParams{
|
||||
id = DepositID,
|
||||
body = Body,
|
||||
source_id = SourceID,
|
||||
wallet_id = WalletID,
|
||||
metadata = Metadata,
|
||||
external_id = ExternalID
|
||||
external_id = ExternalID,
|
||||
description = Description
|
||||
},
|
||||
{ok, DepositState} = call_deposit('Create', {Params, ff_entity_context_codec:marshal(Context)}),
|
||||
Expected = get_deposit(DepositID),
|
||||
@ -231,6 +233,7 @@ create_ok_test(C) ->
|
||||
?assertEqual(ExternalID, DepositState#deposit_DepositState.external_id),
|
||||
?assertEqual(Body, DepositState#deposit_DepositState.body),
|
||||
?assertEqual(Metadata, DepositState#deposit_DepositState.metadata),
|
||||
?assertEqual(Description, DepositState#deposit_DepositState.description),
|
||||
?assertEqual(
|
||||
ff_deposit:domain_revision(Expected),
|
||||
DepositState#deposit_DepositState.domain_revision
|
||||
|
@ -5,6 +5,7 @@
|
||||
-module(ff_deposit).
|
||||
|
||||
-type id() :: binary().
|
||||
-type description() :: binary().
|
||||
|
||||
-define(ACTUAL_FORMAT_VERSION, 3).
|
||||
|
||||
@ -23,7 +24,8 @@
|
||||
external_id => id(),
|
||||
limit_checks => [limit_check_details()],
|
||||
reverts => reverts_index(),
|
||||
adjustments => adjustments_index()
|
||||
adjustments => adjustments_index(),
|
||||
description => description()
|
||||
}.
|
||||
|
||||
-opaque deposit() :: #{
|
||||
@ -36,7 +38,8 @@
|
||||
domain_revision => domain_revision(),
|
||||
created_at => ff_time:timestamp_ms(),
|
||||
metadata => metadata(),
|
||||
external_id => id()
|
||||
external_id => id(),
|
||||
description => description()
|
||||
}.
|
||||
|
||||
-type params() :: #{
|
||||
@ -44,7 +47,8 @@
|
||||
body := ff_accounting:body(),
|
||||
source_id := ff_source:id(),
|
||||
wallet_id := ff_wallet:id(),
|
||||
external_id => external_id()
|
||||
external_id => external_id(),
|
||||
description => description()
|
||||
}.
|
||||
|
||||
-type status() ::
|
||||
@ -157,6 +161,7 @@
|
||||
-export([domain_revision/1]).
|
||||
-export([created_at/1]).
|
||||
-export([metadata/1]).
|
||||
-export([description/1]).
|
||||
|
||||
%% API
|
||||
-export([create/1]).
|
||||
@ -294,6 +299,10 @@ created_at(T) ->
|
||||
metadata(T) ->
|
||||
maps:get(metadata, T, undefined).
|
||||
|
||||
-spec description(deposit_state()) -> description() | undefined.
|
||||
description(Deposit) ->
|
||||
maps:get(description, Deposit, undefined).
|
||||
|
||||
%% API
|
||||
|
||||
-spec create(params()) ->
|
||||
@ -341,7 +350,8 @@ create(Params) ->
|
||||
domain_revision => DomainRevision,
|
||||
created_at => CreatedAt,
|
||||
external_id => maps:get(external_id, Params, undefined),
|
||||
metadata => maps:get(metadata, Params, undefined)
|
||||
metadata => maps:get(metadata, Params, undefined),
|
||||
description => maps:get(description, Params, undefined)
|
||||
})},
|
||||
{status_changed, pending}
|
||||
]
|
||||
|
@ -14,7 +14,7 @@
|
||||
{elvis_style, function_naming_convention, #{regex => "^[a-z]([a-z0-9]*_?)*$"}},
|
||||
{elvis_style, no_if_expression, disable},
|
||||
{elvis_style, state_record_and_type, disable},
|
||||
{elvis_style, god_modules, #{ignore => [ff_withdrawal]}},
|
||||
{elvis_style, god_modules, #{ignore => [ff_withdrawal, ff_deposit]}},
|
||||
%% Project settings
|
||||
% Verbose authorization code triggers this otherwise
|
||||
{elvis_style, dont_repeat_yourself, #{
|
||||
|
@ -41,7 +41,7 @@
|
||||
0},
|
||||
{<<"fistful_proto">>,
|
||||
{git,"https://github.com/valitydev/fistful-proto.git",
|
||||
{ref,"c9c3aa00f075ecf774c2befc57284aeffbeea1fe"}},
|
||||
{ref,"f2ca9b5225956a6bd9e1b3f84157f52c884fdb36"}},
|
||||
0},
|
||||
{<<"genlib">>,
|
||||
{git,"https://github.com/valitydev/genlib.git",
|
||||
|
Loading…
Reference in New Issue
Block a user