aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/admin
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-17 19:35:56 +0900
committernsfisis <nsfisis@gmail.com>2024-08-17 21:10:18 +0900
commit95dd5f0c346d10c9a9497daf88cd199ce71c8122 (patch)
tree6d3621b22cc44d7e93bc6a46b300479619d240d2 /backend/admin
parent48a70e06f54d81cdc6b0c22c2dcce8426b86decf (diff)
downloadphperkaigi-2025-albatross-95dd5f0c346d10c9a9497daf88cd199ce71c8122.tar.gz
phperkaigi-2025-albatross-95dd5f0c346d10c9a9497daf88cd199ce71c8122.tar.zst
phperkaigi-2025-albatross-95dd5f0c346d10c9a9497daf88cd199ce71c8122.zip
feat(backend): fetch user icon from fortee
Diffstat (limited to 'backend/admin')
-rw-r--r--backend/admin/handler.go26
-rw-r--r--backend/admin/templates/users.html3
2 files changed, 29 insertions, 0 deletions
diff --git a/backend/admin/handler.go b/backend/admin/handler.go
index 41eacd4..1b60de5 100644
--- a/backend/admin/handler.go
+++ b/backend/admin/handler.go
@@ -1,7 +1,9 @@
package admin
import (
+ "context"
"errors"
+ "log"
"net/http"
"strconv"
"time"
@@ -10,6 +12,7 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"github.com/labstack/echo/v4"
+ "github.com/nsfisis/iosdc-japan-2024-albatross/backend/account"
"github.com/nsfisis/iosdc-japan-2024-albatross/backend/auth"
"github.com/nsfisis/iosdc-japan-2024-albatross/backend/db"
)
@@ -58,6 +61,7 @@ func (h *Handler) RegisterHandlers(g *echo.Group) {
g.GET("/dashboard", h.getDashboard)
g.GET("/users", h.getUsers)
g.GET("/users/:userID", h.getUserEdit)
+ g.POST("/users/:userID/fetch-icon", h.postUserFetchIcon)
g.GET("/games", h.getGames)
g.GET("/games/:gameID", h.getGameEdit)
g.POST("/games/:gameID", h.postGameEdit)
@@ -116,6 +120,28 @@ func (h *Handler) getUserEdit(c echo.Context) error {
})
}
+func (h *Handler) postUserFetchIcon(c echo.Context) error {
+ userID, err := strconv.Atoi(c.Param("userID"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Invalid user id")
+ }
+ row, err := h.q.GetUserByID(c.Request().Context(), int32(userID))
+ if err != nil {
+ if errors.Is(err, pgx.ErrNoRows) {
+ return echo.NewHTTPError(http.StatusNotFound)
+ }
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+ go func() {
+ err := account.FetchIcon(context.Background(), h.q, int(row.UserID))
+ if err != nil {
+ log.Printf("%v", err)
+ // The failure is intentionally ignored. Retry manually if needed.
+ }
+ }()
+ return c.Redirect(http.StatusSeeOther, "/iosdc-japan/2024/code-battle/admin/users")
+}
+
func (h *Handler) getGames(c echo.Context) error {
rows, err := h.q.ListGames(c.Request().Context())
if err != nil {
diff --git a/backend/admin/templates/users.html b/backend/admin/templates/users.html
index 3543457..3dc03c0 100644
--- a/backend/admin/templates/users.html
+++ b/backend/admin/templates/users.html
@@ -11,6 +11,9 @@
<a href="/iosdc-japan/2024/code-battle/admin/users/{{ .UserID }}">
{{ .DisplayName }} (id={{ .UserID }} username={{ .Username }}){{ if .IsAdmin }} <em>admin</em>{{ end }}
</a>
+ <form method="post" action="/iosdc-japan/2024/code-battle/admin/users/{{ .UserID }}/fetch-icon">
+ <button type="submit">Fetch Icon</button>
+ </form>
</li>
{{ end }}
</ul>