From 4b5c0f0d1f9711b27ededbcdda785753325f04ea Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 20 Mar 2025 20:09:05 +0900 Subject: feat(backend): add /admin/online-qualifying-ranking --- backend/admin/handler.go | 38 ++++++++++++++++++++++ backend/admin/templates/dashboard.html | 3 ++ .../admin/templates/online_qualifying_ranking.html | 31 ++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 backend/admin/templates/online_qualifying_ranking.html (limited to 'backend/admin') diff --git a/backend/admin/handler.go b/backend/admin/handler.go index 8daead0..161f85c 100644 --- a/backend/admin/handler.go +++ b/backend/admin/handler.go @@ -63,6 +63,7 @@ func (h *Handler) RegisterHandlers(g *echo.Group) { g.GET("/games/:gameID", h.getGameEdit) g.POST("/games/:gameID", h.postGameEdit) g.POST("/games/:gameID/start", h.postGameStart) + g.GET("/online-qualifying-ranking", h.getOnlineQualifyingRanking) } func (h *Handler) getDashboard(c echo.Context) error { @@ -388,3 +389,40 @@ func (h *Handler) postGameStart(c echo.Context) error { return c.Redirect(http.StatusSeeOther, basePath+"/admin/games") } + +func (h *Handler) getOnlineQualifyingRanking(c echo.Context) error { + game1, err := strconv.Atoi(c.QueryParam("game_1")) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, "Invalid game_1") + } + game2, err := strconv.Atoi(c.QueryParam("game_2")) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, "Invalid game_2") + } + + rows, err := h.q.GetQualifyingRanking(c.Request().Context(), db.GetQualifyingRankingParams{ + GameID: int32(game1), + GameID_2: int32(game2), + }) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + + entries := make([]echo.Map, len(rows)) + for i, r := range rows { + entries[i] = echo.Map{ + "Rank": i + 1, + "Username": r.Username, + "Score1": r.CodeSize1, + "Score2": r.CodeSize2, + "TotalScore": r.TotalCodeSize, + "SubmittedAt1": r.SubmittedAt1.Time.In(jst).Format("2006-01-02T15:04"), + "SubmittedAt2": r.SubmittedAt2.Time.In(jst).Format("2006-01-02T15:04"), + } + } + return c.Render(http.StatusOK, "online_qualifying_ranking", echo.Map{ + "BasePath": basePath, + "Title": "Online Qualifying Ranking", + "Entries": entries, + }) +} diff --git a/backend/admin/templates/dashboard.html b/backend/admin/templates/dashboard.html index 15b10ff..2d030ef 100644 --- a/backend/admin/templates/dashboard.html +++ b/backend/admin/templates/dashboard.html @@ -7,6 +7,9 @@

Games

+

+ Online Qualifying Ranking +

diff --git a/backend/admin/templates/online_qualifying_ranking.html b/backend/admin/templates/online_qualifying_ranking.html new file mode 100644 index 0000000..3b00046 --- /dev/null +++ b/backend/admin/templates/online_qualifying_ranking.html @@ -0,0 +1,31 @@ +{{ template "base.html" . }} + +{{ define "breadcrumb" }} +Dashboard +{{ end }} + +{{ define "content" }} + + + + + + + + + + + {{ range .Entries }} + + + + + + + + + + {{ end }} + +
順位プレイヤースコア提出時刻
{{ .Rank }}{{ .Username }}{{ .Score1 }}{{ .Score2 }}{{ .TotalScore }}{{ .SubmittedAt1 }}{{ .SubmittedAt2 }}
+{{ end }} -- cgit v1.2.3-70-g09d2