Skip to content

Commit

Permalink
fix: entry float32 truncate error
Browse files Browse the repository at this point in the history
  • Loading branch information
noobj committed Sep 25, 2023
1 parent 55e7fc4 commit 9cf1d38
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
12 changes: 6 additions & 6 deletions cmd/ahorro/fetchentries/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ type Response events.APIGatewayProxyResponse

type Entry struct {
Id primitive.ObjectID `json:"_id" bson:"_id"`
Amount float32 `json:"amount" bson:"amount"`
Amount float64 `json:"amount" bson:"amount"`
Date string `json:"date"`
Descr string `json:"descr"`
}

type AggregateResult struct {
Entries []Entry
Sum float32
Sum float64
Category []EntryRepository.Category
}

type CategoryEntriesBundle struct {
Id primitive.ObjectID `json:"_id" bson:"_id"`
Sum float32 `json:"sum"`
Sum float64 `json:"sum"`
Percentage string `json:"percentage"`
Name string `json:"name"`
Entries []Entry `json:"entries"`
Expand Down Expand Up @@ -132,7 +132,7 @@ func (this Invoker) Invoke(ctx context.Context, request events.APIGatewayV2HTTPR

repoResults := this.entryRepository.Aggregate([]bson.D{matchStage, sortStage, groupStage, sortSumStage, lookupStage})
var categories []CategoryEntriesBundle
total := float32(0.0)
total := float64(0.0)
for _, repoResult := range repoResults {
fmt.Printf("%+v", repoResult)
doc, _ := bson.Marshal(repoResult)
Expand All @@ -156,13 +156,13 @@ func (this Invoker) Invoke(ctx context.Context, request events.APIGatewayV2HTTPR
}

for key, category := range categories {
percentage := float32(category.Sum) / float32(total)
percentage := float64(category.Sum) / float64(total)
categories[key].Percentage = fmt.Sprintf("%.2f", percentage)
}

resultForReturn := struct {
Categories []CategoryEntriesBundle `json:"categories"`
Total float32 `json:"total"`
Total float64 `json:"total"`
}{
Categories: categories,
Total: total,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/mock v1.6.0
github.com/golobby/container/v3 v3.3.1
github.com/google/uuid v1.3.0
github.com/joho/godotenv v1.4.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/mitchellh/mapstructure v1.5.0
Expand All @@ -21,7 +22,6 @@ require (

require (
cloud.google.com/go/compute v1.7.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
github.com/kr/pretty v0.2.1 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ github.com/antchfx/xmlquery v1.3.11/go.mod h1:ywPcYkN0GvURUxXpUujaMVvuLSOYQBzoSf
github.com/antchfx/xpath v1.2.1 h1:qhp4EW6aCOVr5XIkT+l6LJ9ck/JsUH/yyauNgTQkBF8=
github.com/antchfx/xpath v1.2.1/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/aws/aws-lambda-go v1.34.1 h1:M3a/uFYBjii+tDcOJ0wL/WyFi2550FHoECdPf27zvOs=
github.com/aws/aws-lambda-go v1.34.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
github.com/aws/aws-lambda-go v1.37.0 h1:WXkQ/xhIcXZZ2P5ZBEw+bbAKeCEcb5NtiYpSwVVzIXg=
github.com/aws/aws-lambda-go v1.37.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
github.com/aws/aws-sdk-go v1.44.79 h1:IZCtfBq9VlJ1Eu34I+2Y76q+XkvTtZYbEwaoVM1gzoA=
Expand Down Expand Up @@ -154,8 +152,6 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golobby/container/v3 v3.2.1 h1:waIB8d4nSDwMaO7PvM6H+OCqAFEWyMuSPNN4Fwpv0Ok=
github.com/golobby/container/v3 v3.2.1/go.mod h1:RDdKpnKpV1Of11PFBe7Dxc2C1k2KaLE4FD47FflAmj0=
github.com/golobby/container/v3 v3.3.1 h1:Y+QpwChmkz86tAKimvqc0qls8A4eYm/PhMqSEt/HTj4=
github.com/golobby/container/v3 v3.3.1/go.mod h1:RDdKpnKpV1Of11PFBe7Dxc2C1k2KaLE4FD47FflAmj0=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand Down Expand Up @@ -239,10 +235,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/noobj/jwtmiddleware v1.0.2 h1:h30phLAskmcpxBz/sd01qonIfF1Pu5pd1EhAm8JXsVs=
github.com/noobj/jwtmiddleware v1.0.2/go.mod h1:KBR615o5jFZPvzWFs7bQ9ZS/69bo+uJCkI+k0yuQLTg=
github.com/noobj/jwtmiddleware v1.0.3 h1:kfJNDI22T6CCVoALFvMJi2iHBngSKOSAclrMs0mBvrc=
github.com/noobj/jwtmiddleware v1.0.3/go.mod h1:KBR615o5jFZPvzWFs7bQ9ZS/69bo+uJCkI+k0yuQLTg=
github.com/noobj/jwtmiddleware v1.0.4 h1:QWfjMw7d+CaBc14vthC7duzdEeLvq7cwZH133YCLw7I=
github.com/noobj/jwtmiddleware v1.0.4/go.mod h1:KBR615o5jFZPvzWFs7bQ9ZS/69bo+uJCkI+k0yuQLTg=
github.com/onsi/ginkgo/v2 v2.2.0 h1:3ZNA3L1c5FYDFTTxbFeVGGD8jYvjYauHD30YgLxVsNI=
Expand Down
2 changes: 1 addition & 1 deletion internal/repositories/ahorro/entry/entry_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type Entry struct {
Id primitive.ObjectID `json:"_id" bson:"_id"`
Amount float32 `json:"amount" bson:"amount"`
Amount float64 `json:"amount" bson:"amount"`
Date string `json:"date"`
Descr string `json:"descr"`
Category primitive.ObjectID `json:"category,omitempty" bson:"category,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "To run the golang lambda service locally",
"version": "1.0.0",
"scripts": {
"start": "SLS_DEBUG=* node ./node_modules/.bin/serverless offline --host 0.0.0.0 start --useDocker",
"start": "SLS_DEBUG=* node ./node_modules/.bin/serverless offline --host 0.0.0.0 --httpsProtocol ./ssl start --useDocker",
"watch": "nodemon --watch ./ -e go --exec make build -j",
"watch_swim": "nodemon --watch ./ -e go --exec make swimbuild",
"test": "ginkgo ./..."
Expand Down

0 comments on commit 9cf1d38

Please sign in to comment.