aboutsummaryrefslogtreecommitdiff
path: root/api/admin.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/admin.go')
-rw-r--r--api/admin.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/api/admin.go b/api/admin.go
index 3b16d87..e4bfda5 100644
--- a/api/admin.go
+++ b/api/admin.go
@@ -4,13 +4,18 @@ import (
4 "fmt" 4 "fmt"
5 5
6 "git.immae.eu/Cryptoportfolio/Front.git/db" 6 "git.immae.eu/Cryptoportfolio/Front.git/db"
7 "github.com/shopspring/decimal"
7) 8)
8 9
9type GetAllPortfoliosQuery struct { 10type GetAllPortfoliosQuery struct {
10 In struct { 11 In struct {
11 Market string 12 Market string
12 } 13 }
13 Out map[string]Portfolio 14 Out struct {
15 Portfolios map[string]Portfolio `json:"portfolios"`
16 TotalBTCValue decimal.Decimal `json:"totalBtcValue"`
17 TotalBTCVariation decimal.Decimal `json:"totalBtcVariation"`
18 }
14} 19}
15 20
16func (q GetAllPortfoliosQuery) ValidateParams() *Error { 21func (q GetAllPortfoliosQuery) ValidateParams() *Error {
@@ -27,7 +32,7 @@ func (q GetAllPortfoliosQuery) Run() (interface{}, *Error) {
27 return nil, NewInternalError(err) 32 return nil, NewInternalError(err)
28 } 33 }
29 34
30 q.Out = make(map[string]Portfolio) 35 q.Out.Portfolios = make(map[string]Portfolio)
31 36
32 for _, marketConfig := range u { 37 for _, marketConfig := range u {
33 report, err := GetWeekPortfolio(marketConfig) 38 report, err := GetWeekPortfolio(marketConfig)
@@ -39,8 +44,13 @@ func (q GetAllPortfoliosQuery) Run() (interface{}, *Error) {
39 return nil, NewInternalError(err) 44 return nil, NewInternalError(err)
40 } 45 }
41 46
42 q.Out[marketConfig.User.Email] = report.Round() 47 q.Out.Portfolios[marketConfig.User.Email] = report.Round()
48 q.Out.TotalBTCValue = q.Out.TotalBTCValue.Add(report.Performance.Value)
49 q.Out.TotalBTCVariation = q.Out.TotalBTCVariation.Add(report.Performance.Variation)
43 } 50 }
44 51
52 q.Out.TotalBTCValue = q.Out.TotalBTCValue.Round(3)
53 q.Out.TotalBTCVariation = q.Out.TotalBTCVariation.Round(3)
54
45 return q.Out, nil 55 return q.Out, nil
46} 56}