app is now using historical exchange rates for transactions
This commit is contained in:
+47
-5
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"portfolio-tracker/internal/model"
|
||||
"portfolio-tracker/internal/util"
|
||||
"time"
|
||||
)
|
||||
|
||||
func JsonEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -110,7 +111,26 @@ func ClearCurrencyCacheHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
response := map[string]string{
|
||||
"status": "success",
|
||||
"message": "Currency cache cleared successfully",
|
||||
"message": "Currency cache (including historical rates) cleared successfully",
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
// CleanExpiredCacheHandler removes expired cache entries
|
||||
func CleanExpiredCacheHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
removedCount := util.CleanExpiredCache()
|
||||
|
||||
response := map[string]interface{}{
|
||||
"status": "success",
|
||||
"message": "Expired cache entries cleaned",
|
||||
"removed_count": removedCount,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -124,12 +144,34 @@ func CurrencyCacheInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
cacheInfo := util.GetCacheInfo()
|
||||
detailedCacheInfo := util.GetDetailedCacheInfo()
|
||||
|
||||
// Separate historical and current rates
|
||||
historicalRates := make(map[string]interface{})
|
||||
currentRates := make(map[string]interface{})
|
||||
|
||||
for key, cached := range detailedCacheInfo {
|
||||
rateInfo := map[string]interface{}{
|
||||
"rate": cached.Rate,
|
||||
"timestamp": cached.Timestamp,
|
||||
"date": cached.Date,
|
||||
"age_hours": time.Since(cached.Timestamp).Hours(),
|
||||
}
|
||||
|
||||
if cached.Date == cached.Timestamp.Format("2006-01-02") {
|
||||
currentRates[key] = rateInfo
|
||||
} else {
|
||||
historicalRates[key] = rateInfo
|
||||
}
|
||||
}
|
||||
|
||||
response := map[string]interface{}{
|
||||
"status": "success",
|
||||
"cache_size": len(cacheInfo),
|
||||
"entries": cacheInfo,
|
||||
"status": "success",
|
||||
"total_entries": len(detailedCacheInfo),
|
||||
"historical_rates": historicalRates,
|
||||
"current_rates": currentRates,
|
||||
"historical_count": len(historicalRates),
|
||||
"current_count": len(currentRates),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user