package handlers import ( "context" "net/http" "git.haelnorr.com/h/golib/hws" "git.haelnorr.com/h/oslstats/internal/db" adminview "git.haelnorr.com/h/oslstats/internal/view/adminview" "github.com/pkg/errors" "github.com/uptrace/bun" ) // AdminUsersPage renders the full admin dashboard page with users section func AdminUsersPage(s *hws.Server, conn *bun.DB) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var pageOpts *db.PageOpts if r.Method == "GET" { pageOpts = pageOptsFromQuery(s, w, r) } else { pageOpts = pageOptsFromForm(s, w, r) } if pageOpts == nil { return } var users *db.List[db.User] if ok := db.WithReadTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) { var err error users, err = db.GetUsersWithRoles(ctx, tx, pageOpts) if err != nil { return false, errors.Wrap(err, "db.GetUsersWithRoles") } return true, nil }); !ok { return } if r.Method == "GET" { renderSafely(adminview.DashboardPage(users), s, r, w) } else { renderSafely(adminview.UserList(users), s, r, w) } }) }