impl /api/create

main
Bel LaPointe 2025-02-21 15:55:12 -07:00
parent 9bbdeeae9c
commit fcd7dd208c
1 changed files with 18 additions and 0 deletions

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)