From 0ad97ce4ff482cb487f0fe5e4db9c2fdf0c5d885 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 26 Jan 2022 20:22:39 +0000 Subject: [PATCH] Remove unused HTML endpoints --- http/account.go | 38 -------------------------------------- http/accounts.go | 19 ------------------- http/admin.go | 26 -------------------------- http/http.go | 9 +-------- http/session.go | 18 ------------------ 5 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 http/accounts.go diff --git a/http/account.go b/http/account.go index 74c7c4b..1417661 100644 --- a/http/account.go +++ b/http/account.go @@ -15,44 +15,6 @@ type AccountData struct { Transactions []postgres.GetTransactionsForAccountRow } -func (h *Handler) account(c *gin.Context) { - data := c.MustGet("data").(AlwaysNeededData) - - accountID := c.Param("accountid") - accountUUID, err := uuid.Parse(accountID) - if err != nil { - c.Redirect(http.StatusTemporaryRedirect, "/login") - return - } - - account, err := h.Service.GetAccount(c.Request.Context(), accountUUID) - if err != nil { - c.AbortWithError(http.StatusNotFound, err) - return - } - - categories, err := h.Service.GetCategories(c.Request.Context(), data.Budget.ID) - if err != nil { - c.AbortWithError(http.StatusNotFound, err) - return - } - - transactions, err := h.Service.GetTransactionsForAccount(c.Request.Context(), accountUUID) - if err != nil { - c.AbortWithError(http.StatusNotFound, err) - return - } - - d := AccountData{ - data, - &account, - categories, - transactions, - } - - c.HTML(http.StatusOK, "account.html", d) -} - func (h *Handler) transactionsForAccount(c *gin.Context) { accountID := c.Param("accountid") accountUUID, err := uuid.Parse(accountID) diff --git a/http/accounts.go b/http/accounts.go deleted file mode 100644 index 20d833c..0000000 --- a/http/accounts.go +++ /dev/null @@ -1,19 +0,0 @@ -package http - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -type AccountsData struct { - AlwaysNeededData -} - -func (h *Handler) accounts(c *gin.Context) { - d := AccountsData{ - c.MustGet("data").(AlwaysNeededData), - } - - c.HTML(http.StatusOK, "accounts.html", d) -} diff --git a/http/admin.go b/http/admin.go index ee1d600..852c97c 100644 --- a/http/admin.go +++ b/http/admin.go @@ -9,18 +9,7 @@ import ( "github.com/pressly/goose/v3" ) -type AdminData struct { -} - -func (h *Handler) admin(c *gin.Context) { - d := AdminData{} - - c.HTML(http.StatusOK, "admin.html", d) -} - func (h *Handler) clearDatabase(c *gin.Context) { - d := AdminData{} - if err := goose.Reset(h.Service.DB, "schema"); err != nil { c.AbortWithError(http.StatusInternalServerError, err) } @@ -28,20 +17,6 @@ func (h *Handler) clearDatabase(c *gin.Context) { if err := goose.Up(h.Service.DB, "schema"); err != nil { c.AbortWithError(http.StatusInternalServerError, err) } - - c.HTML(http.StatusOK, "admin.html", d) -} - -type SettingsData struct { - AlwaysNeededData -} - -func (h *Handler) settings(c *gin.Context) { - d := SettingsData{ - c.MustGet("data").(AlwaysNeededData), - } - - c.HTML(http.StatusOK, "settings.html", d) } func (h *Handler) clearBudget(c *gin.Context) { @@ -113,5 +88,4 @@ func (h *Handler) cleanNegativeBudget(c *gin.Context) { break } }*/ - } diff --git a/http/http.go b/http/http.go index a31c248..b8d63de 100644 --- a/http/http.go +++ b/http/http.go @@ -43,22 +43,14 @@ func (h *Handler) Serve() { }, ) - router.GET("/login", h.login) - router.GET("/register", h.register) - withLogin := router.Group("") withLogin.Use(h.verifyLoginWithRedirect) - withLogin.GET("/admin", h.admin) - withLogin.GET("/admin/clear-database", h.clearDatabase) withBudget := router.Group("") withBudget.Use(h.verifyLoginWithForbidden) withBudget.Use(h.getImportantData) withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting) withBudget.GET("/budget/:budgetid/all-accounts", h.allAccounts) - withBudget.GET("/budget/:budgetid/accounts", h.accounts) - withBudget.GET("/budget/:budgetid/account/:accountid", h.account) - withBudget.GET("/budget/:budgetid/settings", h.settings) withBudget.GET("/budget/:budgetid/settings/clear", h.clearBudget) withBudget.GET("/budget/:budgetid/settings/clean-negative", h.cleanNegativeBudget) withBudget.GET("/budget/:budgetid/transaction/:transactionid", h.transaction) @@ -74,6 +66,7 @@ func (h *Handler) Serve() { authenticated.Use(h.verifyLoginWithForbidden) authenticated.GET("/dashboard", h.dashboard) authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount) + authenticated.GET("/admin/clear-database", h.clearDatabase) withBudget2 := authenticated.Group("") withBudget2.Use(h.getImportantData) diff --git a/http/session.go b/http/session.go index 9fa585d..32506f7 100644 --- a/http/session.go +++ b/http/session.go @@ -45,24 +45,6 @@ func (h *Handler) verifyLoginWithRedirect(c *gin.Context) { c.Next() } -func (h *Handler) login(c *gin.Context) { - if _, err := h.verifyLogin(c); err == nil { - c.Redirect(http.StatusTemporaryRedirect, "/dashboard") - return - } - - c.HTML(http.StatusOK, "login.html", nil) -} - -func (h *Handler) register(c *gin.Context) { - if _, err := h.verifyLogin(c); err == nil { - c.Redirect(http.StatusTemporaryRedirect, "/dashboard") - return - } - - c.HTML(http.StatusOK, "register.html", nil) -} - type loginInformation struct { Password string `json:"password"` User string `json:"user"`