aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-12 03:10:46 +0900
committernsfisis <nsfisis@gmail.com>2025-03-12 03:10:46 +0900
commit27168df997c298e871d34e58fdc726bf2e8a4954 (patch)
tree3bbd0db1eef071a9bd04d2d39cc92a01e5f1bc9d /backend
parent4848d10be595cbc257b1d43be1c924fdcf81284e (diff)
downloadphperkaigi-2025-albatross-27168df997c298e871d34e58fdc726bf2e8a4954.tar.gz
phperkaigi-2025-albatross-27168df997c298e871d34e58fdc726bf2e8a4954.tar.zst
phperkaigi-2025-albatross-27168df997c298e871d34e58fdc726bf2e8a4954.zip
feat(backend): implement user edit page
Diffstat (limited to 'backend')
-rw-r--r--backend/admin/handler.go35
-rw-r--r--backend/db/query.sql.go29
-rw-r--r--backend/query.sql9
3 files changed, 73 insertions, 0 deletions
diff --git a/backend/admin/handler.go b/backend/admin/handler.go
index 3b8af23..bce4845 100644
--- a/backend/admin/handler.go
+++ b/backend/admin/handler.go
@@ -64,6 +64,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", h.postUserEdit)
g.POST("/users/:userID/fetch-icon", h.postUserFetchIcon)
g.GET("/games", h.getGames)
g.GET("/games/:gameID", h.getGameEdit)
@@ -128,6 +129,40 @@ func (h *Handler) getUserEdit(c echo.Context) error {
})
}
+func (h *Handler) postUserEdit(c echo.Context) error {
+ userID, err := strconv.Atoi(c.Param("userID"))
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, "Invalid user_id")
+ }
+
+ displayName := c.FormValue("display_name")
+ iconPathRaw := c.FormValue("icon_path")
+ isAdmin := (c.FormValue("is_admin") != "")
+ labelRaw := c.FormValue("label")
+
+ var iconPath *string
+ if iconPathRaw != "" {
+ iconPath = &iconPathRaw
+ }
+ var label *string
+ if labelRaw != "" {
+ label = &labelRaw
+ }
+
+ err = h.q.UpdateUser(c.Request().Context(), db.UpdateUserParams{
+ UserID: int32(userID),
+ DisplayName: displayName,
+ IconPath: iconPath,
+ IsAdmin: isAdmin,
+ Label: label,
+ })
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
+ }
+
+ return c.Redirect(http.StatusSeeOther, basePath+"/admin/users")
+}
+
func (h *Handler) postUserFetchIcon(c echo.Context) error {
userID, err := strconv.Atoi(c.Param("userID"))
if err != nil {
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index 5719e57..75671b6 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -733,6 +733,35 @@ func (q *Queries) UpdateSubmissionStatus(ctx context.Context, arg UpdateSubmissi
return err
}
+const updateUser = `-- name: UpdateUser :exec
+UPDATE users
+SET
+ display_name = $2,
+ icon_path = $3,
+ is_admin = $4,
+ label = $5
+WHERE user_id = $1
+`
+
+type UpdateUserParams struct {
+ UserID int32
+ DisplayName string
+ IconPath *string
+ IsAdmin bool
+ Label *string
+}
+
+func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
+ _, err := q.db.Exec(ctx, updateUser,
+ arg.UserID,
+ arg.DisplayName,
+ arg.IconPath,
+ arg.IsAdmin,
+ arg.Label,
+ )
+ return err
+}
+
const updateUserIconPath = `-- name: UpdateUserIconPath :exec
UPDATE users
SET icon_path = $2
diff --git a/backend/query.sql b/backend/query.sql
index dbf050b..e81a11b 100644
--- a/backend/query.sql
+++ b/backend/query.sql
@@ -28,6 +28,15 @@ JOIN user_auths ON users.user_id = user_auths.user_id
WHERE users.username = $1
LIMIT 1;
+-- name: UpdateUser :exec
+UPDATE users
+SET
+ display_name = $2,
+ icon_path = $3,
+ is_admin = $4,
+ label = $5
+WHERE user_id = $1;
+
-- name: CreateUserAuth :exec
INSERT INTO user_auths (user_id, auth_type)
VALUES ($1, $2);