first commit
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/util"
|
||||
)
|
||||
|
||||
func JsonEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
stock := r.URL.Query().Get("stock")
|
||||
|
||||
// Standardwerte setzen, falls Parameter fehlen
|
||||
if stock == "" {
|
||||
stock = "IDIA.SW"
|
||||
}
|
||||
|
||||
data, err := util.FetchYahooFinanceData(stock)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(data))
|
||||
}
|
||||
|
||||
func YahooMaxDividendsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
stock := r.URL.Query().Get("stock")
|
||||
if stock == "" {
|
||||
http.Error(w, "Fehlender stock-Parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := util.FetchYahooFinanceDataMax(stock)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var resp model.YahooDividendChartResponse
|
||||
err = json.Unmarshal([]byte(data), &resp)
|
||||
if err != nil {
|
||||
http.Error(w, "Fehler beim Parsen der Yahoo-Dividenden-Daten: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var result [][]interface{}
|
||||
if len(resp.Chart.Result) > 0 {
|
||||
for _, div := range resp.Chart.Result[0].Events.Dividends {
|
||||
result = append(result, []interface{}{div.Date * 1000, div.Amount})
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
func StockSearchEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query().Get("q")
|
||||
if query == "" {
|
||||
http.Error(w, "Fehlender q-Parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := util.StockSearch(query)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(data))
|
||||
}
|
||||
|
||||
// Helper function to get stock currency from Yahoo Finance
|
||||
func getStockCurrency(stock string) (string, error) {
|
||||
// Fetch basic stock data from Yahoo Finance
|
||||
data, err := util.FetchYahooFinanceData(stock)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Parse the JSON response
|
||||
var resp model.YahooChartResponse
|
||||
err = json.Unmarshal([]byte(data), &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Extract currency from the response
|
||||
if len(resp.Chart.Result) > 0 {
|
||||
currency := resp.Chart.Result[0].Meta.Currency
|
||||
if currency != "" {
|
||||
return currency, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("currency not found in response")
|
||||
}
|
||||
|
||||
// ClearCurrencyCacheHandler clears the currency conversion cache
|
||||
func ClearCurrencyCacheHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
util.ClearCache()
|
||||
|
||||
response := map[string]string{
|
||||
"status": "success",
|
||||
"message": "Currency cache cleared successfully",
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
// CurrencyCacheInfoHandler returns information about the currency cache
|
||||
func CurrencyCacheInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Nur GET erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
cacheInfo := util.GetCacheInfo()
|
||||
|
||||
response := map[string]interface{}{
|
||||
"status": "success",
|
||||
"cache_size": len(cacheInfo),
|
||||
"entries": cacheInfo,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"portfolio-tracker/internal/model" // Add this import
|
||||
"portfolio-tracker/internal/session"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func RegisterHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
username := r.FormValue("username")
|
||||
email := r.FormValue("email")
|
||||
password := r.FormValue("password")
|
||||
|
||||
if username == "" || email == "" || password == "" {
|
||||
http.Error(w, "Alle Felder sind erforderlich", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Passwort hashen
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
http.Error(w, "Fehler beim Hashen des Passworts", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
user := model.User{
|
||||
Username: username,
|
||||
Email: email,
|
||||
Password: string(hash),
|
||||
}
|
||||
|
||||
if err := DB.Create(&user).Error; err != nil {
|
||||
http.Error(w, "Fehler beim Speichern des Users: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
username := r.FormValue("username")
|
||||
password := r.FormValue("password")
|
||||
|
||||
if username == "" || password == "" {
|
||||
http.Error(w, "Alle Felder sind erforderlich", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var user model.User
|
||||
if err := DB.Where("username = ?", username).First(&user).Error; err != nil {
|
||||
http.Error(w, "Benutzer nicht gefunden", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// Passwort prüfen
|
||||
if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)); err != nil {
|
||||
http.Error(w, "Falsches Passwort", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// Session erstellen oder abrufen
|
||||
session, err := session.Store.Get(r, "hnrx_pft_session")
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting session: %v\n", err)
|
||||
http.Error(w, "Session-Fehler", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Session-Werte setzen
|
||||
session.Values["authenticated"] = true
|
||||
session.Values["username"] = username
|
||||
|
||||
// Debug output
|
||||
fmt.Printf("Setting session values - Auth: %v, Username: %s\n", true, username)
|
||||
fmt.Printf("Session ID before save: %s\n", session.ID)
|
||||
|
||||
// Session speichern
|
||||
err = session.Save(r, w)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving session: %v\n", err)
|
||||
http.Error(w, "Fehler beim Speichern der Session", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Session saved successfully with ID: %s\n", session.ID)
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func LogoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := session.Store.Get(r, "hnrx_pft_session")
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting session in logout: %v\n", err)
|
||||
// Continue with logout even if session retrieval fails
|
||||
}
|
||||
|
||||
// Clear session values
|
||||
session.Values["authenticated"] = false
|
||||
session.Values["username"] = ""
|
||||
|
||||
// Set session options to delete the session
|
||||
session.Options.MaxAge = -1
|
||||
|
||||
// Save the session (this will delete it due to MaxAge = -1)
|
||||
err = session.Save(r, w)
|
||||
if err != nil {
|
||||
fmt.Printf("Error saving session during logout: %v\n", err)
|
||||
http.Error(w, "Fehler beim Logout", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Session successfully logged out\n")
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Global database instance
|
||||
var DB *gorm.DB
|
||||
@@ -0,0 +1,98 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/session"
|
||||
"portfolio-tracker/internal/util"
|
||||
"portfolio-tracker/internal/web/templates"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
// Helper function to get session info
|
||||
func getSessionInfo(r *http.Request) (bool, string, error) {
|
||||
session, err := session.Store.Get(r, "hnrx_pft_session")
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
|
||||
auth, ok := session.Values["authenticated"].(bool)
|
||||
if !ok {
|
||||
auth = false
|
||||
}
|
||||
|
||||
username, ok := session.Values["username"].(string)
|
||||
if !ok {
|
||||
username = ""
|
||||
}
|
||||
|
||||
return auth, username, nil
|
||||
}
|
||||
|
||||
// Helper function to get portfolios for a user
|
||||
func getUserPortfolios(username string) []model.Portfolio {
|
||||
var portfolios []model.Portfolio
|
||||
if username != "" {
|
||||
// Get user first
|
||||
var user model.User
|
||||
if err := DB.Where("username = ?", username).First(&user).Error; err != nil {
|
||||
fmt.Printf("Error getting user: %v\n", err)
|
||||
return portfolios
|
||||
}
|
||||
|
||||
// Get user's portfolios
|
||||
if err := DB.Where("user_id = ?", user.ID).Find(&portfolios).Error; err != nil {
|
||||
fmt.Printf("Error getting portfolios: %v\n", err)
|
||||
}
|
||||
}
|
||||
return portfolios
|
||||
}
|
||||
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error: %v\n", err)
|
||||
}
|
||||
|
||||
portfolios := getUserPortfolios(username)
|
||||
|
||||
// Debug output
|
||||
fmt.Printf("Session values - Auth: %v, Username: %s\n", auth, username)
|
||||
|
||||
component := templates.Result(auth, username, portfolios)
|
||||
templ.Handler(component).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func DetailsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error in DetailsHandler: %v\n", err)
|
||||
}
|
||||
|
||||
portfolios := getUserPortfolios(username)
|
||||
|
||||
stock := r.URL.Query().Get("stock")
|
||||
if stock == "" {
|
||||
http.Error(w, "Fehlender stock-Parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := util.FetchYahooFinanceData(stock)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var resp model.YahooChartResponse
|
||||
err = json.Unmarshal([]byte(data), &resp)
|
||||
if err != nil {
|
||||
http.Error(w, "Fehler beim Parsen der Daten: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
templates.StockDetails(auth, username, stock, resp, portfolios).Render(r.Context(), w)
|
||||
}
|
||||
@@ -0,0 +1,413 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/web/templates"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
func PortfolioHandler(w http.ResponseWriter, r *http.Request) {
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error in PortfolioHandler: %v\n", err)
|
||||
}
|
||||
|
||||
portfolios := getUserPortfolios(username)
|
||||
|
||||
component := templates.Portfolio(auth, username, portfolios)
|
||||
templ.Handler(component).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func PortfolioDetailHandler(w http.ResponseWriter, r *http.Request) {
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error in PortfolioDetailHandler: %v\n", err)
|
||||
}
|
||||
|
||||
// Extract portfolio ID from URL path
|
||||
path := r.URL.Path
|
||||
portfolioIDStr := strings.TrimPrefix(path, "/portfolio/")
|
||||
portfolioID, err := strconv.ParseUint(portfolioIDStr, 10, 32)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültige Portfolio-ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get user
|
||||
var user model.User
|
||||
if err := DB.Where("username = ?", username).First(&user).Error; err != nil {
|
||||
http.Error(w, "Benutzer nicht gefunden", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// Get portfolio with activities
|
||||
var portfolio model.Portfolio
|
||||
if err := DB.Preload("Activities").Where("id = ? AND user_id = ?", portfolioID, user.ID).First(&portfolio).Error; err != nil {
|
||||
http.Error(w, "Portfolio nicht gefunden oder keine Berechtigung", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
// Get all user portfolios for navigation
|
||||
portfolios := getUserPortfolios(username)
|
||||
|
||||
component := templates.PortfolioDetail(auth, username, portfolio, portfolios)
|
||||
templ.Handler(component).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func CreatePortfolioHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error in CreatePortfolioHandler: %v\n", err)
|
||||
}
|
||||
|
||||
if !auth {
|
||||
http.Error(w, "Nicht angemeldet", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if username == "" {
|
||||
http.Error(w, "Benutzer nicht gefunden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get form values
|
||||
name := r.FormValue("name")
|
||||
baseCurrency := r.FormValue("base_currency")
|
||||
description := r.FormValue("description")
|
||||
|
||||
// Basic validation
|
||||
if name == "" || baseCurrency == "" {
|
||||
http.Error(w, "Name und Basiswährung sind erforderlich", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get user from database
|
||||
var user model.User
|
||||
if err := DB.Where("username = ?", username).First(&user).Error; err != nil {
|
||||
http.Error(w, "Benutzer nicht gefunden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Create new portfolio
|
||||
portfolio := model.Portfolio{
|
||||
UserID: user.ID,
|
||||
Name: name,
|
||||
BaseCurrency: baseCurrency,
|
||||
Description: description,
|
||||
}
|
||||
|
||||
if err := DB.Create(&portfolio).Error; err != nil {
|
||||
fmt.Printf("Error creating portfolio: %v\n", err)
|
||||
http.Error(w, "Fehler beim Erstellen des Portfolios", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Portfolio created successfully: ID=%d, Name=%s, User=%s\n", portfolio.ID, portfolio.Name, username)
|
||||
|
||||
// Redirect to the new portfolio
|
||||
http.Redirect(w, r, fmt.Sprintf("/portfolio/%d", portfolio.ID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func PortfolioTransactionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error in PortfolioTransactionHandler: %v\n", err)
|
||||
}
|
||||
|
||||
if !auth {
|
||||
http.Error(w, "Nicht angemeldet", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if username == "" {
|
||||
http.Error(w, "Benutzer nicht gefunden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get form values
|
||||
portfolioIDStr := r.FormValue("portfolio_id")
|
||||
transactionType := r.FormValue("type")
|
||||
stock := r.FormValue("stock")
|
||||
amountStr := r.FormValue("amount")
|
||||
priceStr := r.FormValue("price")
|
||||
dateStr := r.FormValue("date")
|
||||
note := r.FormValue("note")
|
||||
|
||||
// Basic validation
|
||||
if transactionType == "" || stock == "" || amountStr == "" || priceStr == "" || dateStr == "" {
|
||||
http.Error(w, "Alle Pflichtfelder müssen ausgefüllt werden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse form values
|
||||
amount, err := strconv.ParseFloat(amountStr, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültiger Betrag", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
price, err := strconv.ParseFloat(priceStr, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültiger Preis", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
date, err := time.Parse("2006-01-02", dateStr)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültiges Datum", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
portfolioID, err := strconv.ParseUint(portfolioIDStr, 10, 32)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültige Portfolio-ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Verify portfolio belongs to user
|
||||
var portfolio model.Portfolio
|
||||
if err := DB.Joins("User").Where("portfolios.id = ? AND User.username = ?", portfolioID, username).First(&portfolio).Error; err != nil {
|
||||
http.Error(w, "Portfolio nicht gefunden oder keine Berechtigung", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Fetch stock currency from Yahoo Finance
|
||||
stockCurrency, err := getStockCurrency(stock)
|
||||
if err != nil {
|
||||
fmt.Printf("Warning: Could not fetch currency for stock %s: %v. Using portfolio base currency.\n", stock, err)
|
||||
stockCurrency = portfolio.BaseCurrency
|
||||
}
|
||||
|
||||
fmt.Printf("Stock %s currency: %s\n", stock, stockCurrency)
|
||||
|
||||
// Create activity
|
||||
activity := model.Activity{
|
||||
PortfolioID: uint(portfolioID),
|
||||
Stock: stock,
|
||||
Type: model.ActivityType(transactionType),
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
Currency: stockCurrency, // Use the fetched stock currency
|
||||
Date: date,
|
||||
Note: note,
|
||||
}
|
||||
|
||||
if err := DB.Create(&activity).Error; err != nil {
|
||||
fmt.Printf("Error creating activity: %v\n", err)
|
||||
http.Error(w, "Fehler beim Speichern der Transaktion", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Activity created successfully: ID=%d, Type=%s, Stock=%s, Currency=%s, Portfolio=%d\n",
|
||||
activity.ID, activity.Type, activity.Stock, activity.Currency, activity.PortfolioID)
|
||||
|
||||
// Redirect to portfolio page
|
||||
http.Redirect(w, r, fmt.Sprintf("/portfolio/%d", portfolioID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func EditTransactionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error in EditTransactionHandler: %v\n", err)
|
||||
}
|
||||
|
||||
if !auth {
|
||||
http.Error(w, "Nicht angemeldet", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if username == "" {
|
||||
http.Error(w, "Benutzer nicht gefunden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get form values
|
||||
activityIDStr := r.FormValue("activity_id")
|
||||
portfolioIDStr := r.FormValue("portfolio_id")
|
||||
transactionType := r.FormValue("type")
|
||||
stock := r.FormValue("stock")
|
||||
amountStr := r.FormValue("amount")
|
||||
priceStr := r.FormValue("price")
|
||||
dateStr := r.FormValue("date")
|
||||
note := r.FormValue("note")
|
||||
|
||||
// Basic validation
|
||||
if activityIDStr == "" || transactionType == "" || stock == "" || amountStr == "" || priceStr == "" || dateStr == "" {
|
||||
http.Error(w, "Alle Pflichtfelder müssen ausgefüllt werden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse form values
|
||||
activityID, err := strconv.ParseUint(activityIDStr, 10, 32)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültige Aktivitäts-ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
portfolioID, err := strconv.ParseUint(portfolioIDStr, 10, 32)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültige Portfolio-ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
amount, err := strconv.ParseFloat(amountStr, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültiger Betrag", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
price, err := strconv.ParseFloat(priceStr, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültiger Preis", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
date, err := time.Parse("2006-01-02", dateStr)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültiges Datum", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get existing activity and verify ownership using subquery
|
||||
var activity model.Activity
|
||||
if err := DB.Where("id = ? AND portfolio_id IN (SELECT id FROM portfolios WHERE user_id = (SELECT id FROM users WHERE username = ?))",
|
||||
activityID, username).First(&activity).Error; err != nil {
|
||||
http.Error(w, "Aktivität nicht gefunden oder keine Berechtigung", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Verify the activity belongs to the specified portfolio
|
||||
if activity.PortfolioID != uint(portfolioID) {
|
||||
http.Error(w, "Aktivität gehört nicht zu diesem Portfolio", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get portfolio to access base currency
|
||||
var portfolio model.Portfolio
|
||||
if err := DB.Where("id = ?", portfolioID).First(&portfolio).Error; err != nil {
|
||||
http.Error(w, "Portfolio nicht gefunden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Fetch stock currency from Yahoo Finance (or use portfolio base currency as fallback)
|
||||
stockCurrency, err := getStockCurrency(stock)
|
||||
if err != nil {
|
||||
fmt.Printf("Warning: Could not fetch currency for stock %s: %v. Using portfolio base currency.\n", stock, err)
|
||||
stockCurrency = portfolio.BaseCurrency
|
||||
}
|
||||
|
||||
// Update activity fields
|
||||
activity.Type = model.ActivityType(transactionType)
|
||||
activity.Stock = stock
|
||||
activity.Amount = amount
|
||||
activity.Price = price
|
||||
activity.Currency = stockCurrency
|
||||
activity.Date = date
|
||||
activity.Note = note
|
||||
|
||||
// Save updated activity
|
||||
if err := DB.Save(&activity).Error; err != nil {
|
||||
fmt.Printf("Error updating activity: %v\n", err)
|
||||
http.Error(w, "Fehler beim Aktualisieren der Transaktion", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Activity updated successfully: ID=%d, Type=%s, Stock=%s, Portfolio=%d\n",
|
||||
activity.ID, activity.Type, activity.Stock, activity.PortfolioID)
|
||||
|
||||
// Redirect to portfolio page
|
||||
http.Redirect(w, r, fmt.Sprintf("/portfolio/%d", portfolioID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func DeleteTransactionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
auth, username, err := getSessionInfo(r)
|
||||
if err != nil {
|
||||
fmt.Printf("Session error in DeleteTransactionHandler: %v\n", err)
|
||||
}
|
||||
|
||||
if !auth {
|
||||
http.Error(w, "Nicht angemeldet", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if username == "" {
|
||||
http.Error(w, "Benutzer nicht gefunden", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get form values
|
||||
activityIDStr := r.FormValue("activity_id")
|
||||
portfolioIDStr := r.FormValue("portfolio_id")
|
||||
|
||||
// Basic validation
|
||||
if activityIDStr == "" || portfolioIDStr == "" {
|
||||
http.Error(w, "Aktivitäts-ID und Portfolio-ID sind erforderlich", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse form values
|
||||
activityID, err := strconv.ParseUint(activityIDStr, 10, 32)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültige Aktivitäts-ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
portfolioID, err := strconv.ParseUint(portfolioIDStr, 10, 32)
|
||||
if err != nil {
|
||||
http.Error(w, "Ungültige Portfolio-ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Get existing activity and verify ownership using subquery
|
||||
var activity model.Activity
|
||||
if err := DB.Where("id = ? AND portfolio_id IN (SELECT id FROM portfolios WHERE user_id = (SELECT id FROM users WHERE username = ?))",
|
||||
activityID, username).First(&activity).Error; err != nil {
|
||||
http.Error(w, "Aktivität nicht gefunden oder keine Berechtigung", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Verify the activity belongs to the specified portfolio
|
||||
if activity.PortfolioID != uint(portfolioID) {
|
||||
http.Error(w, "Aktivität gehört nicht zu diesem Portfolio", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete the activity
|
||||
if err := DB.Delete(&activity).Error; err != nil {
|
||||
fmt.Printf("Error deleting activity: %v\n", err)
|
||||
http.Error(w, "Fehler beim Löschen der Transaktion", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Activity deleted successfully: ID=%d, Type=%s, Stock=%s, Portfolio=%d\n",
|
||||
activity.ID, activity.Type, activity.Stock, activity.PortfolioID)
|
||||
|
||||
// Redirect to portfolio page
|
||||
http.Redirect(w, r, fmt.Sprintf("/portfolio/%d", portfolioID), http.StatusSeeOther)
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"log"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
)
|
||||
|
||||
var Store *sessions.CookieStore
|
||||
|
||||
func init() {
|
||||
// Generate a secure 32-byte key for session authentication
|
||||
authKey := make([]byte, 32)
|
||||
_, err := rand.Read(authKey)
|
||||
if err != nil {
|
||||
// Fallback to a static key if random generation fails
|
||||
authKey = []byte("your-32-byte-long-auth-key-here!!")
|
||||
log.Println("Warning: Using static session key. Generate a secure key for production!")
|
||||
}
|
||||
|
||||
Store = sessions.NewCookieStore(authKey)
|
||||
|
||||
// Configure session options
|
||||
Store.Options = &sessions.Options{
|
||||
Path: "/",
|
||||
MaxAge: 86400 * 7, // 7 days
|
||||
HttpOnly: true,
|
||||
Secure: false, // Set to true if using HTTPS
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ExchangeRateResponse represents the response from the exchange rate API
|
||||
type ExchangeRateResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Base string `json:"base"`
|
||||
Date string `json:"date"`
|
||||
Rates map[string]float64 `json:"rates"`
|
||||
}
|
||||
|
||||
// CachedRate stores exchange rate with timestamp
|
||||
type CachedRate struct {
|
||||
Rate float64
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
// Currency conversion cache
|
||||
var (
|
||||
exchangeRateCache = make(map[string]CachedRate)
|
||||
cacheMutex sync.RWMutex
|
||||
cacheValidDuration = 1 * time.Hour // Cache rates for 1 hour
|
||||
)
|
||||
|
||||
// GetExchangeRate fetches the exchange rate from fromCurrency to toCurrency
|
||||
func GetExchangeRate(fromCurrency, toCurrency string) (float64, error) {
|
||||
// If currencies are the same, return 1.0
|
||||
if fromCurrency == toCurrency {
|
||||
return 1.0, nil
|
||||
}
|
||||
|
||||
cacheKey := fmt.Sprintf("%s_%s", fromCurrency, toCurrency)
|
||||
|
||||
// Check cache first
|
||||
cacheMutex.RLock()
|
||||
if cached, exists := exchangeRateCache[cacheKey]; exists {
|
||||
if time.Since(cached.Timestamp) < cacheValidDuration {
|
||||
cacheMutex.RUnlock()
|
||||
return cached.Rate, nil
|
||||
}
|
||||
}
|
||||
cacheMutex.RUnlock()
|
||||
|
||||
// Fetch from API if not in cache or cache is expired
|
||||
rate, err := fetchExchangeRateFromAPI(fromCurrency, toCurrency)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Cache the result
|
||||
cacheMutex.Lock()
|
||||
exchangeRateCache[cacheKey] = CachedRate{
|
||||
Rate: rate,
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
cacheMutex.Unlock()
|
||||
|
||||
return rate, nil
|
||||
}
|
||||
|
||||
// fetchExchangeRateFromAPI fetches exchange rate from a free API
|
||||
func fetchExchangeRateFromAPI(fromCurrency, toCurrency string) (float64, error) {
|
||||
// Using exchangerate-api.com (completely free, no API key required)
|
||||
url := fmt.Sprintf("https://api.exchangerate-api.com/v4/latest/%s", fromCurrency)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error creating request: %v", err)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "Portfolio-Tracker/1.0")
|
||||
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error fetching exchange rate: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return 0, fmt.Errorf("API returned status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error reading response: %v", err)
|
||||
}
|
||||
|
||||
// Parse exchangerate-api.com response format
|
||||
var apiResp struct {
|
||||
Base string `json:"base"`
|
||||
Date string `json:"date"`
|
||||
Rates map[string]float64 `json:"rates"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &apiResp); err != nil {
|
||||
return 0, fmt.Errorf("error parsing JSON: %v", err)
|
||||
}
|
||||
|
||||
rate, exists := apiResp.Rates[toCurrency]
|
||||
if !exists {
|
||||
return 0, fmt.Errorf("currency %s not found in response", toCurrency)
|
||||
}
|
||||
|
||||
return rate, nil
|
||||
}
|
||||
|
||||
// ConvertCurrency converts an amount from one currency to another
|
||||
func ConvertCurrency(amount float64, fromCurrency, toCurrency string) (float64, error) {
|
||||
if fromCurrency == toCurrency {
|
||||
return amount, nil
|
||||
}
|
||||
|
||||
rate, err := GetExchangeRate(fromCurrency, toCurrency)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return amount * rate, nil
|
||||
}
|
||||
|
||||
// FormatCurrencyAmount formats a currency amount with the currency symbol
|
||||
func FormatCurrencyAmount(amount float64, currency string) string {
|
||||
return fmt.Sprintf("%.2f %s", amount, currency)
|
||||
}
|
||||
|
||||
// GetCurrencySymbol returns the symbol for common currencies
|
||||
func GetCurrencySymbol(currency string) string {
|
||||
symbols := map[string]string{
|
||||
"USD": "$",
|
||||
"EUR": "€",
|
||||
"GBP": "£",
|
||||
"JPY": "¥",
|
||||
"CHF": "CHF",
|
||||
"CAD": "C$",
|
||||
"AUD": "A$",
|
||||
"CNY": "¥",
|
||||
"INR": "₹",
|
||||
"KRW": "₩",
|
||||
"SEK": "kr",
|
||||
"NOK": "kr",
|
||||
"DKK": "kr",
|
||||
"PLN": "zł",
|
||||
"CZK": "Kč",
|
||||
"HUF": "Ft",
|
||||
}
|
||||
|
||||
if symbol, exists := symbols[currency]; exists {
|
||||
return symbol
|
||||
}
|
||||
return currency // Return currency code if symbol not found
|
||||
}
|
||||
|
||||
// FormatCurrencyWithSymbol formats amount with currency symbol
|
||||
func FormatCurrencyWithSymbol(amount float64, currency string) string {
|
||||
symbol := GetCurrencySymbol(currency)
|
||||
if symbol == currency {
|
||||
// If no symbol found, put currency after amount
|
||||
return fmt.Sprintf("%.2f %s", amount, currency)
|
||||
}
|
||||
|
||||
// For most currencies, put symbol before amount
|
||||
switch currency {
|
||||
case "EUR":
|
||||
return fmt.Sprintf("%.2f %s", amount, symbol)
|
||||
default:
|
||||
return fmt.Sprintf("%s%.2f", symbol, amount)
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertAndFormat converts currency and formats it nicely
|
||||
func ConvertAndFormat(amount float64, fromCurrency, toCurrency string) string {
|
||||
if fromCurrency == toCurrency {
|
||||
return FormatCurrencyWithSymbol(amount, toCurrency)
|
||||
}
|
||||
|
||||
convertedAmount, err := ConvertCurrency(amount, fromCurrency, toCurrency)
|
||||
if err != nil {
|
||||
// If conversion fails, return original amount with note
|
||||
return fmt.Sprintf("%.2f %s (conv. error)", amount, fromCurrency)
|
||||
}
|
||||
|
||||
return FormatCurrencyWithSymbol(convertedAmount, toCurrency)
|
||||
}
|
||||
|
||||
// BatchConvertCurrency converts multiple amounts in one API call for efficiency
|
||||
func BatchConvertCurrency(amounts []float64, fromCurrency, toCurrency string) ([]float64, error) {
|
||||
if fromCurrency == toCurrency {
|
||||
return amounts, nil
|
||||
}
|
||||
|
||||
rate, err := GetExchangeRate(fromCurrency, toCurrency)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
converted := make([]float64, len(amounts))
|
||||
for i, amount := range amounts {
|
||||
converted[i] = amount * rate
|
||||
}
|
||||
|
||||
return converted, nil
|
||||
}
|
||||
|
||||
// ClearCache clears the exchange rate cache (useful for testing or manual refresh)
|
||||
func ClearCache() {
|
||||
cacheMutex.Lock()
|
||||
defer cacheMutex.Unlock()
|
||||
exchangeRateCache = make(map[string]CachedRate)
|
||||
}
|
||||
|
||||
// GetCacheInfo returns information about cached exchange rates
|
||||
func GetCacheInfo() map[string]time.Time {
|
||||
cacheMutex.RLock()
|
||||
defer cacheMutex.RUnlock()
|
||||
|
||||
info := make(map[string]time.Time)
|
||||
for key, cached := range exchangeRateCache {
|
||||
info[key] = cached.Timestamp
|
||||
}
|
||||
return info
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGetExchangeRate_SameCurrency(t *testing.T) {
|
||||
rate, err := GetExchangeRate("USD", "USD")
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error for same currency, got %v", err)
|
||||
}
|
||||
if rate != 1.0 {
|
||||
t.Errorf("Expected rate 1.0 for same currency, got %f", rate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertCurrency_SameCurrency(t *testing.T) {
|
||||
amount := 100.0
|
||||
converted, err := ConvertCurrency(amount, "EUR", "EUR")
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error for same currency conversion, got %v", err)
|
||||
}
|
||||
if converted != amount {
|
||||
t.Errorf("Expected %f for same currency conversion, got %f", amount, converted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatCurrencyAmount(t *testing.T) {
|
||||
tests := []struct {
|
||||
amount float64
|
||||
currency string
|
||||
expected string
|
||||
}{
|
||||
{100.5, "USD", "100.50 USD"},
|
||||
{1234.567, "EUR", "1234.57 EUR"},
|
||||
{0.0, "GBP", "0.00 GBP"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := FormatCurrencyAmount(test.amount, test.currency)
|
||||
if result != test.expected {
|
||||
t.Errorf("FormatCurrencyAmount(%.2f, %s) = %s, expected %s",
|
||||
test.amount, test.currency, result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCurrencySymbol(t *testing.T) {
|
||||
tests := []struct {
|
||||
currency string
|
||||
expected string
|
||||
}{
|
||||
{"USD", "$"},
|
||||
{"EUR", "€"},
|
||||
{"GBP", "£"},
|
||||
{"JPY", "¥"},
|
||||
{"CHF", "CHF"},
|
||||
{"UNKNOWN", "UNKNOWN"}, // Should return currency code if symbol not found
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := GetCurrencySymbol(test.currency)
|
||||
if result != test.expected {
|
||||
t.Errorf("GetCurrencySymbol(%s) = %s, expected %s",
|
||||
test.currency, result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatCurrencyWithSymbol(t *testing.T) {
|
||||
tests := []struct {
|
||||
amount float64
|
||||
currency string
|
||||
expected string
|
||||
}{
|
||||
{100.5, "USD", "$100.50"},
|
||||
{1234.56, "EUR", "1234.56 €"},
|
||||
{999.99, "GBP", "£999.99"},
|
||||
{500.0, "UNKNOWN", "500.00 UNKNOWN"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := FormatCurrencyWithSymbol(test.amount, test.currency)
|
||||
if result != test.expected {
|
||||
t.Errorf("FormatCurrencyWithSymbol(%.2f, %s) = %s, expected %s",
|
||||
test.amount, test.currency, result, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertAndFormat_SameCurrency(t *testing.T) {
|
||||
amount := 100.0
|
||||
currency := "USD"
|
||||
result := ConvertAndFormat(amount, currency, currency)
|
||||
expected := FormatCurrencyWithSymbol(amount, currency)
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("ConvertAndFormat(%f, %s, %s) = %s, expected %s",
|
||||
amount, currency, currency, result, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBatchConvertCurrency_SameCurrency(t *testing.T) {
|
||||
amounts := []float64{100.0, 200.0, 300.0}
|
||||
currency := "EUR"
|
||||
|
||||
converted, err := BatchConvertCurrency(amounts, currency, currency)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error for same currency batch conversion, got %v", err)
|
||||
}
|
||||
|
||||
if len(converted) != len(amounts) {
|
||||
t.Errorf("Expected %d converted amounts, got %d", len(amounts), len(converted))
|
||||
}
|
||||
|
||||
for i, amount := range amounts {
|
||||
if converted[i] != amount {
|
||||
t.Errorf("Expected converted[%d] = %f, got %f", i, amount, converted[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClearCache(t *testing.T) {
|
||||
// Add something to cache first
|
||||
cacheMutex.Lock()
|
||||
exchangeRateCache["TEST_USD"] = CachedRate{
|
||||
Rate: 1.5,
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
cacheMutex.Unlock()
|
||||
|
||||
// Verify cache has content
|
||||
info := GetCacheInfo()
|
||||
if len(info) == 0 {
|
||||
t.Error("Expected cache to have content before clearing")
|
||||
}
|
||||
|
||||
// Clear cache
|
||||
ClearCache()
|
||||
|
||||
// Verify cache is empty
|
||||
info = GetCacheInfo()
|
||||
if len(info) != 0 {
|
||||
t.Errorf("Expected empty cache after clearing, got %d items", len(info))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCacheInfo(t *testing.T) {
|
||||
// Clear cache first
|
||||
ClearCache()
|
||||
|
||||
// Add test data to cache
|
||||
testTime := time.Now()
|
||||
cacheMutex.Lock()
|
||||
exchangeRateCache["EUR_USD"] = CachedRate{
|
||||
Rate: 1.2,
|
||||
Timestamp: testTime,
|
||||
}
|
||||
exchangeRateCache["GBP_EUR"] = CachedRate{
|
||||
Rate: 1.15,
|
||||
Timestamp: testTime,
|
||||
}
|
||||
cacheMutex.Unlock()
|
||||
|
||||
info := GetCacheInfo()
|
||||
|
||||
if len(info) != 2 {
|
||||
t.Errorf("Expected 2 cache entries, got %d", len(info))
|
||||
}
|
||||
|
||||
if timestamp, exists := info["EUR_USD"]; !exists {
|
||||
t.Error("Expected EUR_USD entry in cache info")
|
||||
} else if !timestamp.Equal(testTime) {
|
||||
t.Error("Expected timestamp to match test time")
|
||||
}
|
||||
|
||||
if timestamp, exists := info["GBP_EUR"]; !exists {
|
||||
t.Error("Expected GBP_EUR entry in cache info")
|
||||
} else if !timestamp.Equal(testTime) {
|
||||
t.Error("Expected timestamp to match test time")
|
||||
}
|
||||
}
|
||||
|
||||
// Test cache expiration logic
|
||||
func TestCacheExpiration(t *testing.T) {
|
||||
ClearCache()
|
||||
|
||||
// Add expired entry to cache
|
||||
expiredTime := time.Now().Add(-2 * time.Hour) // 2 hours ago
|
||||
cacheMutex.Lock()
|
||||
exchangeRateCache["TEST_EXPIRED"] = CachedRate{
|
||||
Rate: 1.0,
|
||||
Timestamp: expiredTime,
|
||||
}
|
||||
cacheMutex.Unlock()
|
||||
|
||||
// This should not use the expired cache (but will fail API call)
|
||||
// We're mainly testing that it doesn't return the cached expired value
|
||||
_, err := GetExchangeRate("TEST", "EXPIRED")
|
||||
if err == nil {
|
||||
t.Error("Expected error due to invalid currency pair, but got none")
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmark tests
|
||||
func BenchmarkGetCurrencySymbol(b *testing.B) {
|
||||
currencies := []string{"USD", "EUR", "GBP", "JPY", "CHF", "UNKNOWN"}
|
||||
for i := 0; i < b.N; i++ {
|
||||
currency := currencies[i%len(currencies)]
|
||||
GetCurrencySymbol(currency)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFormatCurrencyWithSymbol(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
FormatCurrencyWithSymbol(1234.56, "USD")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type YahooChartResponse struct {
|
||||
Chart struct {
|
||||
Result []struct {
|
||||
Timestamp []int64 `json:"timestamp"`
|
||||
Indicators struct {
|
||||
Quote []struct {
|
||||
Close []float64 `json:"close"`
|
||||
} `json:"quote"`
|
||||
} `json:"indicators"`
|
||||
} `json:"result"`
|
||||
} `json:"chart"`
|
||||
}
|
||||
|
||||
func StockSearch(query string) (string, error) {
|
||||
url := fmt.Sprintf("https://query2.finance.yahoo.com/v1/finance/search?q=%s", query)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Erstellen der Anfrage: %v", err)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Abrufen der URL: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("Fehler: HTTP Status %s", resp.Status)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Lesen der Antwort: %v", err)
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
func FetchYahooFinanceData(stock string) (string, error) {
|
||||
url := fmt.Sprintf(
|
||||
"https://query2.finance.yahoo.com/v8/finance/chart/%s?range=1y&interval=1d&events=history",
|
||||
stock,
|
||||
)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Erstellen der Anfrage: %v", err)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Abrufen der URL: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("Fehler: HTTP Status %s", resp.Status)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Lesen der Antwort: %v", err)
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
func FetchYahooFinanceDataMax(stock string) (string, error) {
|
||||
url := fmt.Sprintf(
|
||||
"https://query2.finance.yahoo.com/v8/finance/chart/%s?range=max&interval=1mo&events=div",
|
||||
stock,
|
||||
)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Erstellen der Anfrage: %v", err)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Abrufen der URL: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("Fehler: HTTP Status %s", resp.Status)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler beim Lesen der Antwort: %v", err)
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
// Neu: Daten für das Chart extrahieren
|
||||
func ExtractChartData(jsonStr string) ([]string, []float64, error) {
|
||||
var data YahooChartResponse
|
||||
err := json.Unmarshal([]byte(jsonStr), &data)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Fehler beim Parsen des JSON: %v", err)
|
||||
}
|
||||
if len(data.Chart.Result) == 0 {
|
||||
return nil, nil, fmt.Errorf("Keine Daten gefunden")
|
||||
}
|
||||
timestamps := data.Chart.Result[0].Timestamp
|
||||
closes := data.Chart.Result[0].Indicators.Quote[0].Close
|
||||
|
||||
labels := make([]string, len(timestamps))
|
||||
for i, ts := range timestamps {
|
||||
labels[i] = time.Unix(ts, 0).Format("2006-01-02")
|
||||
}
|
||||
return labels, closes, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package auth
|
||||
|
||||
templ RegisterForm() {
|
||||
<form method="post" action="/user/register" style="max-width:400px;margin:auto;">
|
||||
<h2>Registrieren</h2>
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Benutzername</label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">E-Mail</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Passwort</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Registrieren</button>
|
||||
</form>
|
||||
}
|
||||
|
||||
templ LoginForm() {
|
||||
<form method="post" action="/user/login" style="max-width:400px;margin:auto;">
|
||||
<h2>Anmelden</h2>
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Benutzername</label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Passwort</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Anmelden</button>
|
||||
</form>
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package auth
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
func RegisterForm() templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\" action=\"/user/register\" style=\"max-width:400px;margin:auto;\"><h2>Registrieren</h2><div class=\"mb-3\"><label for=\"username\" class=\"form-label\">Benutzername</label> <input type=\"text\" class=\"form-control\" id=\"username\" name=\"username\" required></div><div class=\"mb-3\"><label for=\"email\" class=\"form-label\">E-Mail</label> <input type=\"email\" class=\"form-control\" id=\"email\" name=\"email\" required></div><div class=\"mb-3\"><label for=\"password\" class=\"form-label\">Passwort</label> <input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\" required></div><button type=\"submit\" class=\"btn btn-primary w-100\">Registrieren</button></form>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func LoginForm() templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var2 == nil {
|
||||
templ_7745c5c3_Var2 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\" action=\"/user/login\" style=\"max-width:400px;margin:auto;\"><h2>Anmelden</h2><div class=\"mb-3\"><label for=\"username\" class=\"form-label\">Benutzername</label> <input type=\"text\" class=\"form-control\" id=\"username\" name=\"username\" required></div><div class=\"mb-3\"><label for=\"password\" class=\"form-label\">Passwort</label> <input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\" required></div><button type=\"submit\" class=\"btn btn-primary w-100\">Anmelden</button></form>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,78 @@
|
||||
package components
|
||||
|
||||
import "portfolio-tracker/internal/model"
|
||||
|
||||
templ PageLayout(authenticated bool, username string, title string, content templ.Component, portfolios []model.Portfolio) {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>{ title }</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/css/tabler.min.css"/>
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
body {
|
||||
min-height: 100vh;
|
||||
width: 100vw;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
.container-xl, .container-fluid {
|
||||
width: 100% !important;
|
||||
max-width: 100% !important;
|
||||
padding-left: 24px;
|
||||
padding-right: 24px;
|
||||
}
|
||||
.page-wrapper {
|
||||
margin-left: 220px;
|
||||
width: auto;
|
||||
}
|
||||
.card {
|
||||
width: 100%;
|
||||
}
|
||||
.dropdown-search {
|
||||
position: relative;
|
||||
}
|
||||
.dropdown-menu-search {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: 1000;
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 0 0 .25rem .25rem;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.dropdown-menu-search.show {
|
||||
display: block;
|
||||
}
|
||||
.dropdown-item-search {
|
||||
display: block;
|
||||
padding: .5rem 1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.dropdown-item-search:hover {
|
||||
background: #f1f3f4;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
||||
@Search()
|
||||
<div class="page">
|
||||
@Navigation(authenticated, portfolios)
|
||||
<div class="page-wrapper">
|
||||
@content
|
||||
</div>
|
||||
</div>
|
||||
@SearchJS()
|
||||
<script src="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/js/tabler.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package components
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import "portfolio-tracker/internal/model"
|
||||
|
||||
func PageLayout(authenticated bool, username string, title string, content templ.Component, portfolios []model.Portfolio) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/components/layout.templ`, Line: 11, Col: 17}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</title><link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/css/tabler.min.css\"><style>\n\t\t\thtml, body {\n\t\t\t\theight: 100%;\n\t\t\t\twidth: 100%;\n\t\t\t}\n\t\t\tbody {\n\t\t\t\tmin-height: 100vh;\n\t\t\t\twidth: 100vw;\n\t\t\t\toverflow-x: hidden;\n\t\t\t}\n\t\t\t.container-xl, .container-fluid {\n\t\t\t\twidth: 100% !important;\n\t\t\t\tmax-width: 100% !important;\n\t\t\t\tpadding-left: 24px;\n\t\t\t\tpadding-right: 24px;\n\t\t\t}\n\t\t\t.page-wrapper {\n\t\t\t\tmargin-left: 220px;\n\t\t\t\twidth: auto;\n\t\t\t}\n\t\t\t.card {\n\t\t\t\twidth: 100%;\n\t\t\t}\n\t\t\t.dropdown-search {\n\t\t\t\tposition: relative;\n\t\t\t}\n\t\t\t.dropdown-menu-search {\n\t\t\t\tdisplay: none;\n\t\t\t\tposition: absolute;\n\t\t\t\ttop: 100%;\n\t\t\t\tleft: 0;\n\t\t\t\twidth: 100%;\n\t\t\t\tz-index: 1000;\n\t\t\t\tbackground: #fff;\n\t\t\t\tborder: 1px solid #ddd;\n\t\t\t\tborder-radius: 0 0 .25rem .25rem;\n\t\t\t\tmax-height: 300px;\n\t\t\t\toverflow-y: auto;\n\t\t\t}\n\t\t\t.dropdown-menu-search.show {\n\t\t\t\tdisplay: block;\n\t\t\t}\n\t\t\t.dropdown-item-search {\n\t\t\t\tdisplay: block;\n\t\t\t\tpadding: .5rem 1rem;\n\t\t\t\tcursor: pointer;\n\t\t\t}\n\t\t\t.dropdown-item-search:hover {\n\t\t\t\tbackground: #f1f3f4;\n\t\t\t}\n\t\t</style></head><body><script src=\"https://cdn.jsdelivr.net/npm/apexcharts\"></script>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = Search().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"page\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = Navigation(authenticated, portfolios).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"page-wrapper\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = content.Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = SearchJS().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script src=\"https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/js/tabler.min.js\"></script></body></html>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,192 @@
|
||||
package components
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-tracker/internal/model"
|
||||
)
|
||||
|
||||
templ Navigation(authenticated bool, portfolios []model.Portfolio) {
|
||||
<aside class="navbar navbar-vertical navbar-expand-lg" data-bs-theme="dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">
|
||||
<span class="navbar-brand-text">Portfolio Tracker</span>
|
||||
</a>
|
||||
<div class="collapse navbar-collapse show">
|
||||
<ul class="navbar-nav pt-lg-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/">
|
||||
<span class="nav-link-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<rect x="3" y="12" width="6" height="8" rx="1"></rect>
|
||||
<rect x="9" y="8" width="6" height="12" rx="1"></rect>
|
||||
<rect x="15" y="4" width="6" height="16" rx="1"></rect>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nav-link-title">Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="portfolioDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<span class="nav-link-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M9 5H7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2V7a2 2 0 0 0 -2 -2h-2"></path>
|
||||
<path d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"></path>
|
||||
<path d="M9 12l2 2l4 -4"></path>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nav-link-title">Portfolio</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="portfolioDropdown">
|
||||
if len(portfolios) > 0 {
|
||||
for _, portfolio := range portfolios {
|
||||
<li><a class="dropdown-item" href={ templ.URL("/portfolio/" + templ.EscapeString(fmt.Sprintf("%d", portfolio.ID))) }>{ portfolio.Name }</a></li>
|
||||
}
|
||||
<li><hr class="dropdown-divider"/></li>
|
||||
} else {
|
||||
<li><span class="dropdown-item-text text-muted">Keine Portfolios vorhanden</span></li>
|
||||
<li><hr class="dropdown-divider"/></li>
|
||||
}
|
||||
<li>
|
||||
<a class="dropdown-item" href="/portfolio/new" data-bs-toggle="modal" data-bs-target="#createPortfolioModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-sm me-2" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M12 5l0 14"></path>
|
||||
<path d="M5 12l14 0"></path>
|
||||
</svg>
|
||||
Neues Portfolio erstellen
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">
|
||||
<span class="nav-link-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M3 21l18 0"></path>
|
||||
<path d="M3 10l18 0"></path>
|
||||
<path d="M5 6l7 -3l7 3"></path>
|
||||
<path d="M4 10l0 11"></path>
|
||||
<path d="M20 10l0 11"></path>
|
||||
<path d="M8 14l0 3"></path>
|
||||
<path d="M12 14l0 3"></path>
|
||||
<path d="M16 14l0 3"></path>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nav-link-title">Wertpapiere</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- Weitere Menüpunkte hier -->
|
||||
</ul>
|
||||
<div id="login_buttons" class="mt-4" style="padding-left:10px; padding-bottom:10px;">
|
||||
if authenticated == true {
|
||||
<form method="post" action="/user/logout">
|
||||
<button type="submit" class="btn btn-danger w-100">Logout</button>
|
||||
</form>
|
||||
} else {
|
||||
<button type="button" class="btn btn-outline-primary w-100 mb-2" data-bs-toggle="modal" data-bs-target="#loginModal">Login</button>
|
||||
<button type="button" class="btn btn-primary w-100" data-bs-toggle="modal" data-bs-target="#registerModal">Registrieren</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
<!-- Create Portfolio Modal -->
|
||||
<div class="modal modal-blur fade" id="createPortfolioModal" tabindex="-1" aria-labelledby="createPortfolioModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="createPortfolioModalLabel">Neues Portfolio erstellen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form method="post" action="/portfolio/create">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="portfolio-name" class="form-label">Portfolio Name</label>
|
||||
<input type="text" class="form-control" id="portfolio-name" name="name" placeholder="z.B. Mein Hauptportfolio" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="portfolio-currency" class="form-label">Basiswährung</label>
|
||||
<select class="form-select" id="portfolio-currency" name="base_currency" required>
|
||||
<option value="">Wählen Sie eine Währung</option>
|
||||
<option value="EUR">EUR - Euro</option>
|
||||
<option value="USD">USD - US Dollar</option>
|
||||
<option value="GBP">GBP - Britisches Pfund</option>
|
||||
<option value="CHF">CHF - Schweizer Franken</option>
|
||||
<option value="JPY">JPY - Japanischer Yen</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="portfolio-description" class="form-label">Beschreibung (optional)</label>
|
||||
<textarea class="form-control" id="portfolio-description" name="description" rows="3" placeholder="Beschreibung des Portfolios..."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
<button type="submit" class="btn btn-primary">Portfolio erstellen</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Login Modal -->
|
||||
<div class="modal modal-blur fade" id="loginModal" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="loginModalLabel">Anmelden</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form method="post" action="/user/login">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="login-username" class="form-label">Benutzername</label>
|
||||
<input type="text" class="form-control" id="login-username" name="username" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="login-password" class="form-label">Passwort</label>
|
||||
<input type="password" class="form-control" id="login-password" name="password" required/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer d-flex justify-content-between align-items-center">
|
||||
<a href="#" class="text-secondary small" data-bs-dismiss="modal" style="text-decoration:none;">Abbrechen</a>
|
||||
<button type="submit" class="btn btn-primary">Anmelden</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Register Modal -->
|
||||
<div class="modal modal-blur fade" id="registerModal" tabindex="-1" aria-labelledby="registerModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="registerModalLabel">Registrieren</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form method="post" action="/user/register">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="register-username" class="form-label">Benutzername</label>
|
||||
<input type="text" class="form-control" id="register-username" name="username" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="register-email" class="form-label">E-Mail</label>
|
||||
<input type="email" class="form-control" id="register-email" name="email" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="register-password" class="form-label">Passwort</label>
|
||||
<input type="password" class="form-control" id="register-password" name="password" required/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer d-flex justify-content-between align-items-center">
|
||||
<a href="#" class="text-secondary small" data-bs-dismiss="modal" style="text-decoration:none;">Abbrechen</a>
|
||||
<button type="submit" class="btn btn-primary">Registrieren</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package components
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-tracker/internal/model"
|
||||
)
|
||||
|
||||
func Navigation(authenticated bool, portfolios []model.Portfolio) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<aside class=\"navbar navbar-vertical navbar-expand-lg\" data-bs-theme=\"dark\"><div class=\"container-fluid\"><a class=\"navbar-brand\" href=\"#\"><span class=\"navbar-brand-text\">Portfolio Tracker</span></a><div class=\"collapse navbar-collapse show\"><ul class=\"navbar-nav pt-lg-3\"><li class=\"nav-item\"><a class=\"nav-link active\" href=\"/\"><span class=\"nav-link-icon\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <rect x=\"3\" y=\"12\" width=\"6\" height=\"8\" rx=\"1\"></rect> <rect x=\"9\" y=\"8\" width=\"6\" height=\"12\" rx=\"1\"></rect> <rect x=\"15\" y=\"4\" width=\"6\" height=\"16\" rx=\"1\"></rect></svg></span> <span class=\"nav-link-title\">Dashboard</span></a></li><li class=\"nav-item dropdown\"><a class=\"nav-link dropdown-toggle\" href=\"#\" id=\"portfolioDropdown\" role=\"button\" data-bs-toggle=\"dropdown\" aria-expanded=\"false\"><span class=\"nav-link-icon\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <path d=\"M9 5H7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2V7a2 2 0 0 0 -2 -2h-2\"></path> <path d=\"M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z\"></path> <path d=\"M9 12l2 2l4 -4\"></path></svg></span> <span class=\"nav-link-title\">Portfolio</span></a><ul class=\"dropdown-menu\" aria-labelledby=\"portfolioDropdown\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if len(portfolios) > 0 {
|
||||
for _, portfolio := range portfolios {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a class=\"dropdown-item\" href=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 templ.SafeURL = templ.URL("/portfolio/" + templ.EscapeString(fmt.Sprintf("%d", portfolio.ID)))
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var2)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/components/navigation.templ`, Line: 44, Col: 142}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></li>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <li><hr class=\"dropdown-divider\"></li>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><span class=\"dropdown-item-text text-muted\">Keine Portfolios vorhanden</span></li><li><hr class=\"dropdown-divider\"></li>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a class=\"dropdown-item\" href=\"/portfolio/new\" data-bs-toggle=\"modal\" data-bs-target=\"#createPortfolioModal\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon icon-sm me-2\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <path d=\"M12 5l0 14\"></path> <path d=\"M5 12l14 0\"></path></svg> Neues Portfolio erstellen</a></li></ul></li><li class=\"nav-item\"><a class=\"nav-link\" href=\"#\"><span class=\"nav-link-icon\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <path d=\"M3 21l18 0\"></path> <path d=\"M3 10l18 0\"></path> <path d=\"M5 6l7 -3l7 3\"></path> <path d=\"M4 10l0 11\"></path> <path d=\"M20 10l0 11\"></path> <path d=\"M8 14l0 3\"></path> <path d=\"M12 14l0 3\"></path> <path d=\"M16 14l0 3\"></path></svg></span> <span class=\"nav-link-title\">Wertpapiere</span></a></li><!-- Weitere Menüpunkte hier --></ul><div id=\"login_buttons\" class=\"mt-4\" style=\"padding-left:10px; padding-bottom:10px;\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if authenticated == true {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\" action=\"/user/logout\"><button type=\"submit\" class=\"btn btn-danger w-100\">Logout</button></form>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<button type=\"button\" class=\"btn btn-outline-primary w-100 mb-2\" data-bs-toggle=\"modal\" data-bs-target=\"#loginModal\">Login</button> <button type=\"button\" class=\"btn btn-primary w-100\" data-bs-toggle=\"modal\" data-bs-target=\"#registerModal\">Registrieren</button>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div></div></aside><!-- Create Portfolio Modal --><div class=\"modal modal-blur fade\" id=\"createPortfolioModal\" tabindex=\"-1\" aria-labelledby=\"createPortfolioModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"createPortfolioModalLabel\">Neues Portfolio erstellen</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Schließen\"></button></div><form method=\"post\" action=\"/portfolio/create\"><div class=\"modal-body\"><div class=\"mb-3\"><label for=\"portfolio-name\" class=\"form-label\">Portfolio Name</label> <input type=\"text\" class=\"form-control\" id=\"portfolio-name\" name=\"name\" placeholder=\"z.B. Mein Hauptportfolio\" required></div><div class=\"mb-3\"><label for=\"portfolio-currency\" class=\"form-label\">Basiswährung</label> <select class=\"form-select\" id=\"portfolio-currency\" name=\"base_currency\" required><option value=\"\">Wählen Sie eine Währung</option> <option value=\"EUR\">EUR - Euro</option> <option value=\"USD\">USD - US Dollar</option> <option value=\"GBP\">GBP - Britisches Pfund</option> <option value=\"CHF\">CHF - Schweizer Franken</option> <option value=\"JPY\">JPY - Japanischer Yen</option></select></div><div class=\"mb-3\"><label for=\"portfolio-description\" class=\"form-label\">Beschreibung (optional)</label> <textarea class=\"form-control\" id=\"portfolio-description\" name=\"description\" rows=\"3\" placeholder=\"Beschreibung des Portfolios...\"></textarea></div></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Abbrechen</button> <button type=\"submit\" class=\"btn btn-primary\">Portfolio erstellen</button></div></form></div></div></div><!-- Login Modal --><div class=\"modal modal-blur fade\" id=\"loginModal\" tabindex=\"-1\" aria-labelledby=\"loginModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"loginModalLabel\">Anmelden</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Schließen\"></button></div><form method=\"post\" action=\"/user/login\"><div class=\"modal-body\"><div class=\"mb-3\"><label for=\"login-username\" class=\"form-label\">Benutzername</label> <input type=\"text\" class=\"form-control\" id=\"login-username\" name=\"username\" required></div><div class=\"mb-3\"><label for=\"login-password\" class=\"form-label\">Passwort</label> <input type=\"password\" class=\"form-control\" id=\"login-password\" name=\"password\" required></div></div><div class=\"modal-footer d-flex justify-content-between align-items-center\"><a href=\"#\" class=\"text-secondary small\" data-bs-dismiss=\"modal\" style=\"text-decoration:none;\">Abbrechen</a> <button type=\"submit\" class=\"btn btn-primary\">Anmelden</button></div></form></div></div></div><!-- Register Modal --><div class=\"modal modal-blur fade\" id=\"registerModal\" tabindex=\"-1\" aria-labelledby=\"registerModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"registerModalLabel\">Registrieren</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Schließen\"></button></div><form method=\"post\" action=\"/user/register\"><div class=\"modal-body\"><div class=\"mb-3\"><label for=\"register-username\" class=\"form-label\">Benutzername</label> <input type=\"text\" class=\"form-control\" id=\"register-username\" name=\"username\" required></div><div class=\"mb-3\"><label for=\"register-email\" class=\"form-label\">E-Mail</label> <input type=\"email\" class=\"form-control\" id=\"register-email\" name=\"email\" required></div><div class=\"mb-3\"><label for=\"register-password\" class=\"form-label\">Passwort</label> <input type=\"password\" class=\"form-control\" id=\"register-password\" name=\"password\" required></div></div><div class=\"modal-footer d-flex justify-content-between align-items-center\"><a href=\"#\" class=\"text-secondary small\" data-bs-dismiss=\"modal\" style=\"text-decoration:none;\">Abbrechen</a> <button type=\"submit\" class=\"btn btn-primary\">Registrieren</button></div></form></div></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,19 @@
|
||||
package components
|
||||
|
||||
templ Search() {
|
||||
<div class="navbar navbar-expand-lg navbar-light bg-white" style="margin-left:220px;">
|
||||
<div class="container-fluid">
|
||||
<form class="d-flex dropdown-search" id="stock-search-form" autocomplete="off" style="width:100%;">
|
||||
<span class="input-group-text" style="background:transparent; border:none; padding-right:0;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-search" viewBox="0 0 24 24">
|
||||
<circle cx="11" cy="11" r="8"></circle>
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
||||
</svg>
|
||||
</span>
|
||||
<input class="form-control me-2" type="search" placeholder="WKN, ISIN, Name ..." aria-label="Search" id="stock-search-input" autocomplete="off" style="margin-left:-1px;"/>
|
||||
<button class="btn btn-primary" type="submit">Suchen</button>
|
||||
<div class="dropdown-menu-search" id="search-dropdown"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package components
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
func Search() templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"navbar navbar-expand-lg navbar-light bg-white\" style=\"margin-left:220px;\"><div class=\"container-fluid\"><form class=\"d-flex dropdown-search\" id=\"stock-search-form\" autocomplete=\"off\" style=\"width:100%;\"><span class=\"input-group-text\" style=\"background:transparent; border:none; padding-right:0;\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"icon icon-tabler icon-tabler-search\" viewBox=\"0 0 24 24\"><circle cx=\"11\" cy=\"11\" r=\"8\"></circle> <line x1=\"21\" y1=\"21\" x2=\"16.65\" y2=\"16.65\"></line></svg></span> <input class=\"form-control me-2\" type=\"search\" placeholder=\"WKN, ISIN, Name ...\" aria-label=\"Search\" id=\"stock-search-input\" autocomplete=\"off\" style=\"margin-left:-1px;\"> <button class=\"btn btn-primary\" type=\"submit\">Suchen</button><div class=\"dropdown-menu-search\" id=\"search-dropdown\"></div></form></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,89 @@
|
||||
package components
|
||||
|
||||
templ SearchJS() {
|
||||
<script>
|
||||
const input = document.getElementById('stock-search-input');
|
||||
const dropdown = document.getElementById('search-dropdown');
|
||||
let debounceTimeout;
|
||||
let selectedIndex = -1;
|
||||
|
||||
input.addEventListener('input', function () {
|
||||
selectedIndex = -1;
|
||||
const query = input.value.trim();
|
||||
clearTimeout(debounceTimeout);
|
||||
if (query.length < 2) {
|
||||
dropdown.classList.remove('show');
|
||||
dropdown.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
debounceTimeout = setTimeout(() => {
|
||||
fetch('/api/stocksearch?q=' + encodeURIComponent(query))
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.quotes && data.quotes.length > 0) {
|
||||
dropdown.innerHTML = data.quotes.map(item =>
|
||||
`<a class="dropdown-item-search" href="/details?stock=${encodeURIComponent(item.symbol)}">${item.longname || item.shortname || item.symbol} (${item.symbol})</a>`
|
||||
).join('');
|
||||
dropdown.classList.add('show');
|
||||
} else {
|
||||
dropdown.innerHTML = '<div class="dropdown-item-search">Keine Ergebnisse</div>';
|
||||
dropdown.classList.add('show');
|
||||
}
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
|
||||
input.addEventListener('keydown', function (e) {
|
||||
const items = Array.from(dropdown.querySelectorAll('.dropdown-item-search'));
|
||||
if (!dropdown.classList.contains('show') || items.length === 0) return;
|
||||
|
||||
if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
selectedIndex = (selectedIndex + 1) % items.length;
|
||||
updateDropdownSelection(items);
|
||||
} else if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
selectedIndex = (selectedIndex - 1 + items.length) % items.length;
|
||||
updateDropdownSelection(items);
|
||||
} else if (e.key === 'Enter') {
|
||||
if (selectedIndex >= 0 && selectedIndex < items.length) {
|
||||
e.preventDefault();
|
||||
window.location.href = items[selectedIndex].getAttribute('href');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function updateDropdownSelection(items) {
|
||||
items.forEach((item, idx) => {
|
||||
if (idx === selectedIndex) {
|
||||
item.classList.add('active');
|
||||
item.scrollIntoView({ block: 'nearest' });
|
||||
} else {
|
||||
item.classList.remove('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
if (!input.contains(e.target) && !dropdown.contains(e.target)) {
|
||||
dropdown.classList.remove('show');
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('stock-search-form').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const items = Array.from(dropdown.querySelectorAll('.dropdown-item-search'));
|
||||
// Wenn ein Eintrag ausgewählt ist, nimm diesen
|
||||
if (selectedIndex >= 0 && selectedIndex < items.length) {
|
||||
window.location.href = items[selectedIndex].getAttribute('href');
|
||||
return;
|
||||
}
|
||||
// Sonst nimm das erste Ergebnis, falls vorhanden
|
||||
if (items.length > 0) {
|
||||
window.location.href = items[0].getAttribute('href');
|
||||
return;
|
||||
}
|
||||
// Sonst nichts tun
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package components
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
func SearchJS() templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script>\n const input = document.getElementById('stock-search-input');\n const dropdown = document.getElementById('search-dropdown');\n let debounceTimeout;\n let selectedIndex = -1;\n\n input.addEventListener('input', function () {\n selectedIndex = -1;\n const query = input.value.trim();\n clearTimeout(debounceTimeout);\n if (query.length < 2) {\n dropdown.classList.remove('show');\n dropdown.innerHTML = '';\n return;\n }\n debounceTimeout = setTimeout(() => {\n fetch('/api/stocksearch?q=' + encodeURIComponent(query))\n .then(res => res.json())\n .then(data => {\n if (data.quotes && data.quotes.length > 0) {\n dropdown.innerHTML = data.quotes.map(item =>\n `<a class=\"dropdown-item-search\" href=\"/details?stock=${encodeURIComponent(item.symbol)}\">${item.longname || item.shortname || item.symbol} (${item.symbol})</a>`\n ).join('');\n dropdown.classList.add('show');\n } else {\n dropdown.innerHTML = '<div class=\"dropdown-item-search\">Keine Ergebnisse</div>';\n dropdown.classList.add('show');\n }\n });\n }, 300);\n });\n\n input.addEventListener('keydown', function (e) {\n const items = Array.from(dropdown.querySelectorAll('.dropdown-item-search'));\n if (!dropdown.classList.contains('show') || items.length === 0) return;\n\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n selectedIndex = (selectedIndex + 1) % items.length;\n updateDropdownSelection(items);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n selectedIndex = (selectedIndex - 1 + items.length) % items.length;\n updateDropdownSelection(items);\n } else if (e.key === 'Enter') {\n if (selectedIndex >= 0 && selectedIndex < items.length) {\n e.preventDefault();\n window.location.href = items[selectedIndex].getAttribute('href');\n }\n }\n });\n\n function updateDropdownSelection(items) {\n items.forEach((item, idx) => {\n if (idx === selectedIndex) {\n item.classList.add('active');\n item.scrollIntoView({ block: 'nearest' });\n } else {\n item.classList.remove('active');\n }\n });\n }\n\n document.addEventListener('click', function (e) {\n if (!input.contains(e.target) && !dropdown.contains(e.target)) {\n dropdown.classList.remove('show');\n }\n });\n\n document.getElementById('stock-search-form').addEventListener('submit', function(e) {\n e.preventDefault();\n const items = Array.from(dropdown.querySelectorAll('.dropdown-item-search'));\n // Wenn ein Eintrag ausgewählt ist, nimm diesen\n if (selectedIndex >= 0 && selectedIndex < items.length) {\n window.location.href = items[selectedIndex].getAttribute('href');\n return;\n }\n // Sonst nimm das erste Ergebnis, falls vorhanden\n if (items.length > 0) {\n window.location.href = items[0].getAttribute('href');\n return;\n }\n // Sonst nichts tun\n });\n </script>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,149 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/util"
|
||||
"time"
|
||||
)
|
||||
|
||||
// calculateTotalInvested calculates the total amount invested (buy transactions)
|
||||
func calculateTotalInvested(activities []model.Activity) float64 {
|
||||
var total float64 = 0
|
||||
for _, activity := range activities {
|
||||
if activity.Type == model.Buy {
|
||||
total += activity.Amount * activity.Price
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// calculateTotalInvestedInBaseCurrency calculates total invested converted to portfolio base currency
|
||||
func calculateTotalInvestedInBaseCurrency(activities []model.Activity, baseCurrency string) float64 {
|
||||
var total float64 = 0
|
||||
for _, activity := range activities {
|
||||
if activity.Type == model.Buy {
|
||||
activityTotal := activity.Amount * activity.Price
|
||||
|
||||
if activity.Currency == baseCurrency {
|
||||
total += activityTotal
|
||||
} else {
|
||||
convertedTotal, err := util.ConvertCurrency(activityTotal, activity.Currency, baseCurrency)
|
||||
if err != nil {
|
||||
// If conversion fails, add original amount (fallback)
|
||||
total += activityTotal
|
||||
} else {
|
||||
total += convertedTotal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// getLastBuyDate returns the date of the last buy transaction
|
||||
func getLastBuyDate(activities []model.Activity) string {
|
||||
var lastBuy time.Time
|
||||
for _, activity := range activities {
|
||||
if activity.Type == model.Buy && activity.Date.After(lastBuy) {
|
||||
lastBuy = activity.Date
|
||||
}
|
||||
}
|
||||
if lastBuy.IsZero() {
|
||||
return "Keine Käufe"
|
||||
}
|
||||
return lastBuy.Format("02.01.2006")
|
||||
}
|
||||
|
||||
// convertActivityPrice converts activity price to portfolio base currency if different
|
||||
func convertActivityPrice(activity model.Activity, portfolioBaseCurrency string) (float64, string, error) {
|
||||
if activity.Currency == portfolioBaseCurrency {
|
||||
return activity.Price, "", nil // No conversion needed
|
||||
}
|
||||
|
||||
convertedPrice, err := util.ConvertCurrency(activity.Price, activity.Currency, portfolioBaseCurrency)
|
||||
if err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
|
||||
return convertedPrice, portfolioBaseCurrency, nil
|
||||
}
|
||||
|
||||
// formatActivityPrice formats activity price with conversion if needed
|
||||
func formatActivityPrice(activity model.Activity, portfolioBaseCurrency string) string {
|
||||
if activity.Currency == portfolioBaseCurrency {
|
||||
return fmt.Sprintf("%.2f %s", activity.Price, activity.Currency)
|
||||
}
|
||||
|
||||
convertedPrice, err := util.ConvertCurrency(activity.Price, activity.Currency, portfolioBaseCurrency)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%.2f %s (conv. error)", activity.Price, activity.Currency)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f %s (~%.2f %s)", activity.Price, activity.Currency, convertedPrice, portfolioBaseCurrency)
|
||||
}
|
||||
|
||||
// formatActivityTotal formats activity total with conversion if needed
|
||||
func formatActivityTotal(activity model.Activity, portfolioBaseCurrency string) string {
|
||||
total := activity.Amount * activity.Price
|
||||
|
||||
if activity.Currency == portfolioBaseCurrency {
|
||||
return fmt.Sprintf("%.2f %s", total, activity.Currency)
|
||||
}
|
||||
|
||||
convertedTotal, err := util.ConvertCurrency(total, activity.Currency, portfolioBaseCurrency)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%.2f %s (conv. error)", total, activity.Currency)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f %s (~%.2f %s)", total, activity.Currency, convertedTotal, portfolioBaseCurrency)
|
||||
}
|
||||
|
||||
// getConvertedPrice returns the converted price or original if conversion fails
|
||||
func getConvertedPrice(activity model.Activity, portfolioBaseCurrency string) string {
|
||||
if activity.Currency == portfolioBaseCurrency {
|
||||
return ""
|
||||
}
|
||||
|
||||
convertedPrice, err := util.ConvertCurrency(activity.Price, activity.Currency, portfolioBaseCurrency)
|
||||
if err != nil {
|
||||
return "Conv. Error"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f %s", convertedPrice, portfolioBaseCurrency)
|
||||
}
|
||||
|
||||
// getConvertedTotal returns the converted total or original if conversion fails
|
||||
func getConvertedTotal(activity model.Activity, portfolioBaseCurrency string) string {
|
||||
if activity.Currency == portfolioBaseCurrency {
|
||||
return ""
|
||||
}
|
||||
|
||||
total := activity.Amount * activity.Price
|
||||
convertedTotal, err := util.ConvertCurrency(total, activity.Currency, portfolioBaseCurrency)
|
||||
if err != nil {
|
||||
return "Conv. Error"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f %s", convertedTotal, portfolioBaseCurrency)
|
||||
}
|
||||
|
||||
// formatTotalInvestedWithConversion formats total invested with currency info
|
||||
func formatTotalInvestedWithConversion(activities []model.Activity, baseCurrency string) string {
|
||||
convertedTotal := calculateTotalInvestedInBaseCurrency(activities, baseCurrency)
|
||||
|
||||
// Check if any activities have different currencies
|
||||
hasDifferentCurrencies := false
|
||||
for _, activity := range activities {
|
||||
if activity.Type == model.Buy && activity.Currency != baseCurrency {
|
||||
hasDifferentCurrencies = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !hasDifferentCurrencies {
|
||||
return fmt.Sprintf("%.2f %s", convertedTotal, baseCurrency)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f %s (converted)", convertedTotal, baseCurrency)
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/web/templates/components"
|
||||
)
|
||||
|
||||
templ PortfolioDetailContent(portfolio model.Portfolio) {
|
||||
<div class="container-fluid mt-4">
|
||||
<div class="page-header">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col">
|
||||
<h2 class="page-title">{ portfolio.Name } ({ portfolio.BaseCurrency })</h2>
|
||||
<div class="page-subtitle">
|
||||
if portfolio.Description != "" {
|
||||
{ portfolio.Description }
|
||||
} else {
|
||||
Erstellt am { portfolio.CreatedAt.Format("02.01.2006") }
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto ms-auto d-print-none">
|
||||
<div class="btn-list">
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTransactionModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M12 5l0 14"></path>
|
||||
<path d="M5 12l14 0"></path>
|
||||
</svg>
|
||||
Transaktion hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<!-- Portfolio Overview -->
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Positionen</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-vcenter">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Wertpapier</th>
|
||||
<th>Anzahl</th>
|
||||
<th>Ø Einkaufspreis</th>
|
||||
<th>Aktueller Wert</th>
|
||||
<th>+/- Gesamt</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
if len(portfolio.Activities) > 0 {
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-muted py-4">
|
||||
Position calculation will be implemented here
|
||||
</td>
|
||||
</tr>
|
||||
} else {
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-muted py-4">
|
||||
Keine Positionen vorhanden. Fügen Sie Ihre erste Transaktion hinzu.
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Recent Activities -->
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Letzte Transaktionen</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Datum</th>
|
||||
<th>Typ</th>
|
||||
<th>Wertpapier</th>
|
||||
<th>Anzahl</th>
|
||||
<th>Preis</th>
|
||||
<th>Preis ({ portfolio.BaseCurrency })</th>
|
||||
<th>Gesamt</th>
|
||||
<th>Gesamt ({ portfolio.BaseCurrency })</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
if len(portfolio.Activities) > 0 {
|
||||
for i, activity := range portfolio.Activities {
|
||||
if i < 10 {
|
||||
<tr>
|
||||
<td>{ activity.Date.Format("02.01.2006") }</td>
|
||||
<td>
|
||||
if activity.Type == "BUY" {
|
||||
<span class="badge bg-green">Kauf</span>
|
||||
} else if activity.Type == "SELL" {
|
||||
<span class="badge bg-red">Verkauf</span>
|
||||
} else if activity.Type == "DIVIDEND" {
|
||||
<span class="badge bg-blue">Dividende</span>
|
||||
} else {
|
||||
<span class="badge bg-secondary">{ string(activity.Type) }</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<a href={ templ.URL("/details?stock=" + activity.Stock) } class="text-decoration-none">
|
||||
{ activity.Stock }
|
||||
</a>
|
||||
</td>
|
||||
<td>{ fmt.Sprintf("%.3f", activity.Amount) }</td>
|
||||
<td>{ fmt.Sprintf("%.2f %s", activity.Price, activity.Currency) }</td>
|
||||
<td>
|
||||
if activity.Currency != portfolio.BaseCurrency {
|
||||
{ getConvertedPrice(activity, portfolio.BaseCurrency) }
|
||||
} else {
|
||||
<span class="text-muted">-</span>
|
||||
}
|
||||
</td>
|
||||
<td>{ fmt.Sprintf("%.2f %s", activity.Amount * activity.Price, activity.Currency) }</td>
|
||||
<td>
|
||||
if activity.Currency != portfolio.BaseCurrency {
|
||||
{ getConvertedTotal(activity, portfolio.BaseCurrency) }
|
||||
} else {
|
||||
<span class="text-muted">-</span>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-list flex-nowrap">
|
||||
<button
|
||||
class="btn btn-sm btn-outline-primary"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#editTransactionModal"
|
||||
data-activity-id={ fmt.Sprintf("%d", activity.ID) }
|
||||
data-activity-type={ string(activity.Type) }
|
||||
data-activity-stock={ activity.Stock }
|
||||
data-activity-amount={ fmt.Sprintf("%.3f", activity.Amount) }
|
||||
data-activity-price={ fmt.Sprintf("%.2f", activity.Price) }
|
||||
data-activity-date={ activity.Date.Format("2006-01-02") }
|
||||
data-activity-note={ activity.Note }
|
||||
>
|
||||
Bearbeiten
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-sm btn-outline-danger"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#deleteTransactionModal"
|
||||
data-activity-id={ fmt.Sprintf("%d", activity.ID) }
|
||||
data-activity-stock={ activity.Stock }
|
||||
data-activity-type={ string(activity.Type) }
|
||||
data-activity-amount={ fmt.Sprintf("%.3f", activity.Amount) }
|
||||
data-activity-date={ activity.Date.Format("02.01.2006") }
|
||||
>
|
||||
Löschen
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
} else {
|
||||
<tr>
|
||||
<td colspan="9" class="text-center text-muted py-3">
|
||||
Keine Transaktionen vorhanden
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Portfolio Summary -->
|
||||
<div class="col-md-4">
|
||||
<!-- Currency Conversion Info -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="me-3">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon text-blue" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<circle cx="12" cy="12" r="9"></circle>
|
||||
<path d="M12 8h.01"></path>
|
||||
<path d="M11 12h1v4h1"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="flex-fill">
|
||||
<div class="font-weight-medium">Währungsumrechnung</div>
|
||||
<div class="text-muted small">
|
||||
Transaktionen in anderen Währungen werden automatisch in { portfolio.BaseCurrency } umgerechnet.
|
||||
Wechselkurse werden stündlich aktualisiert.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Portfolio-Zusammenfassung</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@PortfolioSummary(portfolio.Activities, portfolio.BaseCurrency)
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Allokation</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="allocationChart"></div>
|
||||
<p class="text-muted text-center">Allokations-Chart wird hier implementiert</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Add Transaction Modal -->
|
||||
<div class="modal modal-blur fade" id="addTransactionModal" tabindex="-1" aria-labelledby="addTransactionModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addTransactionModalLabel">Transaktion hinzufügen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form method="post" action="/portfolio/transaction">
|
||||
<input type="hidden" name="portfolio_id" value={ fmt.Sprintf("%d", portfolio.ID) }/>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="transaction-type" class="form-label">Typ</label>
|
||||
<select class="form-select" id="transaction-type" name="type" required>
|
||||
<option value="">Wählen Sie einen Typ</option>
|
||||
<option value="BUY">Kauf</option>
|
||||
<option value="SELL">Verkauf</option>
|
||||
<option value="DIVIDEND">Dividende</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-stock" class="form-label">Wertpapier</label>
|
||||
<input type="text" class="form-control" id="transaction-stock" name="stock" placeholder="z.B. AAPL" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-amount" class="form-label">Anzahl</label>
|
||||
<input type="number" class="form-control" id="transaction-amount" name="amount" step="0.001" min="0" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-price" class="form-label">Preis</label>
|
||||
<div class="input-group">
|
||||
<input type="number" class="form-control" id="transaction-price" name="price" step="0.01" min="0" required/>
|
||||
<span class="input-group-text">{ portfolio.BaseCurrency }</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-date" class="form-label">Datum</label>
|
||||
<input type="date" class="form-control" id="transaction-date" name="date" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-note" class="form-label">Notiz (optional)</label>
|
||||
<textarea class="form-control" id="transaction-note" name="note" rows="2"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Edit Transaction Modal -->
|
||||
<div class="modal modal-blur fade" id="editTransactionModal" tabindex="-1" aria-labelledby="editTransactionModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editTransactionModalLabel">Transaktion bearbeiten</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form method="post" action="/portfolio/transaction/edit">
|
||||
<input type="hidden" name="activity_id" id="edit-activity-id"/>
|
||||
<input type="hidden" name="portfolio_id" value={ fmt.Sprintf("%d", portfolio.ID) }/>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="edit-transaction-type" class="form-label">Typ</label>
|
||||
<select class="form-select" id="edit-transaction-type" name="type" required>
|
||||
<option value="">Wählen Sie einen Typ</option>
|
||||
<option value="BUY">Kauf</option>
|
||||
<option value="SELL">Verkauf</option>
|
||||
<option value="DIVIDEND">Dividende</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit-transaction-stock" class="form-label">Wertpapier</label>
|
||||
<input type="text" class="form-control" id="edit-transaction-stock" name="stock" placeholder="z.B. AAPL" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit-transaction-amount" class="form-label">Anzahl</label>
|
||||
<input type="number" class="form-control" id="edit-transaction-amount" name="amount" step="0.001" min="0" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit-transaction-price" class="form-label">Preis</label>
|
||||
<div class="input-group">
|
||||
<input type="number" class="form-control" id="edit-transaction-price" name="price" step="0.01" min="0" required/>
|
||||
<span class="input-group-text">{ portfolio.BaseCurrency }</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit-transaction-date" class="form-label">Datum</label>
|
||||
<input type="date" class="form-control" id="edit-transaction-date" name="date" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="edit-transaction-note" class="form-label">Notiz (optional)</label>
|
||||
<textarea class="form-control" id="edit-transaction-note" name="note" rows="2"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Delete Transaction Modal -->
|
||||
<div class="modal modal-blur fade" id="deleteTransactionModal" tabindex="-1" aria-labelledby="deleteTransactionModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="deleteTransactionModalLabel">Transaktion löschen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Möchten Sie diese Transaktion wirklich löschen?</p>
|
||||
<div class="text-muted" id="delete-transaction-details">
|
||||
<small>Diese Aktion kann nicht rückgängig gemacht werden.</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
<form method="post" action="/portfolio/transaction/delete" style="display: inline;">
|
||||
<input type="hidden" name="activity_id" id="delete-activity-id"/>
|
||||
<input type="hidden" name="portfolio_id" value={ fmt.Sprintf("%d", portfolio.ID) }/>
|
||||
<button type="submit" class="btn btn-danger">Löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// Set today's date as default
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
document.getElementById('transaction-date').value = today;
|
||||
|
||||
// Handle edit button clicks
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target.closest('[data-bs-target="#editTransactionModal"]')) {
|
||||
const button = e.target.closest('[data-bs-target="#editTransactionModal"]');
|
||||
|
||||
// Populate edit modal with transaction data
|
||||
document.getElementById('edit-activity-id').value = button.dataset.activityId;
|
||||
document.getElementById('edit-transaction-type').value = button.dataset.activityType;
|
||||
document.getElementById('edit-transaction-stock').value = button.dataset.activityStock;
|
||||
document.getElementById('edit-transaction-amount').value = button.dataset.activityAmount;
|
||||
document.getElementById('edit-transaction-price').value = button.dataset.activityPrice;
|
||||
document.getElementById('edit-transaction-date').value = button.dataset.activityDate;
|
||||
document.getElementById('edit-transaction-note').value = button.dataset.activityNote;
|
||||
}
|
||||
|
||||
// Handle delete button clicks
|
||||
if (e.target.closest('[data-bs-target="#deleteTransactionModal"]')) {
|
||||
const button = e.target.closest('[data-bs-target="#deleteTransactionModal"]');
|
||||
|
||||
// Populate delete modal with transaction data
|
||||
document.getElementById('delete-activity-id').value = button.dataset.activityId;
|
||||
|
||||
// Show transaction details in delete modal
|
||||
const details = document.getElementById('delete-transaction-details');
|
||||
details.innerHTML = `
|
||||
<small>
|
||||
<strong>${button.dataset.activityType}</strong> - ${button.dataset.activityStock}<br>
|
||||
${button.dataset.activityAmount} Stück am ${button.dataset.activityDate}
|
||||
</small>
|
||||
`;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
// Separate component for portfolio summary
|
||||
templ PortfolioSummary(activities []model.Activity, currency string) {
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="mb-3">
|
||||
<div class="text-muted">Anzahl Transaktionen</div>
|
||||
<div class="h3 mb-0">{ fmt.Sprintf("%d", len(activities)) }</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="text-muted">Gesamtwert investiert</div>
|
||||
<div class="h2 mb-0">
|
||||
{ formatTotalInvestedWithConversion(activities, currency) }
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="text-muted">Letzter Kauf</div>
|
||||
<div class="h4 mb-0 text-muted">
|
||||
{ getLastBuyDate(activities) }
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ PortfolioDetail(authenticated bool, username string, portfolio model.Portfolio, portfolios []model.Portfolio) {
|
||||
@components.PageLayout(authenticated, username, portfolio.Name, PortfolioDetailContent(portfolio), portfolios)
|
||||
}
|
||||
@@ -0,0 +1,653 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/web/templates/components"
|
||||
)
|
||||
|
||||
func PortfolioDetailContent(portfolio model.Portfolio) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"container-fluid mt-4\"><div class=\"page-header\"><div class=\"row g-2 align-items-center\"><div class=\"col\"><h2 class=\"page-title\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 14, Col: 44}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" (")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.BaseCurrency)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 14, Col: 72}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(")</h2><div class=\"page-subtitle\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if portfolio.Description != "" {
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.Description)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 17, Col: 30}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Erstellt am ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.CreatedAt.Format("02.01.2006"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 19, Col: 61}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div><div class=\"col-auto ms-auto d-print-none\"><div class=\"btn-list\"><button type=\"button\" class=\"btn btn-primary\" data-bs-toggle=\"modal\" data-bs-target=\"#addTransactionModal\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <path d=\"M12 5l0 14\"></path> <path d=\"M5 12l14 0\"></path></svg> Transaktion hinzufügen</button></div></div></div></div><div class=\"row\"><!-- Portfolio Overview --><div class=\"col-md-8\"><div class=\"card\"><div class=\"card-header\"><h3 class=\"card-title\">Positionen</h3></div><div class=\"card-body\"><div class=\"table-responsive\"><table class=\"table table-vcenter\"><thead><tr><th>Wertpapier</th><th>Anzahl</th><th>Ø Einkaufspreis</th><th>Aktueller Wert</th><th>+/- Gesamt</th><th></th></tr></thead> <tbody>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if len(portfolio.Activities) > 0 {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td colspan=\"6\" class=\"text-center text-muted py-4\">Position calculation will be implemented here</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td colspan=\"6\" class=\"text-center text-muted py-4\">Keine Positionen vorhanden. Fügen Sie Ihre erste Transaktion hinzu.</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table></div></div></div><!-- Recent Activities --><div class=\"card mt-4\"><div class=\"card-header\"><h3 class=\"card-title\">Letzte Transaktionen</h3></div><div class=\"card-body\"><div class=\"table-responsive\"><table class=\"table table-sm\"><thead><tr><th>Datum</th><th>Typ</th><th>Wertpapier</th><th>Anzahl</th><th>Preis</th><th>Preis (")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.BaseCurrency)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 91, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(")</th><th>Gesamt</th><th>Gesamt (")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.BaseCurrency)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 93, Col: 46}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(")</th><th></th></tr></thead> <tbody>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if len(portfolio.Activities) > 0 {
|
||||
for i, activity := range portfolio.Activities {
|
||||
if i < 10 {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(activity.Date.Format("02.01.2006"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 102, Col: 53}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if activity.Type == "BUY" {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"badge bg-green\">Kauf</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else if activity.Type == "SELL" {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"badge bg-red\">Verkauf</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else if activity.Type == "DIVIDEND" {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"badge bg-blue\">Dividende</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"badge bg-secondary\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(string(activity.Type))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 111, Col: 71}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td><a href=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var10 templ.SafeURL = templ.URL("/details?stock=" + activity.Stock)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var10)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"text-decoration-none\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(activity.Stock)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 116, Col: 31}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.3f", activity.Amount))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 119, Col: 55}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f %s", activity.Price, activity.Currency))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 120, Col: 76}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if activity.Currency != portfolio.BaseCurrency {
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(getConvertedPrice(activity, portfolio.BaseCurrency))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 123, Col: 68}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"text-muted\">-</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var15 string
|
||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f %s", activity.Amount*activity.Price, activity.Currency))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 128, Col: 94}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if activity.Currency != portfolio.BaseCurrency {
|
||||
var templ_7745c5c3_Var16 string
|
||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(getConvertedTotal(activity, portfolio.BaseCurrency))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 131, Col: 68}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"text-muted\">-</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td><div class=\"btn-list flex-nowrap\"><button class=\"btn btn-sm btn-outline-primary\" data-bs-toggle=\"modal\" data-bs-target=\"#editTransactionModal\" data-activity-id=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var17 string
|
||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", activity.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 142, Col: 65}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-type=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var18 string
|
||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(string(activity.Type))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 143, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-stock=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var19 string
|
||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(activity.Stock)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 144, Col: 52}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-amount=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var20 string
|
||||
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.3f", activity.Amount))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 145, Col: 75}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-price=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var21 string
|
||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", activity.Price))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 146, Col: 73}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-date=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var22 string
|
||||
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(activity.Date.Format("2006-01-02"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 147, Col: 71}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-note=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var23 string
|
||||
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(activity.Note)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 148, Col: 50}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">Bearbeiten</button> <button class=\"btn btn-sm btn-outline-danger\" data-bs-toggle=\"modal\" data-bs-target=\"#deleteTransactionModal\" data-activity-id=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var24 string
|
||||
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", activity.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 156, Col: 65}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-stock=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var25 string
|
||||
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(activity.Stock)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 157, Col: 52}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-type=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var26 string
|
||||
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(string(activity.Type))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 158, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-amount=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var27 string
|
||||
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.3f", activity.Amount))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 159, Col: 75}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-activity-date=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var28 string
|
||||
templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(activity.Date.Format("02.01.2006"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 160, Col: 71}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">Löschen</button></div></td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td colspan=\"9\" class=\"text-center text-muted py-3\">Keine Transaktionen vorhanden</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table></div></div></div></div><!-- Portfolio Summary --><div class=\"col-md-4\"><!-- Currency Conversion Info --><div class=\"card mb-3\"><div class=\"card-body\"><div class=\"d-flex align-items-center\"><div class=\"me-3\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon text-blue\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <circle cx=\"12\" cy=\"12\" r=\"9\"></circle> <path d=\"M12 8h.01\"></path> <path d=\"M11 12h1v4h1\"></path></svg></div><div class=\"flex-fill\"><div class=\"font-weight-medium\">Währungsumrechnung</div><div class=\"text-muted small\">Transaktionen in anderen Währungen werden automatisch in ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var29 string
|
||||
templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.BaseCurrency)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 199, Col: 91}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" umgerechnet. Wechselkurse werden stündlich aktualisiert.</div></div></div></div></div><div class=\"card\"><div class=\"card-header\"><h3 class=\"card-title\">Portfolio-Zusammenfassung</h3></div><div class=\"card-body\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = PortfolioSummary(portfolio.Activities, portfolio.BaseCurrency).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div><div class=\"card mt-3\"><div class=\"card-header\"><h3 class=\"card-title\">Allokation</h3></div><div class=\"card-body\"><div id=\"allocationChart\"></div><p class=\"text-muted text-center\">Allokations-Chart wird hier implementiert</p></div></div></div></div></div><!-- Add Transaction Modal --><div class=\"modal modal-blur fade\" id=\"addTransactionModal\" tabindex=\"-1\" aria-labelledby=\"addTransactionModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"addTransactionModalLabel\">Transaktion hinzufügen</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Schließen\"></button></div><form method=\"post\" action=\"/portfolio/transaction\"><input type=\"hidden\" name=\"portfolio_id\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var30 string
|
||||
templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", portfolio.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 235, Col: 85}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><div class=\"modal-body\"><div class=\"mb-3\"><label for=\"transaction-type\" class=\"form-label\">Typ</label> <select class=\"form-select\" id=\"transaction-type\" name=\"type\" required><option value=\"\">Wählen Sie einen Typ</option> <option value=\"BUY\">Kauf</option> <option value=\"SELL\">Verkauf</option> <option value=\"DIVIDEND\">Dividende</option></select></div><div class=\"mb-3\"><label for=\"transaction-stock\" class=\"form-label\">Wertpapier</label> <input type=\"text\" class=\"form-control\" id=\"transaction-stock\" name=\"stock\" placeholder=\"z.B. AAPL\" required></div><div class=\"mb-3\"><label for=\"transaction-amount\" class=\"form-label\">Anzahl</label> <input type=\"number\" class=\"form-control\" id=\"transaction-amount\" name=\"amount\" step=\"0.001\" min=\"0\" required></div><div class=\"mb-3\"><label for=\"transaction-price\" class=\"form-label\">Preis</label><div class=\"input-group\"><input type=\"number\" class=\"form-control\" id=\"transaction-price\" name=\"price\" step=\"0.01\" min=\"0\" required> <span class=\"input-group-text\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var31 string
|
||||
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.BaseCurrency)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 258, Col: 63}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></div></div><div class=\"mb-3\"><label for=\"transaction-date\" class=\"form-label\">Datum</label> <input type=\"date\" class=\"form-control\" id=\"transaction-date\" name=\"date\" required></div><div class=\"mb-3\"><label for=\"transaction-note\" class=\"form-label\">Notiz (optional)</label> <textarea class=\"form-control\" id=\"transaction-note\" name=\"note\" rows=\"2\"></textarea></div></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Abbrechen</button> <button type=\"submit\" class=\"btn btn-primary\">Speichern</button></div></form></div></div></div><!-- Edit Transaction Modal --><div class=\"modal modal-blur fade\" id=\"editTransactionModal\" tabindex=\"-1\" aria-labelledby=\"editTransactionModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"editTransactionModalLabel\">Transaktion bearbeiten</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Schließen\"></button></div><form method=\"post\" action=\"/portfolio/transaction/edit\"><input type=\"hidden\" name=\"activity_id\" id=\"edit-activity-id\"> <input type=\"hidden\" name=\"portfolio_id\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var32 string
|
||||
templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", portfolio.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 288, Col: 85}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><div class=\"modal-body\"><div class=\"mb-3\"><label for=\"edit-transaction-type\" class=\"form-label\">Typ</label> <select class=\"form-select\" id=\"edit-transaction-type\" name=\"type\" required><option value=\"\">Wählen Sie einen Typ</option> <option value=\"BUY\">Kauf</option> <option value=\"SELL\">Verkauf</option> <option value=\"DIVIDEND\">Dividende</option></select></div><div class=\"mb-3\"><label for=\"edit-transaction-stock\" class=\"form-label\">Wertpapier</label> <input type=\"text\" class=\"form-control\" id=\"edit-transaction-stock\" name=\"stock\" placeholder=\"z.B. AAPL\" required></div><div class=\"mb-3\"><label for=\"edit-transaction-amount\" class=\"form-label\">Anzahl</label> <input type=\"number\" class=\"form-control\" id=\"edit-transaction-amount\" name=\"amount\" step=\"0.001\" min=\"0\" required></div><div class=\"mb-3\"><label for=\"edit-transaction-price\" class=\"form-label\">Preis</label><div class=\"input-group\"><input type=\"number\" class=\"form-control\" id=\"edit-transaction-price\" name=\"price\" step=\"0.01\" min=\"0\" required> <span class=\"input-group-text\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var33 string
|
||||
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(portfolio.BaseCurrency)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 311, Col: 63}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></div></div><div class=\"mb-3\"><label for=\"edit-transaction-date\" class=\"form-label\">Datum</label> <input type=\"date\" class=\"form-control\" id=\"edit-transaction-date\" name=\"date\" required></div><div class=\"mb-3\"><label for=\"edit-transaction-note\" class=\"form-label\">Notiz (optional)</label> <textarea class=\"form-control\" id=\"edit-transaction-note\" name=\"note\" rows=\"2\"></textarea></div></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Abbrechen</button> <button type=\"submit\" class=\"btn btn-primary\">Speichern</button></div></form></div></div></div><!-- Delete Transaction Modal --><div class=\"modal modal-blur fade\" id=\"deleteTransactionModal\" tabindex=\"-1\" aria-labelledby=\"deleteTransactionModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog modal-sm\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"deleteTransactionModalLabel\">Transaktion löschen</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Schließen\"></button></div><div class=\"modal-body\"><p>Möchten Sie diese Transaktion wirklich löschen?</p><div class=\"text-muted\" id=\"delete-transaction-details\"><small>Diese Aktion kann nicht rückgängig gemacht werden.</small></div></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Abbrechen</button><form method=\"post\" action=\"/portfolio/transaction/delete\" style=\"display: inline;\"><input type=\"hidden\" name=\"activity_id\" id=\"delete-activity-id\"> <input type=\"hidden\" name=\"portfolio_id\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var34 string
|
||||
templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", portfolio.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 349, Col: 86}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> <button type=\"submit\" class=\"btn btn-danger\">Löschen</button></form></div></div></div></div><script>\n\t\t// Set today's date as default\n\t\tdocument.addEventListener('DOMContentLoaded', function() {\n\t\t\tconst today = new Date().toISOString().split('T')[0];\n\t\t\tdocument.getElementById('transaction-date').value = today;\n\n\t\t\t// Handle edit button clicks\n\t\t\tdocument.addEventListener('click', function(e) {\n\t\t\t\tif (e.target.closest('[data-bs-target=\"#editTransactionModal\"]')) {\n\t\t\t\t\tconst button = e.target.closest('[data-bs-target=\"#editTransactionModal\"]');\n\n\t\t\t\t\t// Populate edit modal with transaction data\n\t\t\t\t\tdocument.getElementById('edit-activity-id').value = button.dataset.activityId;\n\t\t\t\t\tdocument.getElementById('edit-transaction-type').value = button.dataset.activityType;\n\t\t\t\t\tdocument.getElementById('edit-transaction-stock').value = button.dataset.activityStock;\n\t\t\t\t\tdocument.getElementById('edit-transaction-amount').value = button.dataset.activityAmount;\n\t\t\t\t\tdocument.getElementById('edit-transaction-price').value = button.dataset.activityPrice;\n\t\t\t\t\tdocument.getElementById('edit-transaction-date').value = button.dataset.activityDate;\n\t\t\t\t\tdocument.getElementById('edit-transaction-note').value = button.dataset.activityNote;\n\t\t\t\t}\n\n\t\t\t\t// Handle delete button clicks\n\t\t\t\tif (e.target.closest('[data-bs-target=\"#deleteTransactionModal\"]')) {\n\t\t\t\t\tconst button = e.target.closest('[data-bs-target=\"#deleteTransactionModal\"]');\n\n\t\t\t\t\t// Populate delete modal with transaction data\n\t\t\t\t\tdocument.getElementById('delete-activity-id').value = button.dataset.activityId;\n\n\t\t\t\t\t// Show transaction details in delete modal\n\t\t\t\t\tconst details = document.getElementById('delete-transaction-details');\n\t\t\t\t\tdetails.innerHTML = `\n\t\t\t\t\t\t<small>\n\t\t\t\t\t\t\t<strong>${button.dataset.activityType}</strong> - ${button.dataset.activityStock}<br>\n\t\t\t\t\t\t\t${button.dataset.activityAmount} Stück am ${button.dataset.activityDate}\n\t\t\t\t\t\t</small>\n\t\t\t\t\t`;\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
// Separate component for portfolio summary
|
||||
func PortfolioSummary(activities []model.Activity, currency string) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var35 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var35 == nil {
|
||||
templ_7745c5c3_Var35 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"row\"><div class=\"col-12\"><div class=\"mb-3\"><div class=\"text-muted\">Anzahl Transaktionen</div><div class=\"h3 mb-0\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var36 string
|
||||
templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(activities)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 404, Col: 61}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div><div class=\"mb-3\"><div class=\"text-muted\">Gesamtwert investiert</div><div class=\"h2 mb-0\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var37 string
|
||||
templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(formatTotalInvestedWithConversion(activities, currency))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 409, Col: 62}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div><div class=\"mb-3\"><div class=\"text-muted\">Letzter Kauf</div><div class=\"h4 mb-0 text-muted\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var38 string
|
||||
templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(getLastBuyDate(activities))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/portfolio-detail.templ`, Line: 415, Col: 33}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func PortfolioDetail(authenticated bool, username string, portfolio model.Portfolio, portfolios []model.Portfolio) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var39 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var39 == nil {
|
||||
templ_7745c5c3_Var39 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = components.PageLayout(authenticated, username, portfolio.Name, PortfolioDetailContent(portfolio), portfolios).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,154 @@
|
||||
package templates
|
||||
|
||||
import "portfolio-tracker/internal/web/templates/components"
|
||||
import "portfolio-tracker/internal/model"
|
||||
|
||||
templ PortfolioContent(username string) {
|
||||
<div class="container-fluid mt-4">
|
||||
<div class="page-header">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col">
|
||||
<h2 class="page-title">Portfolio</h2>
|
||||
<div class="page-subtitle">Verwalten Sie Ihre Investitionen</div>
|
||||
</div>
|
||||
<div class="col-auto ms-auto d-print-none">
|
||||
<div class="btn-list">
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTransactionModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M12 5l0 14" />
|
||||
<path d="M5 12l14 0" />
|
||||
</svg>
|
||||
Transaktion hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Portfolio Overview -->
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Portfolio-Übersicht</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-vcenter">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Wertpapier</th>
|
||||
<th>Anzahl</th>
|
||||
<th>Kurs</th>
|
||||
<th>Wert</th>
|
||||
<th>+/-</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-muted">
|
||||
Keine Positionen vorhanden. Fügen Sie Ihre erste Transaktion hinzu.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Portfolio Summary -->
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Zusammenfassung</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="mb-3">
|
||||
<div class="text-muted">Gesamtwert</div>
|
||||
<div class="h2 mb-0">€0,00</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="text-muted">Gewinn/Verlust</div>
|
||||
<div class="h3 mb-0 text-success">€0,00</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<div class="text-muted">Rendite</div>
|
||||
<div class="h3 mb-0 text-success">0,00%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Letzte Transaktionen</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="text-center text-muted py-3">
|
||||
Keine Transaktionen vorhanden
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Transaction Modal -->
|
||||
<div class="modal modal-blur fade" id="addTransactionModal" tabindex="-1" aria-labelledby="addTransactionModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addTransactionModalLabel">Transaktion hinzufügen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form method="post" action="/portfolio/transaction">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="transaction-type" class="form-label">Typ</label>
|
||||
<select class="form-select" id="transaction-type" name="type" required>
|
||||
<option value="">Wählen Sie einen Typ</option>
|
||||
<option value="BUY">Kauf</option>
|
||||
<option value="SELL">Verkauf</option>
|
||||
<option value="DIVIDEND">Dividende</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-stock" class="form-label">Wertpapier</label>
|
||||
<input type="text" class="form-control" id="transaction-stock" name="stock" placeholder="z.B. AAPL" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-amount" class="form-label">Anzahl</label>
|
||||
<input type="number" class="form-control" id="transaction-amount" name="amount" step="0.01" min="0" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-price" class="form-label">Preis</label>
|
||||
<input type="number" class="form-control" id="transaction-price" name="price" step="0.01" min="0" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-date" class="form-label">Datum</label>
|
||||
<input type="date" class="form-control" id="transaction-date" name="date" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-note" class="form-label">Notiz (optional)</label>
|
||||
<textarea class="form-control" id="transaction-note" name="note" rows="2"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ Portfolio(authenticated bool, username string, portfolios []model.Portfolio) {
|
||||
@components.PageLayout(authenticated, username, "Portfolio", PortfolioContent(username), portfolios)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import "portfolio-tracker/internal/web/templates/components"
|
||||
import "portfolio-tracker/internal/model"
|
||||
|
||||
func PortfolioContent(username string) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"container-fluid mt-4\"><div class=\"page-header\"><div class=\"row g-2 align-items-center\"><div class=\"col\"><h2 class=\"page-title\">Portfolio</h2><div class=\"page-subtitle\">Verwalten Sie Ihre Investitionen</div></div><div class=\"col-auto ms-auto d-print-none\"><div class=\"btn-list\"><button type=\"button\" class=\"btn btn-primary\" data-bs-toggle=\"modal\" data-bs-target=\"#addTransactionModal\"><svg xmlns=\"http://www.w3.org/2000/svg\" class=\"icon\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"></path> <path d=\"M12 5l0 14\"></path> <path d=\"M5 12l14 0\"></path></svg> Transaktion hinzufügen</button></div></div></div></div><div class=\"row\"><!-- Portfolio Overview --><div class=\"col-md-8\"><div class=\"card\"><div class=\"card-header\"><h3 class=\"card-title\">Portfolio-Übersicht</h3></div><div class=\"card-body\"><div class=\"table-responsive\"><table class=\"table table-vcenter\"><thead><tr><th>Wertpapier</th><th>Anzahl</th><th>Kurs</th><th>Wert</th><th>+/-</th><th></th></tr></thead> <tbody><tr><td colspan=\"6\" class=\"text-center text-muted\">Keine Positionen vorhanden. Fügen Sie Ihre erste Transaktion hinzu.</td></tr></tbody></table></div></div></div></div><!-- Portfolio Summary --><div class=\"col-md-4\"><div class=\"card\"><div class=\"card-header\"><h3 class=\"card-title\">Zusammenfassung</h3></div><div class=\"card-body\"><div class=\"row\"><div class=\"col-12\"><div class=\"mb-3\"><div class=\"text-muted\">Gesamtwert</div><div class=\"h2 mb-0\">€0,00</div></div><div class=\"mb-3\"><div class=\"text-muted\">Gewinn/Verlust</div><div class=\"h3 mb-0 text-success\">€0,00</div></div><div class=\"mb-3\"><div class=\"text-muted\">Rendite</div><div class=\"h3 mb-0 text-success\">0,00%</div></div></div></div></div></div><div class=\"card mt-3\"><div class=\"card-header\"><h3 class=\"card-title\">Letzte Transaktionen</h3></div><div class=\"card-body\"><div class=\"text-center text-muted py-3\">Keine Transaktionen vorhanden</div></div></div></div></div></div><!-- Add Transaction Modal --><div class=\"modal modal-blur fade\" id=\"addTransactionModal\" tabindex=\"-1\" aria-labelledby=\"addTransactionModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"addTransactionModalLabel\">Transaktion hinzufügen</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Schließen\"></button></div><form method=\"post\" action=\"/portfolio/transaction\"><div class=\"modal-body\"><div class=\"mb-3\"><label for=\"transaction-type\" class=\"form-label\">Typ</label> <select class=\"form-select\" id=\"transaction-type\" name=\"type\" required><option value=\"\">Wählen Sie einen Typ</option> <option value=\"BUY\">Kauf</option> <option value=\"SELL\">Verkauf</option> <option value=\"DIVIDEND\">Dividende</option></select></div><div class=\"mb-3\"><label for=\"transaction-stock\" class=\"form-label\">Wertpapier</label> <input type=\"text\" class=\"form-control\" id=\"transaction-stock\" name=\"stock\" placeholder=\"z.B. AAPL\" required></div><div class=\"mb-3\"><label for=\"transaction-amount\" class=\"form-label\">Anzahl</label> <input type=\"number\" class=\"form-control\" id=\"transaction-amount\" name=\"amount\" step=\"0.01\" min=\"0\" required></div><div class=\"mb-3\"><label for=\"transaction-price\" class=\"form-label\">Preis</label> <input type=\"number\" class=\"form-control\" id=\"transaction-price\" name=\"price\" step=\"0.01\" min=\"0\" required></div><div class=\"mb-3\"><label for=\"transaction-date\" class=\"form-label\">Datum</label> <input type=\"date\" class=\"form-control\" id=\"transaction-date\" name=\"date\" required></div><div class=\"mb-3\"><label for=\"transaction-note\" class=\"form-label\">Notiz (optional)</label> <textarea class=\"form-control\" id=\"transaction-note\" name=\"note\" rows=\"2\"></textarea></div></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Abbrechen</button> <button type=\"submit\" class=\"btn btn-primary\">Speichern</button></div></form></div></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func Portfolio(authenticated bool, username string, portfolios []model.Portfolio) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var2 == nil {
|
||||
templ_7745c5c3_Var2 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = components.PageLayout(authenticated, username, "Portfolio", PortfolioContent(username), portfolios).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,25 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/web/templates/components"
|
||||
)
|
||||
|
||||
templ DashboardContent(username string) {
|
||||
<div class="container-xl mt-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Willkommen, { username }!</h3>
|
||||
<p class="card-text">Hier ist dein Dashboard.</p>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="chart"></div>
|
||||
<p class="text-muted">Hier können Sie Ihre Portfolio-Übersicht einsehen.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ Result(authenticated bool, username string, portfolios []model.Portfolio) {
|
||||
@components.PageLayout(authenticated, username, "Dashboard", DashboardContent(username), portfolios)
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.778
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/web/templates/components"
|
||||
)
|
||||
|
||||
func DashboardContent(username string) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"container-xl mt-4\"><div class=\"card\"><div class=\"card-header\"><h3 class=\"card-title\">Willkommen, ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(username)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/templates/start.templ`, Line: 12, Col: 49}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("!</h3><p class=\"card-text\">Hier ist dein Dashboard.</p></div><div class=\"card-body\"><div id=\"chart\"></div><p class=\"text-muted\">Hier können Sie Ihre Portfolio-Übersicht einsehen.</p></div></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func Result(authenticated bool, username string, portfolios []model.Portfolio) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var3 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var3 == nil {
|
||||
templ_7745c5c3_Var3 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = components.PageLayout(authenticated, username, "Dashboard", DashboardContent(username), portfolios).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -0,0 +1,300 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/web/templates/components"
|
||||
)
|
||||
|
||||
templ StockDetailsContent(stock string, data model.YahooChartResponse, portfolios []model.Portfolio) {
|
||||
<div class="page-header d-print-none" aria-label="Page header">
|
||||
<div class="container-fluid">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col">
|
||||
<div class="page-pretitle">{ data.Chart.Result[0].Meta.Symbol }</div>
|
||||
<h2 class="page-title">{ data.Chart.Result[0].Meta.LongName }</h2>
|
||||
</div>
|
||||
<div class="col-auto ms-auto d-print-none">
|
||||
<div class="btn-list">
|
||||
<span class="d-none d-sm-inline">
|
||||
<a href="/portfolio" class="btn btn-outline-primary">Zum Portfolio</a>
|
||||
</span>
|
||||
<button type="button" class="btn btn-primary btn-5 d-none d-sm-inline-block" data-bs-toggle="modal" data-bs-target="#addToPortfolioModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M12 5l0 14"></path>
|
||||
<path d="M5 12l14 0"></path>
|
||||
</svg>
|
||||
Zu Portfolio hinzufügen
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary btn-6 d-sm-none btn-icon" data-bs-toggle="modal" data-bs-target="#addToPortfolioModal" aria-label="Zu Portfolio hinzufügen">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M12 5l0 14"></path>
|
||||
<path d="M5 12l14 0"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid mt-4">
|
||||
<div class="row">
|
||||
<!-- Linke Spalte: Charts -->
|
||||
<div class="col-md-8 col-12">
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<h1 class="card-title">Kursentwicklung</h1>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="chart"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h1 class="card-title">Dividenden</h1>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="chart2"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Rechte Spalte: Details -->
|
||||
<div class="col-md-4 col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title">Details</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled">
|
||||
<li><strong>Name:</strong> { data.Chart.Result[0].Meta.LongName }</li>
|
||||
<li><strong>Symbol:</strong> { data.Chart.Result[0].Meta.Symbol }</li>
|
||||
<li><strong>Währung:</strong> { data.Chart.Result[0].Meta.Currency }</li>
|
||||
<li><strong>Börse:</strong> { data.Chart.Result[0].Meta.Exchange }</li>
|
||||
<li><strong>Zeitzone:</strong> { data.Chart.Result[0].Meta.Timezone }</li>
|
||||
<li><strong>Aktueller Preis:</strong> { data.Chart.Result[0].Meta.RegularMarketPrice }</li>
|
||||
<li><strong>Instrumenttyp:</strong> { data.Chart.Result[0].Meta.Instrument }</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Add to Portfolio Modal -->
|
||||
<div class="modal modal-blur fade" id="addToPortfolioModal" tabindex="-1" aria-labelledby="addToPortfolioModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addToPortfolioModalLabel">{ data.Chart.Result[0].Meta.Symbol } zu Portfolio hinzufügen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
||||
</div>
|
||||
<form method="post" action="/portfolio/transaction">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="portfolio-select" class="form-label">Portfolio</label>
|
||||
<select class="form-select" id="portfolio-select" name="portfolio_id" required>
|
||||
<option value="">Wählen Sie ein Portfolio</option>
|
||||
for _, portfolio := range portfolios {
|
||||
<option value={ fmt.Sprintf("%d", portfolio.ID) }>
|
||||
{ portfolio.Name } ({ portfolio.BaseCurrency })
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-type" class="form-label">Transaktionstyp</label>
|
||||
<select class="form-select" id="transaction-type" name="type" required>
|
||||
<option value="">Wählen Sie einen Typ</option>
|
||||
<option value="BUY">Kauf</option>
|
||||
<option value="SELL">Verkauf</option>
|
||||
<option value="DIVIDEND">Dividende</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-stock" class="form-label">Wertpapier</label>
|
||||
<input type="text" class="form-control" id="transaction-stock" name="stock" value={ data.Chart.Result[0].Meta.Symbol } readonly/>
|
||||
<div class="form-text">{ data.Chart.Result[0].Meta.LongName }</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-amount" class="form-label">Anzahl</label>
|
||||
<input type="number" class="form-control" id="transaction-amount" name="amount" step="0.001" min="0" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-price" class="form-label">Preis pro Aktie</label>
|
||||
<div class="input-group">
|
||||
<input type="number" class="form-control" id="transaction-price" name="price" step="0.01" min="0" value={ data.Chart.Result[0].Meta.RegularMarketPrice } required/>
|
||||
<span class="input-group-text">{ data.Chart.Result[0].Meta.Currency }</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-date" class="form-label">Datum</label>
|
||||
<input type="date" class="form-control" id="transaction-date" name="date" required/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="transaction-note" class="form-label">Notiz (optional)</label>
|
||||
<textarea class="form-control" id="transaction-note" name="note" rows="2" placeholder="z.B. Grund für Kauf/Verkauf"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
<button type="submit" class="btn btn-primary">Zu Portfolio hinzufügen</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Inline Scripts for Charts -->
|
||||
<script>
|
||||
// Stock symbol for API calls
|
||||
const stockSymbol = {{ data.Chart.Result[0].Meta.Symbol }};
|
||||
|
||||
// Set today's date as default
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
document.getElementById('transaction-date').value = today;
|
||||
|
||||
// First Chart: Stock Price
|
||||
fetch('/api/yahoo?stock=' + encodeURIComponent(stockSymbol))
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Stock data received:', data);
|
||||
if (data.chart && data.chart.result && data.chart.result.length > 0) {
|
||||
const result = data.chart.result[0];
|
||||
const timestamps = result.timestamp.map(ts =>
|
||||
new Date(ts * 1000).toISOString().slice(0, 10)
|
||||
);
|
||||
const closes = result.indicators.quote[0].close.map(v =>
|
||||
v !== null ? Math.round(v * 10000) / 10000 : null
|
||||
);
|
||||
|
||||
const options = {
|
||||
chart: {
|
||||
type: 'area',
|
||||
height: 350,
|
||||
toolbar: {
|
||||
show: true
|
||||
}
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: false
|
||||
},
|
||||
series: [{
|
||||
name: 'Kurs',
|
||||
data: closes
|
||||
}],
|
||||
xaxis: {
|
||||
categories: timestamps,
|
||||
type: 'datetime'
|
||||
},
|
||||
yaxis: {
|
||||
labels: {
|
||||
formatter: function(value) {
|
||||
return value ? value.toFixed(2) : '';
|
||||
}
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
x: {
|
||||
format: 'dd MMM yyyy'
|
||||
},
|
||||
y: {
|
||||
formatter: function(value) {
|
||||
return value ? value.toFixed(2) : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const chart = new ApexCharts(document.querySelector("#chart"), options);
|
||||
chart.render();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching stock data:', error);
|
||||
document.querySelector("#chart").innerHTML = '<p>Fehler beim Laden der Kursdaten.</p>';
|
||||
});
|
||||
|
||||
// Second Chart: Dividends
|
||||
fetch('/api/yahoomaxdividends?stock=' + encodeURIComponent(stockSymbol))
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Dividend data received:', data);
|
||||
console.log('Data type:', typeof data);
|
||||
console.log('Data length:', data ? data.length : 'no length');
|
||||
|
||||
if (data && Array.isArray(data) && data.length > 0) {
|
||||
console.log('First dividend entry:', data[0]);
|
||||
|
||||
// Convert the data to the format ApexCharts expects
|
||||
const dividendData = data.map(item => ({
|
||||
x: new Date(item[0]),
|
||||
y: item[1]
|
||||
}));
|
||||
|
||||
console.log('Processed dividend data:', dividendData);
|
||||
|
||||
const options2 = {
|
||||
chart: {
|
||||
type: 'bar',
|
||||
height: 350,
|
||||
toolbar: {
|
||||
show: true
|
||||
}
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: false,
|
||||
formatter: function(val) {
|
||||
return val.toFixed(2);
|
||||
}
|
||||
},
|
||||
series: [{
|
||||
name: 'Dividende',
|
||||
data: dividendData
|
||||
}],
|
||||
xaxis: {
|
||||
type: 'datetime',
|
||||
title: {
|
||||
text: 'Datum'
|
||||
}
|
||||
},
|
||||
yaxis: {
|
||||
title: {
|
||||
text: 'Dividende'
|
||||
},
|
||||
labels: {
|
||||
formatter: function(value) {
|
||||
return value ? value.toFixed(2) : '';
|
||||
}
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
x: {
|
||||
format: 'dd MMM yyyy'
|
||||
},
|
||||
y: {
|
||||
formatter: function(value) {
|
||||
return value ? value.toFixed(2) : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const chart2 = new ApexCharts(document.querySelector("#chart2"), options2);
|
||||
chart2.render();
|
||||
} else {
|
||||
console.log('No dividend data available or data is empty');
|
||||
document.querySelector("#chart2").innerHTML = '<p>Keine Dividendendaten verfügbar für dieses Wertpapier.</p>';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching dividend data:', error);
|
||||
document.querySelector("#chart2").innerHTML = '<p>Fehler beim Laden der Dividendendaten.</p>';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
templ StockDetails(authenticated bool, username string, stock string, data model.YahooChartResponse, portfolios []model.Portfolio) {
|
||||
@components.PageLayout(authenticated, username, data.Chart.Result[0].Meta.LongName, StockDetailsContent(stock, data, portfolios), portfolios)
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user