Add total to StatsTypeCurrencyChart
This commit is contained in:
parent
66dfdada06
commit
eeaec565bd
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
||||||
|
"git.qowevisa.me/Qowevisa/fin-check-api/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,14 +86,20 @@ func StatisticsGetAllSpendingsForTypes(c *gin.Context) {
|
||||||
typeToValue[expense.TypeID] = val
|
typeToValue[expense.TypeID] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var sum uint64 = 0
|
||||||
var elements []types.StatsType
|
var elements []types.StatsType
|
||||||
for _, val := range typeToValue {
|
for _, val := range typeToValue {
|
||||||
elements = append(elements, val)
|
elements = append(elements, val)
|
||||||
|
sum += val.Value
|
||||||
}
|
}
|
||||||
|
slices.SortFunc(elements, func(a, b types.StatsType) int {
|
||||||
|
return utils.DescendingSort(a.Value, b.Value)
|
||||||
|
})
|
||||||
|
|
||||||
ret = append(ret, types.StatsTypeCurrencyChart{
|
ret = append(ret, types.StatsTypeCurrencyChart{
|
||||||
CurrencyLabel: fmt.Sprintf("%s (%s)", currency.Symbol, currency.ISOName),
|
CurrencyLabel: fmt.Sprintf("%s (%s)", currency.Symbol, currency.ISOName),
|
||||||
Elements: elements,
|
Elements: elements,
|
||||||
|
Total: sum,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
c.JSON(200, ret)
|
c.JSON(200, ret)
|
||||||
|
|
|
@ -196,6 +196,7 @@ type StatsType struct {
|
||||||
type StatsTypeCurrencyChart struct {
|
type StatsTypeCurrencyChart struct {
|
||||||
CurrencyLabel string `json:"label" example:"$ (USD)"`
|
CurrencyLabel string `json:"label" example:"$ (USD)"`
|
||||||
Elements []StatsType `json:"elements"`
|
Elements []StatsType `json:"elements"`
|
||||||
|
Total uint64 `json:"total" example:"120050"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// {{{ Settings section
|
// {{{ Settings section
|
||||||
|
|
Loading…
Reference in New Issue
Block a user