diff --git a/cmd/http/main.go b/cmd/http/main.go index c1b1d54..34e2ed0 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -71,16 +71,17 @@ func Main() { return } + reqF := f + if queryF := r.URL.Query().Get("f"); queryF != "" { + queryF = path.Join("http", queryF) + reqF, err = ledger.NewFiles(queryF) + if err != nil { + panic(err) + } + } + switch r.URL.Path { case "/api/transactions": - reqF := f - if queryF := r.URL.Query().Get("f"); queryF != "" { - queryF = path.Join("http", queryF) - reqF, err = ledger.NewFiles(queryF) - if err != nil { - panic(err) - } - } lastNLines, err := reqF.TempGetLastNLines(20) if err != nil { panic(err) @@ -104,7 +105,10 @@ func Main() { if err := json.NewDecoder(r.Body).Decode(&lines); err != nil { panic(err) } - http.Error(w, "not done yet", http.StatusNotImplemented) + if err := reqF.TempSetLastNLines(20, lines); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + } + w.WriteHeader(http.StatusResetContent) return } diff --git a/cmd/http/public/transactions.html b/cmd/http/public/transactions.html index cccf5b3..342e322 100644 --- a/cmd/http/public/transactions.html +++ b/cmd/http/public/transactions.html @@ -79,6 +79,7 @@ } function loadLastNLines(lastNLines) { var result = `