diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-19 01:21:28 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-19 02:09:49 +0900 |
| commit | 98974136648935143298c0e0a01714bb146909f1 (patch) | |
| tree | b42ad91ef652d4d86eb03d56cbda063caf0d0b78 /backend/admin/handler.go | |
| parent | 0ad3546aa69d2269e5d739e9b62bc956e95e7f6e (diff) | |
| download | iosdc-japan-2024-albatross-98974136648935143298c0e0a01714bb146909f1.tar.gz iosdc-japan-2024-albatross-98974136648935143298c0e0a01714bb146909f1.tar.zst iosdc-japan-2024-albatross-98974136648935143298c0e0a01714bb146909f1.zip | |
refactor(backend): do not hard-code base path
Diffstat (limited to 'backend/admin/handler.go')
| -rw-r--r-- | backend/admin/handler.go | 31 |
1 files changed, 20 insertions, 11 deletions
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") } |
