Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
duniter-gva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
modules
duniter-gva
Commits
3fbf29f7
Commit
3fbf29f7
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
feat(gql): add field aggregate.sum for query wallets
parent
fd2ecdee
No related branches found
No related tags found
No related merge requests found
Pipeline
#12691
passed
4 years ago
Stage: tests
Stage: quality
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
gql/src/entities.rs
+30
-0
30 additions, 0 deletions
gql/src/entities.rs
gql/src/queries/wallets.rs
+14
-2
14 additions, 2 deletions
gql/src/queries/wallets.rs
with
44 additions
and
2 deletions
gql/src/entities.rs
+
30
−
0
View file @
3fbf29f7
...
...
@@ -33,6 +33,31 @@ pub(crate) struct AmountWithBase {
pub
(
crate
)
amount
:
i32
,
pub
(
crate
)
base
:
i32
,
}
impl
AmountWithBase
{
fn
increment_base
(
self
)
->
Self
{
Self
{
amount
:
self
.amount
/
10
,
base
:
self
.base
+
1
,
}
}
}
impl
std
::
ops
::
Add
for
AmountWithBase
{
type
Output
=
Self
;
fn
add
(
self
,
rhs
:
Self
)
->
Self
::
Output
{
#[allow(clippy::comparison_chain)]
if
self
.base
==
rhs
.base
{
Self
{
amount
:
self
.amount
+
rhs
.amount
,
base
:
self
.base
,
}
}
else
if
self
.base
>
rhs
.base
{
self
.add
(
rhs
.increment_base
())
}
else
{
self
.increment_base
()
.add
(
rhs
)
}
}
}
impl
From
<
SourceAmount
>
for
AmountWithBase
{
fn
from
(
sa
:
SourceAmount
)
->
Self
{
Self
{
...
...
@@ -41,6 +66,11 @@ impl From<SourceAmount> for AmountWithBase {
}
}
}
impl
std
::
iter
::
Sum
for
AmountWithBase
{
fn
sum
<
I
:
Iterator
<
Item
=
Self
>>
(
iter
:
I
)
->
Self
{
iter
.fold
(
AmountWithBase
::
default
(),
std
::
ops
::
Add
::
add
)
}
}
#[derive(async_graphql::SimpleObject)]
pub
(
crate
)
struct
EdgeTx
{
...
...
This diff is collapsed.
Click to expand it.
gql/src/queries/wallets.rs
+
14
−
2
View file @
3fbf29f7
...
...
@@ -32,7 +32,7 @@ impl WalletsQuery {
#[graphql(desc
=
"minimal balance"
)]
min_balance
:
Option
<
i64
>
,
#[graphql(desc
=
"pagination"
,
default)]
pagination
:
Pagination
,
#[graphql(desc
=
"Wallet type filter"
,
default)]
wallet_type_filter
:
WalletTypeFilter
,
)
->
async_graphql
::
Result
<
Connection
<
String
,
Wallet
,
EmptyFields
,
EmptyFields
>>
{
)
->
async_graphql
::
Result
<
Connection
<
String
,
Wallet
,
AggregateSum
,
EmptyFields
>>
{
let
QueryContext
{
is_whitelisted
}
=
ctx
.data
::
<
QueryContext
>
()
?
;
let
data
=
ctx
.data
::
<
GvaSchemaData
>
()
?
;
...
...
@@ -160,7 +160,19 @@ impl WalletsQuery {
}
};
let
mut
conn
=
Connection
::
new
(
has_previous_page
,
has_next_page
);
let
sum
=
if
ctx
.look_ahead
()
.field
(
"aggregate"
)
.field
(
"sum"
)
.exists
()
{
data
.iter
()
.map
(|
wallet
|
wallet
.balance
)
.sum
()
}
else
{
AmountWithBase
::
default
()
};
let
mut
conn
=
Connection
::
with_additional_fields
(
has_previous_page
,
has_next_page
,
AggregateSum
{
aggregate
:
Sum
{
sum
},
},
);
conn
.append
(
data
.into_iter
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment