halfway to moolah2

This commit is contained in:
Bel LaPointe
2023-10-27 21:28:31 -06:00
parent e36f08deba
commit dafac49126
4 changed files with 82 additions and 0 deletions

View File

@@ -54,6 +54,25 @@ func main() {
if *httpOutput != "" {
foo := func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api") {
switch r.URL.Path {
case "/api/transactions":
reqF := f
if queryF := r.URL.Query().Get("f"); queryF != "" {
reqF, err = ledger.NewFiles(queryF)
if err != nil {
panic(err)
}
}
deltas, err := reqF.Deltas()
if err != nil {
panic(err)
}
json.NewEncoder(w).Encode(map[string]any{
"deltas": deltas.Like(ledger.LikeAfter(time.Now().Add(-1 * time.Hour * 24 * 365 / 2).Format("2006-01"))),
"balances": deltas.Balances().Like("^AssetAccount:").WithBPIs(bpis),
})
return
}
} else if strings.HasPrefix(r.URL.Path, "/transactions") {
f, err := os.Open("./public/transactions.html")
if err != nil {