diff --git a/http/accounts.go b/http/accounts.go index 99251c9..7c7383d 100644 --- a/http/accounts.go +++ b/http/accounts.go @@ -32,12 +32,3 @@ func (h *Handler) accounts(c *gin.Context) { c.HTML(http.StatusOK, "accounts.html", d) } - -type AdminData struct { -} - -func (h *Handler) admin(c *gin.Context) { - d := AdminData{} - - c.HTML(http.StatusOK, "accounts.html", d) -} diff --git a/http/admin.go b/http/admin.go new file mode 100644 index 0000000..fe00bb3 --- /dev/null +++ b/http/admin.go @@ -0,0 +1,31 @@ +package http + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "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.Down(h.Service.LegacyDB, "schema"); err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + } + + if err := goose.Up(h.Service.LegacyDB, "schema"); err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + } + + c.HTML(http.StatusOK, "admin.html", d) +} diff --git a/http/http.go b/http/http.go index 9958082..b4ddae8 100644 --- a/http/http.go +++ b/http/http.go @@ -54,6 +54,7 @@ func (h *Handler) Serve() { authenticatedFrontend.GET("/budget/:budgetid", h.budget) authenticatedFrontend.GET("/budget/:budgetid/accounts", h.accounts) authenticatedFrontend.GET("/admin", h.admin) + authenticatedFrontend.GET("/admin/clear-database", h.clearDatabase) } api := router.Group("/api/v1") { diff --git a/web/admin.html b/web/admin.html new file mode 100644 index 0000000..afd8e04 --- /dev/null +++ b/web/admin.html @@ -0,0 +1,14 @@ + +{{define "title"}} + Admin +{{end}} + +{{template "base" .}} + +{{define "main"}} +
This removes all data and starts from scratch. Not undoable!
+