Compare commits
2 Commits
9bbdeeae9c
...
af1b23731a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af1b23731a | ||
|
|
fcd7dd208c |
@@ -187,6 +187,15 @@
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create() {
|
||||||
|
http("POST", "/api/create", (body, status) => {
|
||||||
|
if (status != 200)
|
||||||
|
throw(`Unexpected status ${status}: ${body}`)
|
||||||
|
loadTransactions([])
|
||||||
|
load()
|
||||||
|
}, JSON.stringify({}))
|
||||||
|
}
|
||||||
|
|
||||||
function stage(who, contributesToHouse) {
|
function stage(who, contributesToHouse) {
|
||||||
var d = new Date()
|
var d = new Date()
|
||||||
const zeroPad = (num, places) => String(num).padStart(places, '0')
|
const zeroPad = (num, places) => String(num).padStart(places, '0')
|
||||||
@@ -241,6 +250,11 @@
|
|||||||
</details>
|
</details>
|
||||||
<details open>
|
<details open>
|
||||||
<summary>Register</summary>
|
<summary>Register</summary>
|
||||||
|
<form action="#" onsubmit="create(); return false;">
|
||||||
|
<button style="width: 100%">
|
||||||
|
CREATE
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
<div id="reg">
|
<div id="reg">
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ func (router Router) API(w http.ResponseWriter, r *http.Request) {
|
|||||||
router.APITransactions(w, r)
|
router.APITransactions(w, r)
|
||||||
case "/api/amend":
|
case "/api/amend":
|
||||||
router.APIAmend(w, r)
|
router.APIAmend(w, r)
|
||||||
|
case "/api/create":
|
||||||
|
router.APICreate(w, r)
|
||||||
case "/api/trends":
|
case "/api/trends":
|
||||||
router.APITrends(w, r)
|
router.APITrends(w, r)
|
||||||
case "/api/reg", "/api/bal":
|
case "/api/reg", "/api/bal":
|
||||||
@@ -225,6 +227,21 @@ func (router Router) APITrends(w http.ResponseWriter, r *http.Request) {
|
|||||||
pie("Median Monthly Spending (MORE detailed)", `Withdrawal:[0-9]*:[^:]*:[^:]*`, 10)
|
pie("Median Monthly Spending (MORE detailed)", `Withdrawal:[0-9]*:[^:]*:[^:]*`, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (router Router) APICreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
new := ledger.Delta{
|
||||||
|
Name: "TODO",
|
||||||
|
Date: time.Now().Format(`2006-01-02`),
|
||||||
|
Description: "TODO",
|
||||||
|
Currency: "$",
|
||||||
|
Value: 0.01,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := router.files.Add("HouseyMcHouseface:Withdrawal:0:TODO", new); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (router Router) APIAmend(w http.ResponseWriter, r *http.Request) {
|
func (router Router) APIAmend(w http.ResponseWriter, r *http.Request) {
|
||||||
b, _ := io.ReadAll(r.Body)
|
b, _ := io.ReadAll(r.Body)
|
||||||
|
|
||||||
@@ -236,6 +253,7 @@ func (router Router) APIAmend(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
req.Now.Name = strings.ReplaceAll(req.Now.Name, " ", "_")
|
||||||
|
|
||||||
if err := router.files.Amend(req.Old, req.Now); err != nil {
|
if err := router.files.Amend(req.Old, req.Now); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
|||||||
Reference in New Issue
Block a user