diff --git a/handlers/statistics.go b/handlers/statistics.go index 3bbd634..c9ec730 100644 --- a/handlers/statistics.go +++ b/handlers/statistics.go @@ -7,6 +7,7 @@ import ( "git.qowevisa.me/Qowevisa/fin-check-api/db" "git.qowevisa.me/Qowevisa/fin-check-api/types" + "git.qowevisa.me/Qowevisa/fin-check-api/utils" "github.com/gin-gonic/gin" ) @@ -85,14 +86,20 @@ func StatisticsGetAllSpendingsForTypes(c *gin.Context) { typeToValue[expense.TypeID] = val } } + var sum uint64 = 0 var elements []types.StatsType for _, val := range typeToValue { 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{ CurrencyLabel: fmt.Sprintf("%s (%s)", currency.Symbol, currency.ISOName), Elements: elements, + Total: sum, }) } c.JSON(200, ret) diff --git a/types/types.go b/types/types.go index 1459905..f9e2c9b 100644 --- a/types/types.go +++ b/types/types.go @@ -196,6 +196,7 @@ type StatsType struct { type StatsTypeCurrencyChart struct { CurrencyLabel string `json:"label" example:"$ (USD)"` Elements []StatsType `json:"elements"` + Total uint64 `json:"total" example:"120050"` } // {{{ Settings section