added dividend db table and insert by trade

This commit is contained in:
samantha42
2026-04-06 07:36:45 +02:00
parent 31108a16d0
commit 57ae3cfb06
7 changed files with 120 additions and 48 deletions

View File

@@ -25,14 +25,7 @@ func GetTrades(db *sql.DB) ([]model.Trade, error) {
return nil, err
}
switch typeInt {
case 0:
t.Type = model.TradeType(false)
case 1:
t.Type = model.TradeType(true)
default:
return nil, fmt.Errorf("failed to convert given Type int to bool of trade type.")
}
t.Type = model.TradeType(typeInt)
trades = append(trades, t)
}
@@ -81,6 +74,21 @@ func InsertTrade(db *sql.DB, trade model.Trade) error {
return err
}
func InsertDividend(db *sql.DB, div model.Dividend) error {
_, err := db.Exec(
"INSERT INTO trades (symbol, currency_code, shares, product, value, tax_amount, tax_rate, net_value, payment_date) VALUES (?, ?, ?, ?, ?, ?, ?)",
div.Symbol,
div.CurrencyCode,
div.Product,
div.Value,
div.TaxAmount,
div.TaxRate,
div.NetValue,
div.PaymentDate,
)
return err
}
func UpdatePositions(db *sql.DB, positions []model.Position) error {
// Complete overwrite of the db positions
_, err := db.Exec("DELETE FROM position")