Compare commits

..

2 Commits

Author SHA1 Message Date
Bel LaPointe
af1b23731a gui CREATE button
All checks were successful
cicd / ci (push) Successful in 1m3s
2025-02-21 16:24:41 -07:00
Bel LaPointe
fcd7dd208c impl /api/create 2025-02-21 15:55:12 -07:00
2 changed files with 32 additions and 0 deletions

View File

@@ -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) {
var d = new Date()
const zeroPad = (num, places) => String(num).padStart(places, '0')
@@ -241,6 +250,11 @@
</details>
<details open>
<summary>Register</summary>
<form action="#" onsubmit="create(); return false;">
<button style="width: 100%">
CREATE
</button>
</form>
<div id="reg">
</div>
</details>

View File

@@ -75,6 +75,8 @@ func (router Router) API(w http.ResponseWriter, r *http.Request) {
router.APITransactions(w, r)
case "/api/amend":
router.APIAmend(w, r)
case "/api/create":
router.APICreate(w, r)
case "/api/trends":
router.APITrends(w, r)
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)
}
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) {
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)
return
}
req.Now.Name = strings.ReplaceAll(req.Now.Name, " ", "_")
if err := router.files.Amend(req.Old, req.Now); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)