all repos — piggy @ bbb48c59b31feefe1c469fb20c41527184610062

Dead simple finance manager in Go, HTML and JS.

update exchange detection logic
Marco Andronaco andronacomarco@gmail.com
Sun, 06 Oct 2024 14:33:42 +0200
commit

bbb48c59b31feefe1c469fb20c41527184610062

parent

d8748d219af2eb8f80b1589a04f72614d5638b86

3 files changed, 3 insertions(+), 14 deletions(-)

jump to
M src/app/init.gosrc/app/init.go

@@ -43,11 +43,6 @@ }

if bookmakersAmount == 0 { InsertSampleData() } - - err = DB.Model(&Bookmaker{}).Where("default_commission > 0").Pluck("id", &ExchangeIDs).Error - if err != nil { - log.Println("could not get exchange ids: " + err.Error()) - } } func InsertSampleData() {
M src/app/records.gosrc/app/records.go

@@ -43,7 +43,7 @@ if e.Won == nil || e.Odds == nil {

log.Fatalf("please, update e.Won and e.Odds first") } - if IsExchange(e.BookmakerID) { + if e.Bookmaker.IsExchange() { r := (int(e.Amount) * (int(*e.Odds) - 100)) / 100 if *e.Won { value = int(e.Amount) - int(e.Amount)*int(e.Commission)/10000
M src/app/utils.gosrc/app/utils.go

@@ -1,7 +1,5 @@

package app -var ExchangeIDs []uint - func IndexOf[T comparable](slice []T, element T) int { for i, el := range slice { if el == element {

@@ -11,10 +9,6 @@ }

return -1 } -func Contains[T comparable](slice []T, element T) bool { - return IndexOf(slice, element) != -1 -} - -func IsExchange(bookmakerID uint) bool { - return Contains(ExchangeIDs, bookmakerID) +func (b Bookmaker) IsExchange() bool { + return b.DefaultCommission != 0 }