Add admin routes
This commit is contained in:
parent
4011f3cace
commit
11d20eeb66
@ -32,12 +32,3 @@ func (h *Handler) accounts(c *gin.Context) {
|
|||||||
|
|
||||||
c.HTML(http.StatusOK, "accounts.html", d)
|
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)
|
|
||||||
}
|
|
||||||
|
31
http/admin.go
Normal file
31
http/admin.go
Normal file
@ -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)
|
||||||
|
}
|
@ -54,6 +54,7 @@ func (h *Handler) Serve() {
|
|||||||
authenticatedFrontend.GET("/budget/:budgetid", h.budget)
|
authenticatedFrontend.GET("/budget/:budgetid", h.budget)
|
||||||
authenticatedFrontend.GET("/budget/:budgetid/accounts", h.accounts)
|
authenticatedFrontend.GET("/budget/:budgetid/accounts", h.accounts)
|
||||||
authenticatedFrontend.GET("/admin", h.admin)
|
authenticatedFrontend.GET("/admin", h.admin)
|
||||||
|
authenticatedFrontend.GET("/admin/clear-database", h.clearDatabase)
|
||||||
}
|
}
|
||||||
api := router.Group("/api/v1")
|
api := router.Group("/api/v1")
|
||||||
{
|
{
|
||||||
|
14
web/admin.html
Normal file
14
web/admin.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
{{define "title"}}
|
||||||
|
Admin
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{template "base" .}}
|
||||||
|
|
||||||
|
{{define "main"}}
|
||||||
|
<h1>Danger Zone</h1>
|
||||||
|
<div class="budget-item">
|
||||||
|
<button>Clear database</button>
|
||||||
|
<p>This removes all data and starts from scratch. Not undoable!</p>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
Loading…
x
Reference in New Issue
Block a user