From 98974136648935143298c0e0a01714bb146909f1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 19 Aug 2024 01:21:28 +0900 Subject: refactor(backend): do not hard-code base path --- backend/admin/handler.go | 31 ++++++++++++++++++++----------- backend/admin/templates/base.html | 6 +++--- backend/admin/templates/dashboard.html | 6 +++--- backend/admin/templates/game_edit.html | 2 +- backend/admin/templates/games.html | 6 +++--- backend/admin/templates/user_edit.html | 2 +- backend/admin/templates/users.html | 6 +++--- 7 files changed, 34 insertions(+), 25 deletions(-) (limited to 'backend') diff --git a/backend/admin/handler.go b/backend/admin/handler.go index 1b60de5..17341d5 100644 --- a/backend/admin/handler.go +++ b/backend/admin/handler.go @@ -17,6 +17,10 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" ) +const ( + basePath = "/iosdc-japan/2024/code-battle" +) + var jst = time.FixedZone("Asia/Tokyo", 9*60*60) type Handler struct { @@ -40,11 +44,11 @@ func newAdminMiddleware() echo.MiddlewareFunc { return func(c echo.Context) error { jwt, err := c.Cookie("albatross_token") if err != nil { - return c.Redirect(http.StatusSeeOther, "/iosdc-japan/2024/code-battle/login") + return c.Redirect(http.StatusSeeOther, basePath+"/login") } claims, err := auth.ParseJWT(jwt.Value) if err != nil { - return c.Redirect(http.StatusSeeOther, "/iosdc-japan/2024/code-battle/login") + return c.Redirect(http.StatusSeeOther, basePath+"/login") } if !claims.IsAdmin { return echo.NewHTTPError(http.StatusForbidden) @@ -69,7 +73,8 @@ func (h *Handler) RegisterHandlers(g *echo.Group) { func (h *Handler) getDashboard(c echo.Context) error { return c.Render(http.StatusOK, "dashboard", echo.Map{ - "Title": "Dashboard", + "BasePath": basePath, + "Title": "Dashboard", }) } @@ -90,8 +95,9 @@ func (h *Handler) getUsers(c echo.Context) error { } return c.Render(http.StatusOK, "users", echo.Map{ - "Title": "Users", - "Users": users, + "BasePath": basePath, + "Title": "Users", + "Users": users, }) } @@ -109,7 +115,8 @@ func (h *Handler) getUserEdit(c echo.Context) error { } return c.Render(http.StatusOK, "user_edit", echo.Map{ - "Title": "User Edit", + "BasePath": basePath, + "Title": "User Edit", "User": echo.Map{ "UserID": row.UserID, "Username": row.Username, @@ -139,7 +146,7 @@ func (h *Handler) postUserFetchIcon(c echo.Context) error { // The failure is intentionally ignored. Retry manually if needed. } }() - return c.Redirect(http.StatusSeeOther, "/iosdc-japan/2024/code-battle/admin/users") + return c.Redirect(http.StatusSeeOther, basePath+"/admin/users") } func (h *Handler) getGames(c echo.Context) error { @@ -165,8 +172,9 @@ func (h *Handler) getGames(c echo.Context) error { } return c.Render(http.StatusOK, "games", echo.Map{ - "Title": "Games", - "Games": games, + "BasePath": basePath, + "Title": "Games", + "Games": games, }) } @@ -189,7 +197,8 @@ func (h *Handler) getGameEdit(c echo.Context) error { } return c.Render(http.StatusOK, "game_edit", echo.Map{ - "Title": "Game Edit", + "BasePath": basePath, + "Title": "Game Edit", "Game": echo.Map{ "GameID": row.GameID, "GameType": row.GameType, @@ -278,5 +287,5 @@ func (h *Handler) postGameEdit(c echo.Context) error { } } - return c.Redirect(http.StatusSeeOther, c.Request().URL.Path) + return c.Redirect(http.StatusSeeOther, basePath+"/admin/games") } diff --git a/backend/admin/templates/base.html b/backend/admin/templates/base.html index 49e2066..8e71194 100644 --- a/backend/admin/templates/base.html +++ b/backend/admin/templates/base.html @@ -2,9 +2,9 @@ ADMIN {{ .Title }} | iOSDC Japan 2024 Albatross.swift - - - + + +
diff --git a/backend/admin/templates/dashboard.html b/backend/admin/templates/dashboard.html index b2037cb..15b10ff 100644 --- a/backend/admin/templates/dashboard.html +++ b/backend/admin/templates/dashboard.html @@ -2,12 +2,12 @@ {{ define "content" }}

- Users + Users

- Games + Games

-
+
{{ end }} diff --git a/backend/admin/templates/game_edit.html b/backend/admin/templates/game_edit.html index 66f3b9e..48a0625 100644 --- a/backend/admin/templates/game_edit.html +++ b/backend/admin/templates/game_edit.html @@ -1,7 +1,7 @@ {{ template "base.html" . }} {{ define "breadcrumb" }} -Dashboard | Games +Dashboard | Games {{ end }} {{ define "content" }} diff --git a/backend/admin/templates/games.html b/backend/admin/templates/games.html index 6d6bd68..9dd9cae 100644 --- a/backend/admin/templates/games.html +++ b/backend/admin/templates/games.html @@ -1,20 +1,20 @@ {{ template "base.html" . }} {{ define "breadcrumb" }} -Dashboard +Dashboard {{ end }} {{ define "content" }}