first commit

This commit is contained in:
Matthias Hinrichs
2025-07-05 03:10:41 +02:00
commit 9b7bdcbc53
39 changed files with 5109 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package model
import (
"time"
"gorm.io/gorm"
)
type ActivityType string
const (
Buy ActivityType = "BUY"
Sell ActivityType = "SELL"
Dividend ActivityType = "DIVIDEND"
Fee ActivityType = "FEE"
Tax ActivityType = "TAX"
)
type Activity struct {
ID uint `gorm:"primaryKey" json:"id"`
PortfolioID uint `gorm:"not null;index" json:"portfolio_id"` // Referenz auf Portfolio
Stock string `gorm:"not null;size:20" json:"stock"` // Symbol oder ISIN
Type ActivityType `gorm:"not null;size:20" json:"type"` // BUY, SELL, DIVIDEND, FEE, TAX
Amount float64 `gorm:"not null" json:"amount"` // Stückzahl oder Betrag
Price float64 `gorm:"default:0" json:"price"` // Preis pro Stück (bei BUY/SELL), sonst 0
ConvertedPrice float64 `gorm:"default:0" json:"converted_price"` // Preis pro Stück (bei BUY/SELL), sonst 0
Fee float64 `gorm:"default:0" json:"fee"` // Gebühr (bei BUY/SELL), sonst 0
Taxes float64 `gorm:"default:0" json:"taxes"` // Steuern (bei BUY/SELL), sonst 0
Currency string `gorm:"not null;size:3;default:'EUR'" json:"currency"` // Währung (z.B. EUR, USD)
Date time.Time `gorm:"not null" json:"date"` // Datum der Aktivität
Note string `gorm:"type:text" json:"note"` // Optional: Notiz
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
// Relationships
Portfolio Portfolio `gorm:"foreignKey:PortfolioID" json:"portfolio,omitempty"`
}
+44
View File
@@ -0,0 +1,44 @@
package model
type StockMeta struct {
Symbol string `json:"symbol"`
RegularMarketPrice float64 `json:"regularMarketPrice"`
Exchange string `json:"exchangeName"`
Currency string `json:"currency"`
Instrument string `json:"instrumentType"`
FirstTrade int64 `json:"firstTradeDate"`
GMTOffset int64 `json:"gmtoffset"`
Timezone string `json:"exchangeTimezoneName"`
ShortName string `json:"shortName"`
LongName string `json:"longName"`
}
// Struct to represent a single dividend event
type DividendEvent struct {
Amount float64 `json:"amount"`
Date int64 `json:"date"`
}
// Struct to represent the events object, specifically dividends
type Events struct {
Dividends map[string]DividendEvent `json:"dividends"`
}
// Struct for the Yahoo Chart Response containing events (like dividends)
type YahooDividendChartResponse struct {
Chart struct {
Result []struct {
Events Events `json:"events"`
} `json:"result"`
} `json:"chart"`
}
// Existing struct for general Yahoo Chart Response
type YahooChartResponse struct {
Chart struct {
Result []struct {
Meta StockMeta `json:"meta"`
// ... weitere Felder wie Timestamp, Indicators etc.
} `json:"result"`
} `json:"chart"`
}
+22
View File
@@ -0,0 +1,22 @@
package model
import (
"time"
"gorm.io/gorm"
)
type Portfolio struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"not null;index" json:"user_id"` // Referenz auf User
Name string `gorm:"not null;size:255" json:"name"` // Name des Portfolios
BaseCurrency string `gorm:"not null;size:3" json:"base_currency"` // Basiswährung, z.B. "EUR"
Description string `gorm:"type:text" json:"description"` // Beschreibung des Portfolios
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
// Relationships
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
Activities []Activity `gorm:"foreignKey:PortfolioID" json:"activities,omitempty"`
}
+20
View File
@@ -0,0 +1,20 @@
package model
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"uniqueIndex;not null;size:255" json:"username"`
Email string `gorm:"uniqueIndex;not null;size:255" json:"email"`
Password string `gorm:"not null" json:"password"` // Hash speichern, nicht das Klartext-Passwort!
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
// Relationships
Portfolios []Portfolio `gorm:"foreignKey:UserID" json:"portfolios,omitempty"`
}