From 06361c9066012139d2a74c391c33a020f2087093 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 6 Apr 2022 19:51:12 +0000 Subject: [PATCH 1/5] Remove clean-negative --- server/admin.go | 46 -------------------------------------- server/http.go | 1 - web/src/pages/Settings.vue | 18 --------------- 3 files changed, 65 deletions(-) diff --git a/server/admin.go b/server/admin.go index 7d19da3..b3a5b81 100644 --- a/server/admin.go +++ b/server/admin.go @@ -64,49 +64,3 @@ func (h *Handler) clearBudget(c *gin.Context) { h.clearBudgetData(c, budgetUUID) } - -func (h *Handler) cleanNegativeBudget(c *gin.Context) { - /*budgetID := c.Param("budgetid") - budgetUUID, err := uuid.Parse(budgetID) - if err != nil { - c.Redirect(http.StatusTemporaryRedirect, "/login") - return - }*/ - - /*min_date, err := h.Service.GetFirstActivity(c.Request.Context(), budgetUUID) - date := getFirstOfMonthTime(min_date) - for { - nextDate := date.AddDate(0, 1, 0) - params := postgres.GetCategoriesWithBalanceParams{ - BudgetID: budgetUUID, - ToDate: nextDate, - FromDate: date, - } - categories, err := h.Service.GetCategoriesWithBalance(c.Request.Context(), params) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, err) - return - } - - for _, category := range categories { - available := category.Available.GetFloat64() - if available >= 0 { - continue - } - var negativeAvailable postgres.Numeric - negativeAvailable.Set(-available) - createAssignment := postgres.CreateAssignmentParams{ - Date: nextDate.AddDate(0, 0, -1), - Amount: negativeAvailable, - CategoryID: category.ID, - } - h.Service.CreateAssignment(c.Request.Context(), createAssignment) - } - - if nextDate.Before(time.Now()) { - date = nextDate - } else { - break - } - }*/ -} diff --git a/server/http.go b/server/http.go index e958687..46f994d 100644 --- a/server/http.go +++ b/server/http.go @@ -72,7 +72,6 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { budget.POST("/:budgetid/export/ynab/transactions", h.exportYNABTransactions) budget.POST("/:budgetid/export/ynab/assignments", h.exportYNABAssignments) budget.POST("/:budgetid/settings/clear", h.clearBudget) - budget.POST("/:budgetid/settings/clean-negative", h.cleanNegativeBudget) transaction := authenticated.Group("/transaction") transaction.POST("/new", h.newTransaction) diff --git a/web/src/pages/Settings.vue b/web/src/pages/Settings.vue index dd2b55d..55a9a94 100644 --- a/web/src/pages/Settings.vue +++ b/web/src/pages/Settings.vue @@ -44,9 +44,6 @@ function deleteBudget() { function clearBudget() { POST("/budget/" + CurrentBudgetID.value + "/settings/clear", null) }; -function cleanNegative() { - // Fix all historic negative category-balances -}; function ynabImport() { if (transactionsFile.value == undefined || assignmentsFile.value == undefined) return @@ -109,21 +106,6 @@ function ynabExport() { Delete budget - -

- Fix all historic negative category-balances -

-

- This restores YNABs functionality, that would substract any - overspent categories' balances from next months inflows. -

- -

Import YNAB Budget -- 2.47.2 From 324e86bbf0775f658f40c29412fdaa32b5a3294c Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 6 Apr 2022 19:51:20 +0000 Subject: [PATCH 2/5] Remove dashboard API --- server/dashboard.go | 25 ------------------------- server/http.go | 1 - 2 files changed, 26 deletions(-) delete mode 100644 server/dashboard.go diff --git a/server/dashboard.go b/server/dashboard.go deleted file mode 100644 index 64667d8..0000000 --- a/server/dashboard.go +++ /dev/null @@ -1,25 +0,0 @@ -package server - -import ( - "net/http" - - "git.javil.eu/jacob1123/budgeteer/postgres" - "github.com/gin-gonic/gin" -) - -func (h *Handler) dashboard(c *gin.Context) { - userID := MustGetToken(c).GetID() - budgets, err := h.Service.GetBudgetsForUser(c.Request.Context(), userID) - if err != nil { - return - } - - d := DashboardData{ - Budgets: budgets, - } - c.JSON(http.StatusOK, d) -} - -type DashboardData struct { - Budgets []postgres.Budget -} diff --git a/server/http.go b/server/http.go index 46f994d..c691291 100644 --- a/server/http.go +++ b/server/http.go @@ -54,7 +54,6 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { authenticated := api.Group("") authenticated.Use(h.verifyLoginWithForbidden) - authenticated.GET("/dashboard", h.dashboard) authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount) authenticated.POST("/account/:accountid/reconcile", h.reconcileTransactions) authenticated.POST("/account/:accountid", h.editAccount) -- 2.47.2 From dd16abcf2a5d5bde9244f38b2ee97b4d853767c1 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 6 Apr 2022 19:51:54 +0000 Subject: [PATCH 3/5] Remove GET for login route --- server/http.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/http.go b/server/http.go index c691291..10ccea4 100644 --- a/server/http.go +++ b/server/http.go @@ -48,7 +48,6 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { api := router.Group("/api/v1") anonymous := api.Group("/user") - anonymous.GET("/login", func(c *gin.Context) { c.Redirect(http.StatusPermanentRedirect, "/login") }) anonymous.POST("/login", h.loginPost) anonymous.POST("/register", h.registerPost) -- 2.47.2 From c9f67ae9b9cacf63692945c73245daf7e18c96f6 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 6 Apr 2022 19:59:41 +0000 Subject: [PATCH 4/5] Split new and update-transaction into separate methods --- server/http.go | 42 ++++++++++++++++++++++-------------------- server/transaction.go | 27 ++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/server/http.go b/server/http.go index 10ccea4..b96a645 100644 --- a/server/http.go +++ b/server/http.go @@ -52,28 +52,30 @@ func (h *Handler) LoadRoutes(router *gin.Engine) { anonymous.POST("/register", h.registerPost) authenticated := api.Group("") - authenticated.Use(h.verifyLoginWithForbidden) - authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount) - authenticated.POST("/account/:accountid/reconcile", h.reconcileTransactions) - authenticated.POST("/account/:accountid", h.editAccount) - authenticated.GET("/admin/clear-database", h.clearDatabase) + { + authenticated.Use(h.verifyLoginWithForbidden) + authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount) + authenticated.POST("/account/:accountid/reconcile", h.reconcileTransactions) + authenticated.POST("/account/:accountid", h.editAccount) + authenticated.GET("/admin/clear-database", h.clearDatabase) - budget := authenticated.Group("/budget") - budget.POST("/new", h.newBudget) - budget.GET("/:budgetid", h.budgeting) - budget.GET("/:budgetid/:year/:month", h.budgetingForMonth) - budget.POST("/:budgetid/category/:categoryid/:year/:month", h.setCategoryAssignment) - budget.GET("/:budgetid/autocomplete/payees", h.autocompletePayee) - budget.GET("/:budgetid/autocomplete/categories", h.autocompleteCategories) - budget.DELETE("/:budgetid", h.deleteBudget) - budget.POST("/:budgetid/import/ynab", h.importYNAB) - budget.POST("/:budgetid/export/ynab/transactions", h.exportYNABTransactions) - budget.POST("/:budgetid/export/ynab/assignments", h.exportYNABAssignments) - budget.POST("/:budgetid/settings/clear", h.clearBudget) + budget := authenticated.Group("/budget") + budget.POST("/new", h.newBudget) + budget.GET("/:budgetid", h.budget) + budget.GET("/:budgetid/:year/:month", h.budgetingForMonth) + budget.POST("/:budgetid/category/:categoryid/:year/:month", h.setCategoryAssignment) + budget.GET("/:budgetid/autocomplete/payees", h.autocompletePayee) + budget.GET("/:budgetid/autocomplete/categories", h.autocompleteCategories) + budget.DELETE("/:budgetid", h.deleteBudget) + budget.POST("/:budgetid/import/ynab", h.importYNAB) + budget.POST("/:budgetid/export/ynab/transactions", h.exportYNABTransactions) + budget.POST("/:budgetid/export/ynab/assignments", h.exportYNABAssignments) + budget.POST("/:budgetid/settings/clear", h.clearBudget) - transaction := authenticated.Group("/transaction") - transaction.POST("/new", h.newTransaction) - transaction.POST("/:transactionid", h.newTransaction) + transaction := authenticated.Group("/transaction") + transaction.POST("/new", h.newTransaction) + transaction.POST("/:transactionid", h.updateTransaction) + } } func (h *Handler) ServeStatic(c *gin.Context) { diff --git a/server/transaction.go b/server/transaction.go index a9cce82..0a959ba 100644 --- a/server/transaction.go +++ b/server/transaction.go @@ -27,7 +27,7 @@ type NewTransactionPayload struct { State string `json:"state"` } -func (h *Handler) newTransaction(c *gin.Context) { +func (h *Handler) updateTransaction(c *gin.Context) { var payload NewTransactionPayload err := c.BindJSON(&payload) if err != nil { @@ -42,8 +42,26 @@ func (h *Handler) newTransaction(c *gin.Context) { } transactionID := c.Param("transactionid") - if transactionID != "" { - h.UpdateTransaction(payload, amount, transactionID, c) + transactionUUID, err := uuid.Parse(transactionID) + if err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"transactionid missing from URL"}) + return + } + + h.UpdateTransaction(payload, amount, transactionUUID, c) +} + +func (h *Handler) newTransaction(c *gin.Context) { + var payload NewTransactionPayload + err := c.BindJSON(&payload) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + return + } + + amount, err := numeric.Parse(payload.Amount) + if err != nil { + c.AbortWithError(http.StatusBadRequest, fmt.Errorf("amount: %w", err)) return } @@ -87,8 +105,7 @@ func (h *Handler) newTransaction(c *gin.Context) { c.JSON(http.StatusOK, transaction) } -func (h *Handler) UpdateTransaction(payload NewTransactionPayload, amount numeric.Numeric, transactionID string, c *gin.Context) { - transactionUUID := uuid.MustParse(transactionID) +func (h *Handler) UpdateTransaction(payload NewTransactionPayload, amount numeric.Numeric, transactionUUID uuid.UUID, c *gin.Context) { if amount.IsZero() { err := h.Service.DeleteTransaction(c.Request.Context(), transactionUUID) if err != nil { -- 2.47.2 From e8849aa45a3b4d4d118b7af79c3d9bd7be1b7ab5 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 6 Apr 2022 20:01:41 +0000 Subject: [PATCH 5/5] Rename budgeting to budget --- server/account.go | 2 +- server/budgeting.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/account.go b/server/account.go index 65b0908..d92746c 100644 --- a/server/account.go +++ b/server/account.go @@ -69,5 +69,5 @@ func (h *Handler) editAccount(c *gin.Context) { return } - h.returnBudgetingData(c, account.BudgetID) + h.getBudget(c, account.BudgetID) } diff --git a/server/budgeting.go b/server/budgeting.go index b8341b7..814d94b 100644 --- a/server/budgeting.go +++ b/server/budgeting.go @@ -126,7 +126,7 @@ type BudgetingResponse struct { Budget postgres.Budget } -func (h *Handler) budgeting(c *gin.Context) { +func (h *Handler) budget(c *gin.Context) { budgetID := c.Param("budgetid") budgetUUID, err := uuid.Parse(budgetID) if err != nil { @@ -134,10 +134,10 @@ func (h *Handler) budgeting(c *gin.Context) { return } - h.returnBudgetingData(c, budgetUUID) + h.getBudget(c, budgetUUID) } -func (h *Handler) returnBudgetingData(c *gin.Context, budgetUUID uuid.UUID) { +func (h *Handler) getBudget(c *gin.Context, budgetUUID uuid.UUID) { budget, err := h.Service.GetBudget(c.Request.Context(), budgetUUID) if err != nil { c.AbortWithError(http.StatusNotFound, err) -- 2.47.2