Implement YNAB Import in Vue
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type BudgetingData struct {
|
||||
@ -60,8 +61,29 @@ func getDate(c *gin.Context) (time.Time, error) {
|
||||
}
|
||||
|
||||
func (h *Handler) budgeting(c *gin.Context) {
|
||||
alwaysNeededData := c.MustGet("data").(AlwaysNeededData)
|
||||
budgetUUID := alwaysNeededData.Budget.ID
|
||||
budgetID := c.Param("budgetid")
|
||||
budgetUUID, err := uuid.Parse(budgetID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL"))
|
||||
return
|
||||
}
|
||||
|
||||
budget, err := h.Service.GetBudget(c.Request.Context(), budgetUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
||||
accounts, err := h.Service.GetAccountsWithBalance(c.Request.Context(), budgetUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
data := AlwaysNeededData{
|
||||
Accounts: accounts,
|
||||
Budget: budget,
|
||||
}
|
||||
|
||||
firstOfMonth, err := getDate(c)
|
||||
if err != nil {
|
||||
@ -72,7 +94,7 @@ func (h *Handler) budgeting(c *gin.Context) {
|
||||
firstOfNextMonth := firstOfMonth.AddDate(0, 1, 0)
|
||||
firstOfPreviousMonth := firstOfMonth.AddDate(0, -1, 0)
|
||||
d := BudgetingData{
|
||||
AlwaysNeededData: alwaysNeededData,
|
||||
AlwaysNeededData: data,
|
||||
Date: firstOfMonth,
|
||||
Next: firstOfNextMonth,
|
||||
Previous: firstOfPreviousMonth,
|
||||
@ -87,13 +109,12 @@ func (h *Handler) budgeting(c *gin.Context) {
|
||||
}
|
||||
|
||||
// skip everything in the future
|
||||
categoriesWithBalance, moneyUsed, err := h.calculateBalances(c, alwaysNeededData.Budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances)
|
||||
categoriesWithBalance, moneyUsed, err := h.calculateBalances(c, data.Budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
d.Categories = categoriesWithBalance
|
||||
|
||||
data := c.MustGet("data").(AlwaysNeededData)
|
||||
var availableBalance float64 = 0
|
||||
for _, cat := range categories {
|
||||
if cat.ID != data.Budget.IncomeCategoryID {
|
||||
|
Reference in New Issue
Block a user