Refactor Store into SessionStore; move domain SQL onto User/Question/Answer.

This commit is contained in:
2026-08-22 02:40:51 -07:00
parent f31f352838
commit c77298411e
15 changed files with 696 additions and 876 deletions
+8 -3
View File
@@ -28,7 +28,7 @@ func (s *Server) handleAdminUsers(w http.ResponseWriter, r *http.Request) {
if s.requireAdmin(w, r) == nil {
return
}
users, err := s.store.ListUsers(r.Context())
users, err := store.ListUsers(r.Context(), s.db)
if err != nil {
http.Error(w, "could not load users", http.StatusInternalServerError)
return
@@ -48,9 +48,14 @@ func (s *Server) handleAdminSetRole(w http.ResponseWriter, r *http.Request) {
}
id := chi.URLParam(r, "id")
role := store.Role(r.PostFormValue("role"))
err := s.store.SetRole(r.Context(), id, role)
u, err := store.UserByID(r.Context(), s.db, id)
if err != nil {
http.Error(w, "could not update role", http.StatusBadRequest)
return
}
err = u.SetRole(r.Context(), role)
if errors.Is(err, store.ErrLastAdmin) {
users, listErr := s.store.ListUsers(r.Context())
users, listErr := store.ListUsers(r.Context(), s.db)
if listErr != nil {
http.Error(w, "could not demote last admin", http.StatusBadRequest)
return