Implement assignment import and clear of budget

This commit is contained in:
2021-12-07 15:18:47 +00:00
parent 6f4bff929e
commit 0b0b20c5ec
12 changed files with 249 additions and 23 deletions

View File

@ -1,6 +1,7 @@
package http
import (
"fmt"
"io/fs"
"net/http"
"time"
@ -57,6 +58,7 @@ func (h *Handler) Serve() {
withBudget.Use(h.verifyLoginWithRedirect)
withBudget.Use(h.getImportantData)
withBudget.GET("/budget/:budgetid", h.budgeting)
withBudget.GET("/budget/:budgetid/clear", h.clearBudget)
withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting)
withBudget.GET("/budget/:budgetid/all-accounts", h.budget)
withBudget.GET("/budget/:budgetid/accounts", h.accounts)
@ -86,21 +88,9 @@ func (h *Handler) Serve() {
}
func (h *Handler) importYNAB(c *gin.Context) {
transactionsFile, err := c.FormFile("transactions")
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
transactions, err := transactionsFile.Open()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
budgetID, succ := c.GetPostForm("budget_id")
if !succ {
c.AbortWithError(http.StatusBadRequest, err)
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("no budget_id specified"))
return
}
@ -116,7 +106,37 @@ func (h *Handler) importYNAB(c *gin.Context) {
return
}
err = ynab.Import(transactions)
transactionsFile, err := c.FormFile("transactions")
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
transactions, err := transactionsFile.Open()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
err = ynab.ImportTransactions(transactions)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
assignmentsFile, err := c.FormFile("assignments")
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
assignments, err := assignmentsFile.Open()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
err = ynab.ImportAssignments(assignments)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return