aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/admin/handler.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-20 20:09:05 +0900
committernsfisis <nsfisis@gmail.com>2025-03-20 20:09:05 +0900
commit4b5c0f0d1f9711b27ededbcdda785753325f04ea (patch)
treeb8d5e2006035af2481a9c9cd7e8300e2cd6e3cb8 /backend/admin/handler.go
parent1a08d06be929900fb8d8b61a1ac0611005c277e8 (diff)
downloadphperkaigi-2025-albatross-4b5c0f0d1f9711b27ededbcdda785753325f04ea.tar.gz
phperkaigi-2025-albatross-4b5c0f0d1f9711b27ededbcdda785753325f04ea.tar.zst
phperkaigi-2025-albatross-4b5c0f0d1f9711b27ededbcdda785753325f04ea.zip
feat(backend): add /admin/online-qualifying-ranking
Diffstat (limited to 'backend/admin/handler.go')
-rw-r--r--backend/admin/handler.go38
1 files changed, 38 insertions, 0 deletions
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,
+ })
+}