new model and endpoints..

This commit is contained in:
samantha42
2026-03-28 08:33:12 +01:00
parent c2276b6e13
commit 31108a16d0
3 changed files with 61 additions and 1 deletions

View File

@@ -69,6 +69,29 @@ func InitDB(db *sql.DB) {
UNIQUE(company_id, name) UNIQUE(company_id, name)
); );
-- parent table
CREATE TABLE closed_positions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
currency_code TEXT NOT NULL,
product TEXT NOT NULL,
open_time DATETIME NOT NULL,
realized_gain REAL,
tax_amount REAL,
holding_days INTEGER
);
-- child table, one row per close lot
CREATE TABLE close_entries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
closed_position_id INTEGER NOT NULL REFERENCES closed_positions(id),
shares INTEGER NOT NULL,
in_price REAL NOT NULL,
out_price REAL NOT NULL,
gain_price REAL NOT NULL,
close_time DATETIME NOT NULL
);
CREATE TABLE IF NOT EXISTS revenue_entries ( CREATE TABLE IF NOT EXISTS revenue_entries (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
company_id INTEGER NOT NULL, company_id INTEGER NOT NULL,

View File

@@ -5,6 +5,36 @@ import (
"time" "time"
) )
type Dividend struct {
Symbol string
CurrencyCode string
Product TradeProduct
Value float64
PaymentDate time.Time
TaxAmount float64
TaxRate float64
NetValue float64
}
type CloseEntry struct {
Shares int
InPrice float64
OutPrice float64
GainPrice float64
CloseTime time.Time
}
type ClosedPosition struct {
Symbol string
CurrencyCode string
Product TradeProduct
Closes []CloseEntry // each close carries its own prices + share count
OpenTime time.Time
RealizedGain float64
TaxAmount float64
HoldingDays int
}
type Position struct { type Position struct {
CompanyID int CompanyID int
Symbol string Symbol string
@@ -81,4 +111,6 @@ func (r *AddTradeRequest) Validate() error {
type Portifolio struct { type Portifolio struct {
Positions []Position Positions []Position
Trades []Trade Trades []Trade
closed []ClosedPosition
Dividends []Dividend
} }

View File

@@ -50,12 +50,17 @@ func main() {
//Trades //Trades
mux.HandleFunc("POST /trade/add", handlers.AddTradeHandler(db)) mux.HandleFunc("POST /trade/add", handlers.AddTradeHandler(db))
mux.HandleFunc("GET /trade/list", handlers.GetTradeListHandler(db)) mux.HandleFunc("GET /trade/list", handlers.GetTradeListHandler(db))
mux.HandleFunc("GET /trade/search", handlers.GetTradeListHandler(db)) // new
//Positions
mux.HandleFunc("GET /positions/list", handlers.GetPositionListHandler(db)) mux.HandleFunc("GET /positions/list", handlers.GetPositionListHandler(db))
mux.HandleFunc("GET /positions/closed/list", handlers.GetPositionListHandler(db)) // new
mux.HandleFunc("GET /positions/closed/search", handlers.GetTradeListHandler(db)) // new
// Company // Company
mux.HandleFunc("POST /company/add", handlers.AddCompanyHandler(db)) mux.HandleFunc("POST /company/add", handlers.AddCompanyHandler(db))
mux.HandleFunc("GET /company/list", handlers.GetCompaniesHandler(db)) mux.HandleFunc("GET /company/list", handlers.GetCompaniesHandler(db))
mux.HandleFunc("GET /company/revenue/categories", handlers.GetCompanyRevenueCategories(db)) mux.HandleFunc("GET /company/revenue/categories", handlers.GetCompanyRevenueCategories(db))
mux.HandleFunc("POST /company/S-O/add", handlers.GetCompaniesHandler(db)) // new
mux.HandleFunc("GET /company/S-O/list", handlers.GetCompaniesHandler(db)) // new
// Currency // Currency
mux.HandleFunc("GET /currency/list", handlers.GetCurrenciesHandler(db)) mux.HandleFunc("GET /currency/list", handlers.GetCurrenciesHandler(db))